From 1e1e5cb477d06f89244696baa4b1f3952e00de11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20W=C3=B6hrl?= Date: Thu, 11 Jun 2020 17:45:45 +0200 Subject: [PATCH] fix absolut position when padding in place --- gentest/fixtures/YGAbsolutePositionTest.html | 4 ++ tests/YGAbsolutePositionTest.cpp | 65 +++++++++++++++----- yoga/Yoga.cpp | 6 +- 3 files changed, 56 insertions(+), 19 deletions(-) diff --git a/gentest/fixtures/YGAbsolutePositionTest.html b/gentest/fixtures/YGAbsolutePositionTest.html index 39f8e980..3efd1c3c 100644 --- a/gentest/fixtures/YGAbsolutePositionTest.html +++ b/gentest/fixtures/YGAbsolutePositionTest.html @@ -88,3 +88,7 @@
+
+
+
+ diff --git a/tests/YGAbsolutePositionTest.cpp b/tests/YGAbsolutePositionTest.cpp index eea56132..0a2105cc 100644 --- a/tests/YGAbsolutePositionTest.cpp +++ b/tests/YGAbsolutePositionTest.cpp @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the LICENSE * file in the root directory of this source tree. */ -// @Generated by gentest/gentest.rb from +// @Generated by gentest/gentest.rb from // gentest/fixtures/YGAbsolutePositionTest.html #include @@ -184,9 +184,7 @@ TEST(YogaTest, absolute_layout_width_height_start_top_end_bottom) { YGConfigFree(config); } -TEST( - YogaTest, - do_not_clamp_height_of_absolute_node_to_height_of_its_overflow_hidden_parent) { +TEST(YogaTest, do_not_clamp_height_of_absolute_node_to_height_of_its_overflow_hidden_parent) { const YGConfigRef config = YGConfigNew(); const YGNodeRef root = YGNodeNewWithConfig(config); @@ -578,9 +576,7 @@ TEST(YogaTest, absolute_layout_align_items_center_on_child_only) { YGConfigFree(config); } -TEST( - YogaTest, - absolute_layout_align_items_and_justify_content_center_and_top_position) { +TEST(YogaTest, absolute_layout_align_items_and_justify_content_center_and_top_position) { const YGConfigRef config = YGConfigNew(); const YGNodeRef root = YGNodeNewWithConfig(config); @@ -625,9 +621,7 @@ TEST( YGConfigFree(config); } -TEST( - YogaTest, - absolute_layout_align_items_and_justify_content_center_and_bottom_position) { +TEST(YogaTest, absolute_layout_align_items_and_justify_content_center_and_bottom_position) { const YGConfigRef config = YGConfigNew(); const YGNodeRef root = YGNodeNewWithConfig(config); @@ -672,9 +666,7 @@ TEST( YGConfigFree(config); } -TEST( - YogaTest, - absolute_layout_align_items_and_justify_content_center_and_left_position) { +TEST(YogaTest, absolute_layout_align_items_and_justify_content_center_and_left_position) { const YGConfigRef config = YGConfigNew(); const YGNodeRef root = YGNodeNewWithConfig(config); @@ -719,9 +711,7 @@ TEST( YGConfigFree(config); } -TEST( - YogaTest, - absolute_layout_align_items_and_justify_content_center_and_right_position) { +TEST(YogaTest, absolute_layout_align_items_and_justify_content_center_and_right_position) { const YGConfigRef config = YGConfigNew(); const YGNodeRef root = YGNodeNewWithConfig(config); @@ -1039,3 +1029,46 @@ TEST(YogaTest, absolute_layout_in_wrap_reverse_row_container_flex_end) { YGConfigFree(config); } + +TEST(YogaTest, absolute_layout_percentage_from_padded_parent) { + const YGConfigRef config = YGConfigNew(); + + const YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetPadding(root, YGEdgeTop, 100); + YGNodeStyleSetBorder(root, YGEdgeTop, 100); + YGNodeStyleSetWidth(root, 750); + YGNodeStyleSetHeight(root, 1000); + + const YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); + YGNodeStyleSetWidth(root_child0, 750); + YGNodeStyleSetHeightPercent(root_child0, 50); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(750, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(1000, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(750, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(750, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(1000, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(750, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 91e09c15..e628eced 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -2656,7 +2656,7 @@ static void YGJustifyMainAxis( } else if (performLayout) { child->setLayoutPosition( childLayout.position[pos[mainAxis]] + - node->getLeadingBorder(mainAxis) + leadingMainDim, + node->getLeadingPadding(mainAxis, ownerWidth).unwrap() + leadingMainDim, pos[mainAxis]); } } @@ -3563,9 +3563,9 @@ static void YGNodelayoutImpl( YGNodeAbsoluteLayoutChild( node, child, - availableInnerWidth, + availableWidth, isMainAxisRow ? measureModeMainDim : measureModeCrossDim, - availableInnerHeight, + availableHeight, direction, config, layoutMarkerData,