From 81be437a8f41bd691858d19bff838addca0e3773 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20W=C3=B6hrl?= Date: Sun, 12 Mar 2017 01:06:02 +0100 Subject: [PATCH] fix alignment with margin --- .../tests/Facebook.Yoga/YGAlignItemsTest.cs | 59 +++++++++++++++++++ gentest/fixtures/YGAlignItemsTest.html | 9 ++- .../com/facebook/yoga/YGAlignItemsTest.java | 58 ++++++++++++++++++ .../tests/Facebook.Yoga/YGAlignItemsTest.js | 58 ++++++++++++++++++ tests/YGAlignItemsTest.cpp | 59 +++++++++++++++++++ yoga/Yoga.c | 3 - 6 files changed, 241 insertions(+), 5 deletions(-) diff --git a/csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs b/csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs index d5022c10..a0dd4736 100644 --- a/csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs +++ b/csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs @@ -1587,5 +1587,64 @@ namespace Facebook.Yoga Assert.AreEqual(20f, root_child3.LayoutHeight); } + [Test] + public void Test_align_items_center_nested() + { + YogaConfig config = new YogaConfig(); + + YogaNode root = new YogaNode(config); + root.JustifyContent = YogaJustify.Center; + root.AlignItems = YogaAlign.Center; + root.PositionType = YogaPositionType.Absolute; + root.Width = 52; + root.Height = 52; + + YogaNode root_child0 = new YogaNode(config); + root_child0.AlignItems = YogaAlign.Center; + root.Insert(0, root_child0); + + YogaNode root_child0_child0 = new YogaNode(config); + root_child0_child0.MarginLeft = 10; + root_child0_child0.MarginRight = 10; + root_child0_child0.Width = 52; + root_child0_child0.Height = 52; + root_child0.Insert(0, root_child0_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(52f, root.LayoutWidth); + Assert.AreEqual(52f, root.LayoutHeight); + + Assert.AreEqual(-10f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(72f, root_child0.LayoutWidth); + Assert.AreEqual(52f, root_child0.LayoutHeight); + + Assert.AreEqual(10f, root_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0.LayoutY); + Assert.AreEqual(52f, root_child0_child0.LayoutWidth); + Assert.AreEqual(52f, root_child0_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(52f, root.LayoutWidth); + Assert.AreEqual(52f, root.LayoutHeight); + + Assert.AreEqual(-10f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(72f, root_child0.LayoutWidth); + Assert.AreEqual(52f, root_child0.LayoutHeight); + + Assert.AreEqual(10f, root_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0.LayoutY); + Assert.AreEqual(52f, root_child0_child0.LayoutWidth); + Assert.AreEqual(52f, root_child0_child0.LayoutHeight); + } + } } diff --git a/gentest/fixtures/YGAlignItemsTest.html b/gentest/fixtures/YGAlignItemsTest.html index 49aaa9aa..d1d174b2 100644 --- a/gentest/fixtures/YGAlignItemsTest.html +++ b/gentest/fixtures/YGAlignItemsTest.html @@ -133,8 +133,6 @@
- -
@@ -144,4 +142,11 @@
+
+ + +
+
+
+
\ No newline at end of file diff --git a/java/tests/com/facebook/yoga/YGAlignItemsTest.java b/java/tests/com/facebook/yoga/YGAlignItemsTest.java index 0b9533fb..5a885f6c 100644 --- a/java/tests/com/facebook/yoga/YGAlignItemsTest.java +++ b/java/tests/com/facebook/yoga/YGAlignItemsTest.java @@ -1567,4 +1567,62 @@ public class YGAlignItemsTest { assertEquals(20f, root_child3.getLayoutHeight(), 0.0f); } + @Test + public void test_align_items_center_nested() { + YogaConfig config = new YogaConfig(); + + final YogaNode root = new YogaNode(config); + root.setJustifyContent(YogaJustify.CENTER); + root.setAlignItems(YogaAlign.CENTER); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(52f); + root.setHeight(52f); + + final YogaNode root_child0 = new YogaNode(config); + root_child0.setAlignItems(YogaAlign.CENTER); + root.addChildAt(root_child0, 0); + + final YogaNode root_child0_child0 = new YogaNode(config); + root_child0_child0.setMargin(YogaEdge.LEFT, 10f); + root_child0_child0.setMargin(YogaEdge.RIGHT, 10f); + root_child0_child0.setWidth(52f); + root_child0_child0.setHeight(52f); + root_child0.addChildAt(root_child0_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(52f, root.getLayoutWidth(), 0.0f); + assertEquals(52f, root.getLayoutHeight(), 0.0f); + + assertEquals(-10f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(72f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(52f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(52f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(52f, root_child0_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(52f, root.getLayoutWidth(), 0.0f); + assertEquals(52f, root.getLayoutHeight(), 0.0f); + + assertEquals(-10f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(72f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(52f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(52f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(52f, root_child0_child0.getLayoutHeight(), 0.0f); + } + } diff --git a/javascript/tests/Facebook.Yoga/YGAlignItemsTest.js b/javascript/tests/Facebook.Yoga/YGAlignItemsTest.js index 8c4bee4c..1e59df3c 100644 --- a/javascript/tests/Facebook.Yoga/YGAlignItemsTest.js +++ b/javascript/tests/Facebook.Yoga/YGAlignItemsTest.js @@ -1562,3 +1562,61 @@ it("align_baseline_multiline_row_and_column", function () { } } }); +it("align_items_center_nested", function () { + try { + var root = Yoga.Node.create(config); + root.setJustifyContent(Yoga.JUSTIFY_CENTER); + root.setAlignItems(Yoga.ALIGN_CENTER); + root.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); + root.setWidth(52); + root.setHeight(52); + + var root_child0 = Yoga.Node.create(config); + root_child0.setAlignItems(Yoga.ALIGN_CENTER); + root.insertChild(root_child0, 0); + + var root_child0_child0 = Yoga.Node.create(config); + root_child0_child0.setMargin(Yoga.EDGE_LEFT, 10); + root_child0_child0.setMargin(Yoga.EDGE_RIGHT, 10); + root_child0_child0.setWidth(52); + root_child0_child0.setHeight(52); + root_child0.insertChild(root_child0_child0, 0); + root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR); + + console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); + console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); + console.assert(52 === root.getComputedWidth(), "52 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(52 === root.getComputedHeight(), "52 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(-10 === root_child0.getComputedLeft(), "-10 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(72 === root_child0.getComputedWidth(), "72 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(52 === root_child0.getComputedHeight(), "52 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(10 === root_child0_child0.getComputedLeft(), "10 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")"); + console.assert(52 === root_child0_child0.getComputedWidth(), "52 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")"); + console.assert(52 === root_child0_child0.getComputedHeight(), "52 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")"); + + root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL); + + console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); + console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); + console.assert(52 === root.getComputedWidth(), "52 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(52 === root.getComputedHeight(), "52 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(-10 === root_child0.getComputedLeft(), "-10 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(72 === root_child0.getComputedWidth(), "72 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(52 === root_child0.getComputedHeight(), "52 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(10 === root_child0_child0.getComputedLeft(), "10 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")"); + console.assert(52 === root_child0_child0.getComputedWidth(), "52 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")"); + console.assert(52 === root_child0_child0.getComputedHeight(), "52 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")"); + } finally { + if (typeof root !== "undefined") { + root.freeRecursive(); + } + } +}); diff --git a/tests/YGAlignItemsTest.cpp b/tests/YGAlignItemsTest.cpp index 90fefcbc..0bc0a596 100644 --- a/tests/YGAlignItemsTest.cpp +++ b/tests/YGAlignItemsTest.cpp @@ -1581,3 +1581,62 @@ TEST(YogaTest, align_baseline_multiline_row_and_column) { YGConfigFree(config); } + +TEST(YogaTest, align_items_center_nested) { + const YGConfigRef config = YGConfigNew(); + + const YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetJustifyContent(root, YGJustifyCenter); + YGNodeStyleSetAlignItems(root, YGAlignCenter); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetWidth(root, 52); + YGNodeStyleSetHeight(root, 52); + + const YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetAlignItems(root_child0, YGAlignCenter); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetMargin(root_child0_child0, YGEdgeLeft, 10); + YGNodeStyleSetMargin(root_child0_child0, YGEdgeRight, 10); + YGNodeStyleSetWidth(root_child0_child0, 52); + YGNodeStyleSetHeight(root_child0_child0, 52); + YGNodeInsertChild(root_child0, root_child0_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root_child0_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root_child0_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} diff --git a/yoga/Yoga.c b/yoga/Yoga.c index d77be50e..ee782ca3 100644 --- a/yoga/Yoga.c +++ b/yoga/Yoga.c @@ -2625,9 +2625,6 @@ static void YGNodelayoutImpl(const YGNodeRef node, parentWidth) - paddingAndBorderAxisCross; - if (measureModeCrossDim == YGMeasureModeAtMost) { - containerCrossAxis = fminf(containerCrossAxis, availableInnerCrossDim); - } } // If there's no flex wrap, the cross dimension is defined by the container.