From 369c9ad12a4cf65570ede43dcb771c5c015e92fb Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Thu, 15 Mar 2018 07:13:02 -0700 Subject: [PATCH] Fix setter and getter of margin, position, border and padding Summary: This diff fixes the setter and getter of margin, position, border and padding to the previous behaviour of yoga, before floatoptional change This diff also removes the unrequired `#define` Reviewed By: emilsjolander Differential Revision: D7274115 fbshipit-source-id: 942a91e6562ef789ae79102a828f397889468fa7 --- yoga/YGNodePrint.cpp | 5 ++++- yoga/Yoga.cpp | 34 +++++++++------------------------- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/yoga/YGNodePrint.cpp b/yoga/YGNodePrint.cpp index 8585b725..ab0666d0 100644 --- a/yoga/YGNodePrint.cpp +++ b/yoga/YGNodePrint.cpp @@ -72,7 +72,10 @@ appendNumberIfNotAuto(string* base, const string& key, const YGValue number) { static void appendNumberIfNotZero(string* base, const string& str, const YGValue number) { - if (!YGFloatsEqual(number.value, 0)) { + + if (number.unit == YGUnitAuto) { + base->append(str + ": auto; "); + } else if (!YGFloatsEqual(number.value, 0)) { appendNumberIfNotUndefined(base, str, number); } } diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index b5e1e4c0..5ccb6b1e 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -637,7 +637,7 @@ float YGNodeStyleGetFlexShrink(const YGNodeRef node) { void YGNodeStyleSet##name##Auto(const YGNodeRef node, const YGEdge edge) { \ if (node->getStyle().instanceName[edge].unit != YGUnitAuto) { \ YGStyle style = node->getStyle(); \ - style.instanceName[edge].value = YGUndefined; \ + style.instanceName[edge].value = 0; \ style.instanceName[edge].unit = YGUnitAuto; \ node->setStyle(style); \ node->markDirtyAndPropogate(); \ @@ -649,7 +649,7 @@ float YGNodeStyleGetFlexShrink(const YGNodeRef node) { void YGNodeStyleSet##name( \ const YGNodeRef node, const YGEdge edge, const float paramName) { \ YGValue value = { \ - .value = paramName, \ + .value = YGFloatSanitize(paramName), \ .unit = YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint, \ }; \ if ((node->getStyle().instanceName[edge].value != value.value && \ @@ -665,7 +665,7 @@ float YGNodeStyleGetFlexShrink(const YGNodeRef node) { void YGNodeStyleSet##name##Percent( \ const YGNodeRef node, const YGEdge edge, const float paramName) { \ YGValue value = { \ - .value = paramName, \ + .value = YGFloatSanitize(paramName), \ .unit = \ YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPercent, \ }; \ @@ -681,28 +681,11 @@ float YGNodeStyleGetFlexShrink(const YGNodeRef node) { \ WIN_STRUCT(type) \ YGNodeStyleGet##name(const YGNodeRef node, const YGEdge edge) { \ - return WIN_STRUCT_REF(node->getStyle().instanceName[edge]); \ - } - -#define YG_NODE_STYLE_EDGE_PROPERTY_IMPL(type, name, paramName, instanceName) \ - void YGNodeStyleSet##name( \ - const YGNodeRef node, const YGEdge edge, const float paramName) { \ - YGValue value = { \ - .value = paramName, \ - .unit = YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint, \ - }; \ - if ((node->getStyle().instanceName[edge].value != value.value && \ - value.unit != YGUnitUndefined) || \ - node->getStyle().instanceName[edge].unit != value.unit) { \ - YGStyle style = node->getStyle(); \ - style.instanceName[edge] = value; \ - node->setStyle(style); \ - node->markDirtyAndPropogate(); \ + YGValue value = node->getStyle().instanceName[edge]; \ + if (value.unit == YGUnitUndefined || value.unit == YGUnitAuto) { \ + value.value = YGUndefined; \ } \ - } \ - \ - float YGNodeStyleGet##name(const YGNodeRef node, const YGEdge edge) { \ - return node->getStyle().instanceName[edge].value; \ + return WIN_STRUCT_REF(value); \ } #define YG_NODE_LAYOUT_PROPERTY_IMPL(type, name, instanceName) \ @@ -873,7 +856,8 @@ void YGNodeStyleSetBorder( } float YGNodeStyleGetBorder(const YGNodeRef node, const YGEdge edge) { - if (node->getStyle().border[edge].unit == YGUnitUndefined) { + if (node->getStyle().border[edge].unit == YGUnitUndefined || + node->getStyle().border[edge].unit == YGUnitAuto) { // TODO(T26792433): Rather than returning YGUndefined, change the api to // return YGFloatOptional. return YGUndefined;