Replace point setter in `YG_NODE_STYLE_PROPERTY_UNIT_IMPL` macro with template code

Reviewed By: astreet

Differential Revision: D8874735

fbshipit-source-id: 77fa1ceb2eaff6a0e415ef939e55aa22bc3d6099
This commit is contained in:
David Aurelio 2018-08-17 03:56:39 -07:00 committed by Facebook Github Bot
parent edc15ebceb
commit 03377ac322
1 changed files with 25 additions and 12 deletions

View File

@ -604,6 +604,16 @@ struct StyleProp {
}
};
struct Value {
template <YGUnit U>
static YGValue create(float value) {
return {
YGFloatSanitize(value),
YGFloatIsUndefined(value) ? YGUnitUndefined : U,
};
}
};
template <YGStyle::Dimensions YGStyle::*P>
struct DimensionProp {
template <YGDimension idx>
@ -614,6 +624,17 @@ struct DimensionProp {
}
return WIN_STRUCT_REF(value);
}
template <YGDimension idx, YGUnit U>
static void set(YGNodeRef node, float newValue) {
YGValue value = Value::create<U>(newValue);
if (((node->getStyle().*P)[idx].value != value.value &&
value.unit != YGUnitUndefined) ||
(node->getStyle().*P)[idx].unit != value.unit) {
(node->getStyle().*P)[idx] = value;
node->markDirtyAndPropogate();
}
}
};
} // namespace
@ -621,16 +642,8 @@ struct DimensionProp {
#define YG_NODE_STYLE_PROPERTY_SETTER_UNIT_IMPL( \
type, name, paramName, instanceName, dimension) \
void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \
YGValue value = { \
YGFloatSanitize(paramName), \
YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint, \
}; \
if ((node->getStyle().instanceName[dimension].value != value.value && \
value.unit != YGUnitUndefined) || \
node->getStyle().instanceName[dimension].unit != value.unit) { \
node->getStyle().instanceName[dimension] = value; \
node->markDirtyAndPropogate(); \
} \
DimensionProp<&YGStyle::instanceName>::set<dimension, YGUnitPoint>( \
node, paramName); \
} \
\
void YGNodeStyleSet##name##Percent( \
@ -641,7 +654,7 @@ struct DimensionProp {
}; \
if ((node->getStyle().instanceName[dimension].value != value.value && \
value.unit != YGUnitUndefined) || \
node->getStyle().instanceName[dimension].unit != value.unit) { \ \
node->getStyle().instanceName[dimension].unit != value.unit) { \
node->getStyle().instanceName[dimension] = value; \
node->markDirtyAndPropogate(); \
} \