From b88cf7ff67317559ae378a19138a0ea7ffdf5df6 Mon Sep 17 00:00:00 2001 From: Sidharth Guglani Date: Fri, 15 Nov 2019 05:10:33 -0800 Subject: [PATCH] use owner's width for resolving the margin and padding for node Summary: The margin and padding are resolved incorrectly for leaf nodes (nodes with measure function set) if margin and padding are used in percentages. Here we were using node's width instead of container width to calculate the margin and padding. Fixed this to use container's width. ## Changelog: [General][Yoga] : Fixed an issue where margin and padding were resolved incorrectly for leaf nodes (nodes with measure function set) if margin and padding are used in percentages. Reviewed By: alickbass Differential Revision: D17130520 fbshipit-source-id: ac904d432f121973e7739debd9136909b5ca1427 --- tests/YGMeasureTest.cpp | 4 ++-- yoga/Yoga.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/YGMeasureTest.cpp b/tests/YGMeasureTest.cpp index 38c28059..baeb0ae8 100644 --- a/tests/YGMeasureTest.cpp +++ b/tests/YGMeasureTest.cpp @@ -686,9 +686,9 @@ TEST(YogaTest, percent_with_text_node) { ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(15, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetHeight(root_child1)); YGNodeFreeRecursive(root); diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 04d199a3..41de5119 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -1670,13 +1670,13 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions( "Expected node to have custom measure function"); const float paddingAndBorderAxisRow = - YGNodePaddingAndBorderForAxis(node, YGFlexDirectionRow, availableWidth); - const float paddingAndBorderAxisColumn = YGNodePaddingAndBorderForAxis( - node, YGFlexDirectionColumn, availableWidth); + YGNodePaddingAndBorderForAxis(node, YGFlexDirectionRow, ownerWidth); + const float paddingAndBorderAxisColumn = + YGNodePaddingAndBorderForAxis(node, YGFlexDirectionColumn, ownerWidth); const float marginAxisRow = - node->getMarginForAxis(YGFlexDirectionRow, availableWidth).unwrap(); + node->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap(); const float marginAxisColumn = - node->getMarginForAxis(YGFlexDirectionColumn, availableWidth).unwrap(); + node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth).unwrap(); // We want to make sure we don't call measure with negative size const float innerWidth = YGFloatIsUndefined(availableWidth)