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