diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index c9404dec..c9799c3c 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -576,16 +576,24 @@ float YGNodeStyleGetFlexShrink(const YGNodeRef node) { : node->getStyle().flexShrink.getValue(); } -#define YG_NODE_STYLE_PROPERTY_SETTER_IMPL( \ - type, name, paramName, instanceName) \ - void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \ - if (node->getStyle().instanceName != paramName) { \ - YGStyle style = node->getStyle(); \ - style.instanceName = paramName; \ - node->setStyle(style); \ - node->markDirtyAndPropogate(); \ - } \ +namespace { + +template +struct StyleProp { + static T get(YGNodeRef node) { + return node->getStyle().*P; } + static void set(YGNodeRef node, T newValue) { + if (node->getStyle().*P != newValue) { + YGStyle style = node->getStyle(); + style.*P = newValue; + node->setStyle(style); + node->markDirtyAndPropogate(); + } + } +}; + +} // namespace #define YG_NODE_STYLE_PROPERTY_SETTER_UNIT_IMPL( \ type, name, paramName, instanceName) \ @@ -661,13 +669,6 @@ float YGNodeStyleGetFlexShrink(const YGNodeRef node) { } \ } -#define YG_NODE_STYLE_PROPERTY_IMPL(type, name, paramName, instanceName) \ - YG_NODE_STYLE_PROPERTY_SETTER_IMPL(type, name, paramName, instanceName) \ - \ - type YGNodeStyleGet##name(const YGNodeRef node) { \ - return node->getStyle().instanceName; \ - } - #define YG_NODE_STYLE_PROPERTY_UNIT_IMPL(type, name, paramName, instanceName) \ YG_NODE_STYLE_PROPERTY_SETTER_UNIT_IMPL( \ float, name, paramName, instanceName) \ @@ -778,33 +779,85 @@ float YGNodeStyleGetFlexShrink(const YGNodeRef node) { return node->getLayout().instanceName[edge]; \ } -// YG_NODE_PROPERTY_IMPL(void *, Context, context, context); -// YG_NODE_PROPERTY_IMPL(YGPrintFunc, PrintFunc, printFunc, print); -// YG_NODE_PROPERTY_IMPL(bool, HasNewLayout, hasNewLayout, hasNewLayout); -// YG_NODE_PROPERTY_IMPL(YGNodeType, NodeType, nodeType, nodeType); +void YGNodeStyleSetDirection( + const YGNodeRef node, + const YGDirection direction) { + StyleProp::set(node, direction); +} +YGDirection YGNodeStyleGetDirection(const YGNodeRef node) { + return StyleProp::get(node); +} -YG_NODE_STYLE_PROPERTY_IMPL(YGDirection, Direction, direction, direction); -YG_NODE_STYLE_PROPERTY_IMPL( - YGFlexDirection, - FlexDirection, - flexDirection, - flexDirection); -YG_NODE_STYLE_PROPERTY_IMPL( - YGJustify, - JustifyContent, - justifyContent, - justifyContent); -YG_NODE_STYLE_PROPERTY_IMPL(YGAlign, AlignContent, alignContent, alignContent); -YG_NODE_STYLE_PROPERTY_IMPL(YGAlign, AlignItems, alignItems, alignItems); -YG_NODE_STYLE_PROPERTY_IMPL(YGAlign, AlignSelf, alignSelf, alignSelf); -YG_NODE_STYLE_PROPERTY_IMPL( - YGPositionType, - PositionType, - positionType, - positionType); -YG_NODE_STYLE_PROPERTY_IMPL(YGWrap, FlexWrap, flexWrap, flexWrap); -YG_NODE_STYLE_PROPERTY_IMPL(YGOverflow, Overflow, overflow, overflow); -YG_NODE_STYLE_PROPERTY_IMPL(YGDisplay, Display, display, display); +void YGNodeStyleSetFlexDirection( + const YGNodeRef node, + const YGFlexDirection flexDirection) { + StyleProp::set(node, flexDirection); +} +YGFlexDirection YGNodeStyleGetFlexDirection(const YGNodeRef node) { + return StyleProp::get(node); +} + +void YGNodeStyleSetJustifyContent( + const YGNodeRef node, + const YGJustify justifyContent) { + StyleProp::set(node, justifyContent); +} +YGJustify YGNodeStyleGetJustifyContent(const YGNodeRef node) { + return StyleProp::get(node); +} + +void YGNodeStyleSetAlignContent( + const YGNodeRef node, + const YGAlign alignContent) { + StyleProp::set(node, alignContent); +} +YGAlign YGNodeStyleGetAlignContent(const YGNodeRef node) { + return StyleProp::get(node); +} + +void YGNodeStyleSetAlignItems(const YGNodeRef node, const YGAlign alignItems) { + StyleProp::set(node, alignItems); +} +YGAlign YGNodeStyleGetAlignItems(const YGNodeRef node) { + return StyleProp::get(node); +} + +void YGNodeStyleSetAlignSelf(const YGNodeRef node, const YGAlign alignSelf) { + StyleProp::set(node, alignSelf); +} +YGAlign YGNodeStyleGetAlignSelf(const YGNodeRef node) { + return StyleProp::get(node); +} + +void YGNodeStyleSetPositionType( + const YGNodeRef node, + const YGPositionType positionType) { + StyleProp::set(node, positionType); +} +YGPositionType YGNodeStyleGetPositionType(const YGNodeRef node) { + return StyleProp::get(node); +} + +void YGNodeStyleSetFlexWrap(const YGNodeRef node, const YGWrap flexWrap) { + StyleProp::set(node, flexWrap); +} +YGWrap YGNodeStyleGetFlexWrap(const YGNodeRef node) { + return StyleProp::get(node); +} + +void YGNodeStyleSetOverflow(const YGNodeRef node, const YGOverflow overflow) { + StyleProp::set(node, overflow); +} +YGOverflow YGNodeStyleGetOverflow(const YGNodeRef node) { + return StyleProp::get(node); +} + +void YGNodeStyleSetDisplay(const YGNodeRef node, const YGDisplay display) { + StyleProp::set(node, display); +} +YGDisplay YGNodeStyleGetDisplay(const YGNodeRef node) { + return StyleProp::get(node); +} // TODO(T26792433): Change the API to accept YGFloatOptional. void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {