From 240c2dd6573367cd94bfa4893316347b75b2fc18 Mon Sep 17 00:00:00 2001 From: Emil Sjolander Date: Sat, 11 Feb 2017 05:26:55 -0800 Subject: [PATCH 01/20] Fix min/max not overriding width/height Summary: Two bugs: 1. Min/Max width/height should have higher priority than width/height 2. custom measure nodes percentages should be based in parent size like everything else. Differential Revision: D4537576 fbshipit-source-id: c003f723f424afbca63170d41e54fd5ff837926d --- .../Facebook.Yoga/YGMinMaxDimensionTest.cs | 133 +++++++++++++++++ gentest/fixtures/YGMinMaxDimensionTest.html | 17 +++ .../facebook/yoga/YGMinMaxDimensionTest.java | 128 ++++++++++++++++ .../Facebook.Yoga/YGMinMaxDimensionTest.js | 138 ++++++++++++++++++ tests/YGMeasureTest.cpp | 4 +- tests/YGMinMaxDimensionTest.cpp | 123 ++++++++++++++++ yoga/YGEnums.h | 111 ++++++++------ yoga/Yoga.c | 48 +++--- 8 files changed, 631 insertions(+), 71 deletions(-) diff --git a/csharp/tests/Facebook.Yoga/YGMinMaxDimensionTest.cs b/csharp/tests/Facebook.Yoga/YGMinMaxDimensionTest.cs index 91b72401..fb98750a 100644 --- a/csharp/tests/Facebook.Yoga/YGMinMaxDimensionTest.cs +++ b/csharp/tests/Facebook.Yoga/YGMinMaxDimensionTest.cs @@ -675,5 +675,138 @@ namespace Facebook.Yoga Assert.AreEqual(50f, root_child1.LayoutHeight); } + [Test] + public void Test_min_width_overrides_width() + { + YogaNode root = new YogaNode(); + root.Width = 50; + root.MinWidth = 100; + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(0f, root.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(0f, root.LayoutHeight); + } + + [Test] + public void Test_max_width_overrides_width() + { + YogaNode root = new YogaNode(); + root.Width = 200; + root.MaxWidth = 100; + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(0f, root.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(0f, root.LayoutHeight); + } + + [Test] + public void Test_min_height_overrides_height() + { + YogaNode root = new YogaNode(); + root.Height = 50; + root.MinHeight = 100; + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(0f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(0f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + } + + [Test] + public void Test_max_height_overrides_height() + { + YogaNode root = new YogaNode(); + root.Height = 200; + root.MaxHeight = 100; + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(0f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(0f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + } + + [Test] + public void Test_min_max_percent_no_width_height() + { + YogaNode root = new YogaNode(); + root.AlignItems = YogaAlign.FlexStart; + root.Width = 100; + root.Height = 100; + + YogaNode root_child0 = new YogaNode(); + root_child0.MinWidth = 10.Percent(); + root_child0.MaxWidth = 10.Percent(); + root_child0.MinHeight = 10.Percent(); + root_child0.MaxHeight = 10.Percent(); + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(90f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + } + } } diff --git a/gentest/fixtures/YGMinMaxDimensionTest.html b/gentest/fixtures/YGMinMaxDimensionTest.html index 6adf67e5..621c6cc3 100644 --- a/gentest/fixtures/YGMinMaxDimensionTest.html +++ b/gentest/fixtures/YGMinMaxDimensionTest.html @@ -63,3 +63,20 @@
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
diff --git a/java/tests/com/facebook/yoga/YGMinMaxDimensionTest.java b/java/tests/com/facebook/yoga/YGMinMaxDimensionTest.java index 66f45832..a5d4ce35 100644 --- a/java/tests/com/facebook/yoga/YGMinMaxDimensionTest.java +++ b/java/tests/com/facebook/yoga/YGMinMaxDimensionTest.java @@ -661,4 +661,132 @@ public class YGMinMaxDimensionTest { assertEquals(50f, root_child1.getLayoutHeight(), 0.0f); } + @Test + public void test_min_width_overrides_width() { + final YogaNode root = new YogaNode(); + root.setWidth(50f); + root.setMinWidth(100f); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(0f, root.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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(0f, root.getLayoutHeight(), 0.0f); + } + + @Test + public void test_max_width_overrides_width() { + final YogaNode root = new YogaNode(); + root.setWidth(200f); + root.setMaxWidth(100f); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(0f, root.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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(0f, root.getLayoutHeight(), 0.0f); + } + + @Test + public void test_min_height_overrides_height() { + final YogaNode root = new YogaNode(); + root.setHeight(50f); + root.setMinHeight(100f); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(0f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.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(0f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + } + + @Test + public void test_max_height_overrides_height() { + final YogaNode root = new YogaNode(); + root.setHeight(200f); + root.setMaxHeight(100f); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(0f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.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(0f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + } + + @Test + public void test_min_max_percent_no_width_height() { + final YogaNode root = new YogaNode(); + root.setAlignItems(YogaAlign.FLEX_START); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setMinWidthPercent(10f); + root_child0.setMaxWidthPercent(10f); + root_child0.setMinHeightPercent(10f); + root_child0.setMaxHeightPercent(10f); + root.addChildAt(root_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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(90f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + } + } diff --git a/javascript/tests/Facebook.Yoga/YGMinMaxDimensionTest.js b/javascript/tests/Facebook.Yoga/YGMinMaxDimensionTest.js index db5d78ce..0ff8cc5f 100644 --- a/javascript/tests/Facebook.Yoga/YGMinMaxDimensionTest.js +++ b/javascript/tests/Facebook.Yoga/YGMinMaxDimensionTest.js @@ -682,3 +682,141 @@ it("flex_grow_within_constrained_max_column", function () { (typeof gc !== "undefined") && gc(); console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); }); +it("min_width_overrides_width", function () { + var root = Yoga.Node.create(); + root.setWidth(50); + root.setMinWidth(100); + 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(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(0 === root.getComputedHeight(), "0 === root.getComputedHeight() (" + root.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(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(0 === root.getComputedHeight(), "0 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + if (typeof root !== "undefined") + root.freeRecursive(); + + (typeof gc !== "undefined") && gc(); + console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); +}); +it("max_width_overrides_width", function () { + var root = Yoga.Node.create(); + root.setWidth(200); + root.setMaxWidth(100); + 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(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(0 === root.getComputedHeight(), "0 === root.getComputedHeight() (" + root.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(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(0 === root.getComputedHeight(), "0 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + if (typeof root !== "undefined") + root.freeRecursive(); + + (typeof gc !== "undefined") && gc(); + console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); +}); +it("min_height_overrides_height", function () { + var root = Yoga.Node.create(); + root.setHeight(50); + root.setMinHeight(100); + 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(0 === root.getComputedWidth(), "0 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.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(0 === root.getComputedWidth(), "0 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + if (typeof root !== "undefined") + root.freeRecursive(); + + (typeof gc !== "undefined") && gc(); + console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); +}); +it("max_height_overrides_height", function () { + var root = Yoga.Node.create(); + root.setHeight(200); + root.setMaxHeight(100); + 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(0 === root.getComputedWidth(), "0 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.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(0 === root.getComputedWidth(), "0 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + if (typeof root !== "undefined") + root.freeRecursive(); + + (typeof gc !== "undefined") && gc(); + console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); +}); +it("min_max_percent_no_width_height", function () { + var root = Yoga.Node.create(); + root.setAlignItems(Yoga.ALIGN_FLEX_START); + root.setWidth(100); + root.setHeight(100); + + var root_child0 = Yoga.Node.create(); + root_child0.setMinWidth("10%"); + root_child0.setMaxWidth("10%"); + root_child0.setMinHeight("10%"); + root_child0.setMaxHeight("10%"); + root.insertChild(root_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(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(10 === root_child0.getComputedWidth(), "10 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(10 === root_child0.getComputedHeight(), "10 === root_child0.getComputedHeight() (" + root_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(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(90 === root_child0.getComputedLeft(), "90 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(10 === root_child0.getComputedWidth(), "10 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(10 === root_child0.getComputedHeight(), "10 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + if (typeof root !== "undefined") + root.freeRecursive(); + + (typeof gc !== "undefined") && gc(); + console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); +}); diff --git a/tests/YGMeasureTest.cpp b/tests/YGMeasureTest.cpp index a65ad8ff..79adf98d 100644 --- a/tests/YGMeasureTest.cpp +++ b/tests/YGMeasureTest.cpp @@ -123,7 +123,7 @@ TEST(YogaTest, dont_measure_when_min_equals_max_percentages) { YGNodeFreeRecursive(root); } -TEST(YogaTest, dont_measure_when_min_equals_max_mixed) { +TEST(YogaTest, dont_measure_when_min_equals_max_mixed_width_percent) { const YGNodeRef root = YGNodeNew(); YGNodeStyleSetAlignItems(root, YGAlignFlexStart); YGNodeStyleSetWidth(root, 100); @@ -151,7 +151,7 @@ TEST(YogaTest, dont_measure_when_min_equals_max_mixed) { YGNodeFreeRecursive(root); } -TEST(YogaTest, dont_measure_when_min_equals_max_mixed_2) { +TEST(YogaTest, dont_measure_when_min_equals_max_mixed_height_percent) { const YGNodeRef root = YGNodeNew(); YGNodeStyleSetAlignItems(root, YGAlignFlexStart); YGNodeStyleSetWidth(root, 100); diff --git a/tests/YGMinMaxDimensionTest.cpp b/tests/YGMinMaxDimensionTest.cpp index 126f7700..c9b7ea58 100644 --- a/tests/YGMinMaxDimensionTest.cpp +++ b/tests/YGMinMaxDimensionTest.cpp @@ -643,3 +643,126 @@ TEST(YogaTest, flex_grow_within_constrained_max_column) { YGNodeFreeRecursive(root); } + +TEST(YogaTest, min_width_overrides_width) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 50); + YGNodeStyleSetMinWidth(root, 100); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, max_width_overrides_width) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 200); + YGNodeStyleSetMaxWidth(root, 100); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, min_height_overrides_height) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetHeight(root, 50); + YGNodeStyleSetMinHeight(root, 100); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, max_height_overrides_height) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetHeight(root, 200); + YGNodeStyleSetMaxHeight(root, 100); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, min_max_percent_no_width_height) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetMinWidthPercent(root_child0, 10); + YGNodeStyleSetMaxWidthPercent(root_child0, 10); + YGNodeStyleSetMinHeightPercent(root_child0, 10); + YGNodeStyleSetMaxHeightPercent(root_child0, 10); + 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(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} diff --git a/yoga/YGEnums.h b/yoga/YGEnums.h index b4efc9cc..3e65e103 100644 --- a/yoga/YGEnums.h +++ b/yoga/YGEnums.h @@ -15,21 +15,26 @@ YG_EXTERN_C_BEGIN #define YGAlignCount 6 typedef YG_ENUM_BEGIN(YGAlign) { - YGAlignAuto, YGAlignFlexStart, YGAlignCenter, YGAlignFlexEnd, YGAlignStretch, YGAlignBaseline, -} -YG_ENUM_END(YGAlign); + YGAlignAuto, + YGAlignFlexStart, + YGAlignCenter, + YGAlignFlexEnd, + YGAlignStretch, + YGAlignBaseline, +} YG_ENUM_END(YGAlign); #define YGDimensionCount 2 typedef YG_ENUM_BEGIN(YGDimension) { - YGDimensionWidth, YGDimensionHeight, -} -YG_ENUM_END(YGDimension); + YGDimensionWidth, + YGDimensionHeight, +} YG_ENUM_END(YGDimension); #define YGDirectionCount 3 typedef YG_ENUM_BEGIN(YGDirection) { - YGDirectionInherit, YGDirectionLTR, YGDirectionRTL, -} -YG_ENUM_END(YGDirection); + YGDirectionInherit, + YGDirectionLTR, + YGDirectionRTL, +} YG_ENUM_END(YGDirection); #define YGDisplayCount 2 typedef YG_ENUM_BEGIN(YGDisplay) { @@ -39,71 +44,87 @@ typedef YG_ENUM_BEGIN(YGDisplay) { #define YGEdgeCount 9 typedef YG_ENUM_BEGIN(YGEdge) { - YGEdgeLeft, YGEdgeTop, YGEdgeRight, YGEdgeBottom, YGEdgeStart, YGEdgeEnd, YGEdgeHorizontal, - YGEdgeVertical, YGEdgeAll, -} -YG_ENUM_END(YGEdge); + YGEdgeLeft, + YGEdgeTop, + YGEdgeRight, + YGEdgeBottom, + YGEdgeStart, + YGEdgeEnd, + YGEdgeHorizontal, + YGEdgeVertical, + YGEdgeAll, +} YG_ENUM_END(YGEdge); #define YGExperimentalFeatureCount 2 typedef YG_ENUM_BEGIN(YGExperimentalFeature) { - YGExperimentalFeatureRounding, YGExperimentalFeatureWebFlexBasis, -} -YG_ENUM_END(YGExperimentalFeature); + YGExperimentalFeatureRounding, + YGExperimentalFeatureWebFlexBasis, +} YG_ENUM_END(YGExperimentalFeature); #define YGFlexDirectionCount 4 typedef YG_ENUM_BEGIN(YGFlexDirection) { - YGFlexDirectionColumn, YGFlexDirectionColumnReverse, YGFlexDirectionRow, - YGFlexDirectionRowReverse, -} -YG_ENUM_END(YGFlexDirection); + YGFlexDirectionColumn, + YGFlexDirectionColumnReverse, + YGFlexDirectionRow, + YGFlexDirectionRowReverse, +} YG_ENUM_END(YGFlexDirection); #define YGJustifyCount 5 typedef YG_ENUM_BEGIN(YGJustify) { - YGJustifyFlexStart, YGJustifyCenter, YGJustifyFlexEnd, YGJustifySpaceBetween, - YGJustifySpaceAround, -} -YG_ENUM_END(YGJustify); + YGJustifyFlexStart, + YGJustifyCenter, + YGJustifyFlexEnd, + YGJustifySpaceBetween, + YGJustifySpaceAround, +} YG_ENUM_END(YGJustify); #define YGLogLevelCount 5 typedef YG_ENUM_BEGIN(YGLogLevel) { - YGLogLevelError, YGLogLevelWarn, YGLogLevelInfo, YGLogLevelDebug, YGLogLevelVerbose, -} -YG_ENUM_END(YGLogLevel); + YGLogLevelError, + YGLogLevelWarn, + YGLogLevelInfo, + YGLogLevelDebug, + YGLogLevelVerbose, +} YG_ENUM_END(YGLogLevel); #define YGMeasureModeCount 3 typedef YG_ENUM_BEGIN(YGMeasureMode) { - YGMeasureModeUndefined, YGMeasureModeExactly, YGMeasureModeAtMost, -} -YG_ENUM_END(YGMeasureMode); + YGMeasureModeUndefined, + YGMeasureModeExactly, + YGMeasureModeAtMost, +} YG_ENUM_END(YGMeasureMode); #define YGOverflowCount 3 typedef YG_ENUM_BEGIN(YGOverflow) { - YGOverflowVisible, YGOverflowHidden, YGOverflowScroll, -} -YG_ENUM_END(YGOverflow); + YGOverflowVisible, + YGOverflowHidden, + YGOverflowScroll, +} YG_ENUM_END(YGOverflow); #define YGPositionTypeCount 2 typedef YG_ENUM_BEGIN(YGPositionType) { - YGPositionTypeRelative, YGPositionTypeAbsolute, -} -YG_ENUM_END(YGPositionType); + YGPositionTypeRelative, + YGPositionTypeAbsolute, +} YG_ENUM_END(YGPositionType); #define YGPrintOptionsCount 3 typedef YG_ENUM_BEGIN(YGPrintOptions) { - YGPrintOptionsLayout = 1, YGPrintOptionsStyle = 2, YGPrintOptionsChildren = 4, -} -YG_ENUM_END(YGPrintOptions); + YGPrintOptionsLayout = 1, + YGPrintOptionsStyle = 2, + YGPrintOptionsChildren = 4, +} YG_ENUM_END(YGPrintOptions); #define YGUnitCount 3 typedef YG_ENUM_BEGIN(YGUnit) { - YGUnitUndefined, YGUnitPixel, YGUnitPercent, -} -YG_ENUM_END(YGUnit); + YGUnitUndefined, + YGUnitPixel, + YGUnitPercent, +} YG_ENUM_END(YGUnit); #define YGWrapCount 2 typedef YG_ENUM_BEGIN(YGWrap) { - YGWrapNoWrap, YGWrapWrap, -} -YG_ENUM_END(YGWrap); + YGWrapNoWrap, + YGWrapWrap, +} YG_ENUM_END(YGWrap); YG_EXTERN_C_END diff --git a/yoga/Yoga.c b/yoga/Yoga.c index 3bd71471..a6dde07d 100644 --- a/yoga/Yoga.c +++ b/yoga/Yoga.c @@ -641,13 +641,11 @@ static inline bool YGValueEqual(const YGValue a, const YGValue b) { static inline void YGResolveDimensions(YGNodeRef node) { for (YGDimension dim = YGDimensionWidth; dim <= YGDimensionHeight; dim++) { - if (node->style.dimensions[dim].unit != YGUnitUndefined) { - node->resolvedDimensions[dim] = node->style.dimensions[dim]; + if (node->style.maxDimensions[dim].unit != YGUnitUndefined && + YGValueEqual(node->style.maxDimensions[dim], node->style.minDimensions[dim])) { + node->resolvedDimensions[dim] = node->style.maxDimensions[dim]; } else { - if (node->style.maxDimensions[dim].unit != YGUnitUndefined && - YGValueEqual(node->style.maxDimensions[dim], node->style.minDimensions[dim])) { - node->resolvedDimensions[dim] = node->style.maxDimensions[dim]; - } + node->resolvedDimensions[dim] = node->style.dimensions[dim]; } } } @@ -1167,14 +1165,13 @@ static float YGNodeBoundAxisWithinMinAndMax(const YGNodeRef node, const float axisSize) { float min = YGUndefined; float max = YGUndefined; - if (!YGNodeIsStyleDimDefined(node, axis, axisSize)) { - if (YGFlexDirectionIsColumn(axis)) { - min = YGValueResolve(&node->style.minDimensions[YGDimensionHeight], axisSize); - max = YGValueResolve(&node->style.maxDimensions[YGDimensionHeight], axisSize); - } else if (YGFlexDirectionIsRow(axis)) { - min = YGValueResolve(&node->style.minDimensions[YGDimensionWidth], axisSize); - max = YGValueResolve(&node->style.maxDimensions[YGDimensionWidth], axisSize); - } + + if (YGFlexDirectionIsColumn(axis)) { + min = YGValueResolve(&node->style.minDimensions[YGDimensionHeight], axisSize); + max = YGValueResolve(&node->style.maxDimensions[YGDimensionHeight], axisSize); + } else if (YGFlexDirectionIsRow(axis)) { + min = YGValueResolve(&node->style.minDimensions[YGDimensionWidth], axisSize); + max = YGValueResolve(&node->style.maxDimensions[YGDimensionWidth], axisSize); } float boundValue = value; @@ -1545,7 +1542,9 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions(const YGNodeRef node, const float availableWidth, const float availableHeight, const YGMeasureMode widthMeasureMode, - const YGMeasureMode heightMeasureMode) { + const YGMeasureMode heightMeasureMode, + const float parentWidth, + const float parentHeight) { YG_ASSERT(node->measure, "Expected node to have custom measure function"); const float paddingAndBorderAxisRow = @@ -1561,13 +1560,9 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions(const YGNodeRef node, if (widthMeasureMode == YGMeasureModeExactly && heightMeasureMode == YGMeasureModeExactly) { // Don't bother sizing the text if both dimensions are already defined. node->layout.measuredDimensions[YGDimensionWidth] = YGNodeBoundAxis( - node, YGFlexDirectionRow, availableWidth - marginAxisRow, availableWidth, availableWidth); - node->layout.measuredDimensions[YGDimensionHeight] = - YGNodeBoundAxis(node, - YGFlexDirectionColumn, - availableHeight - marginAxisColumn, - availableHeight, - availableWidth); + node, YGFlexDirectionRow, availableWidth - marginAxisRow, parentWidth, parentWidth); + node->layout.measuredDimensions[YGDimensionHeight] = YGNodeBoundAxis( + node, YGFlexDirectionColumn, availableHeight - marginAxisColumn, parentHeight, parentWidth); } else if (innerWidth <= 0.0f || innerHeight <= 0.0f) { // Don't bother sizing the text if there's no horizontal or vertical // space. @@ -1841,8 +1836,13 @@ static void YGNodelayoutImpl(const YGNodeRef node, YGNodeTrailingPadding(node, flexColumnDirection, parentWidth); if (node->measure) { - YGNodeWithMeasureFuncSetMeasuredDimensions( - node, availableWidth, availableHeight, widthMeasureMode, heightMeasureMode); + YGNodeWithMeasureFuncSetMeasuredDimensions(node, + availableWidth, + availableHeight, + widthMeasureMode, + heightMeasureMode, + parentWidth, + parentHeight); return; } From 6ceb4af2d48b8f2b6ed4abb0239b5095799e1cee Mon Sep 17 00:00:00 2001 From: Emil Sjolander Date: Sat, 11 Feb 2017 06:19:52 -0800 Subject: [PATCH 02/20] Expose layout border to java Summary: Expose layout border to java Reviewed By: astreet Differential Revision: D4543284 fbshipit-source-id: 6030915fc6f758e785a688f94c8ffbec7fbac8b8 --- java/com/facebook/yoga/YogaNode.java | 28 +++++++++++++++++++ java/com/facebook/yoga/YogaNodeAPI.java | 1 + java/jni/YGJNI.cpp | 10 +++++++ .../tests/com/facebook/yoga/YogaNodeTest.java | 17 +++++++++++ 4 files changed, 56 insertions(+) diff --git a/java/com/facebook/yoga/YogaNode.java b/java/com/facebook/yoga/YogaNode.java index 1bca0372..c53aecc6 100644 --- a/java/com/facebook/yoga/YogaNode.java +++ b/java/com/facebook/yoga/YogaNode.java @@ -86,6 +86,14 @@ public class YogaNode implements YogaNodeAPI { @DoNotStrip private float mPaddingBottom = 0; @DoNotStrip + private float mBorderLeft = 0; + @DoNotStrip + private float mBorderTop = 0; + @DoNotStrip + private float mBorderRight = 0; + @DoNotStrip + private float mBorderBottom = 0; + @DoNotStrip private int mLayoutDirection = 0; private native long jni_YGNodeNew(); @@ -633,6 +641,26 @@ public class YogaNode implements YogaNodeAPI { } } + @Override + public float getLayoutBorder(YogaEdge edge) { + switch (edge) { + case LEFT: + return mBorderLeft; + case TOP: + return mBorderTop; + case RIGHT: + return mBorderRight; + case BOTTOM: + return mBorderBottom; + case START: + return getLayoutDirection() == YogaDirection.RTL ? mBorderRight : mBorderLeft; + case END: + return getLayoutDirection() == YogaDirection.RTL ? mBorderLeft : mBorderRight; + default: + throw new IllegalArgumentException("Cannot get layout border of multi-edge shorthands"); + } + } + @Override public YogaDirection getLayoutDirection() { return YogaDirection.fromInt(mLayoutDirection); diff --git a/java/com/facebook/yoga/YogaNodeAPI.java b/java/com/facebook/yoga/YogaNodeAPI.java index a2ca3200..406ec587 100644 --- a/java/com/facebook/yoga/YogaNodeAPI.java +++ b/java/com/facebook/yoga/YogaNodeAPI.java @@ -84,6 +84,7 @@ public interface YogaNodeAPI { float getLayoutHeight(); float getLayoutMargin(YogaEdge edge); float getLayoutPadding(YogaEdge edge); + float getLayoutBorder(YogaEdge edge); YogaDirection getLayoutDirection(); YogaOverflow getOverflow(); void setOverflow(YogaOverflow overflow); diff --git a/java/jni/YGJNI.cpp b/java/jni/YGJNI.cpp index 8476bc1b..92923543 100644 --- a/java/jni/YGJNI.cpp +++ b/java/jni/YGJNI.cpp @@ -40,6 +40,11 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) { static auto paddingRightField = obj->getClass()->getField("mPaddingRight"); static auto paddingBottomField = obj->getClass()->getField("mPaddingBottom"); + static auto borderLeftField = obj->getClass()->getField("mBorderLeft"); + static auto borderTopField = obj->getClass()->getField("mBorderTop"); + static auto borderRightField = obj->getClass()->getField("mBorderRight"); + static auto borderBottomField = obj->getClass()->getField("mBorderBottom"); + obj->setFieldValue(widthField, YGNodeLayoutGetWidth(root)); obj->setFieldValue(heightField, YGNodeLayoutGetHeight(root)); obj->setFieldValue(leftField, YGNodeLayoutGetLeft(root)); @@ -55,6 +60,11 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) { obj->setFieldValue(paddingRightField, YGNodeLayoutGetPadding(root, YGEdgeRight)); obj->setFieldValue(paddingBottomField, YGNodeLayoutGetPadding(root, YGEdgeBottom)); + obj->setFieldValue(borderLeftField, YGNodeLayoutGetBorder(root, YGEdgeLeft)); + obj->setFieldValue(borderTopField, YGNodeLayoutGetBorder(root, YGEdgeTop)); + obj->setFieldValue(borderRightField, YGNodeLayoutGetBorder(root, YGEdgeRight)); + obj->setFieldValue(borderBottomField, YGNodeLayoutGetBorder(root, YGEdgeBottom)); + YGTransferLayoutDirection(root, obj); for (uint32_t i = 0; i < YGNodeGetChildCount(root); i++) { diff --git a/java/tests/com/facebook/yoga/YogaNodeTest.java b/java/tests/com/facebook/yoga/YogaNodeTest.java index 60953f2e..e5575d46 100644 --- a/java/tests/com/facebook/yoga/YogaNodeTest.java +++ b/java/tests/com/facebook/yoga/YogaNodeTest.java @@ -202,6 +202,23 @@ public class YogaNodeTest { assertEquals(4, (int) node.getLayoutPadding(YogaEdge.BOTTOM)); } + @Test + public void testLayoutBorder() { + final YogaNode node = new YogaNode(); + node.setWidth(100); + node.setHeight(100); + node.setBorder(YogaEdge.START, 1); + node.setBorder(YogaEdge.END, 2); + node.setBorder(YogaEdge.TOP, 3); + node.setBorder(YogaEdge.BOTTOM, 4); + node.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(1, (int) node.getLayoutBorder(YogaEdge.LEFT)); + assertEquals(2, (int) node.getLayoutBorder(YogaEdge.RIGHT)); + assertEquals(3, (int) node.getLayoutBorder(YogaEdge.TOP)); + assertEquals(4, (int) node.getLayoutBorder(YogaEdge.BOTTOM)); + } + @Test public void testPercentPaddingOnRoot() { final YogaNode node = new YogaNode(); From 168ae4099d039d20129f44d4eb63499e00db9073 Mon Sep 17 00:00:00 2001 From: Emil Sjolander Date: Sat, 11 Feb 2017 06:19:56 -0800 Subject: [PATCH 03/20] Always return undefined value if nothing is set Summary: This reflects a check to native code where style values will always return the value that was set on them and default to undefined. Reviewed By: astreet Differential Revision: D4531779 fbshipit-source-id: 97a789e70dcf0fb5174e2039991e7a2b27f45f01 --- java/com/facebook/yoga/YogaNode.java | 6 +++--- java/tests/com/facebook/yoga/YogaNodeTest.java | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/java/com/facebook/yoga/YogaNode.java b/java/com/facebook/yoga/YogaNode.java index c53aecc6..08edbd46 100644 --- a/java/com/facebook/yoga/YogaNode.java +++ b/java/com/facebook/yoga/YogaNode.java @@ -382,7 +382,7 @@ public class YogaNode implements YogaNodeAPI { @Override public YogaValue getMargin(YogaEdge edge) { if (!mHasSetMargin) { - return edge.intValue() < YogaEdge.START.intValue() ? YogaValue.ZERO : YogaValue.UNDEFINED; + return YogaValue.UNDEFINED; } return (YogaValue) jni_YGNodeStyleGetMargin(mNativePointer, edge.intValue()); } @@ -405,7 +405,7 @@ public class YogaNode implements YogaNodeAPI { @Override public YogaValue getPadding(YogaEdge edge) { if (!mHasSetPadding) { - return edge.intValue() < YogaEdge.START.intValue() ? YogaValue.ZERO : YogaValue.UNDEFINED; + return YogaValue.UNDEFINED; } return (YogaValue) jni_YGNodeStyleGetPadding(mNativePointer, edge.intValue()); } @@ -428,7 +428,7 @@ public class YogaNode implements YogaNodeAPI { @Override public float getBorder(YogaEdge edge) { if (!mHasSetBorder) { - return edge.intValue() < YogaEdge.START.intValue() ? 0 : YogaConstants.UNDEFINED; + return YogaConstants.UNDEFINED; } return jni_YGNodeStyleGetBorder(mNativePointer, edge.intValue()); } diff --git a/java/tests/com/facebook/yoga/YogaNodeTest.java b/java/tests/com/facebook/yoga/YogaNodeTest.java index e5575d46..5b21a28e 100644 --- a/java/tests/com/facebook/yoga/YogaNodeTest.java +++ b/java/tests/com/facebook/yoga/YogaNodeTest.java @@ -230,4 +230,16 @@ public class YogaNodeTest { assertEquals(5, (int) node.getLayoutPadding(YogaEdge.TOP)); assertEquals(5, (int) node.getLayoutPadding(YogaEdge.BOTTOM)); } + + @Test + public void testDefaultEdgeValues() { + final YogaNode node = new YogaNode(); + + for (YogaEdge edge : YogaEdge.values()) { + assertEquals(YogaUnit.UNDEFINED, node.getMargin(edge).unit); + assertEquals(YogaUnit.UNDEFINED, node.getPadding(edge).unit); + assertEquals(YogaUnit.UNDEFINED, node.getPosition(edge).unit); + assertTrue(YogaConstants.isUndefined(node.getBorder(edge))); + } + } } From e0e2a61dfcf5d039f178dcbaa54301c6da27cba3 Mon Sep 17 00:00:00 2001 From: Emil Sjolander Date: Sat, 11 Feb 2017 06:19:58 -0800 Subject: [PATCH 04/20] Use Float.compare in java equals Summary: Handles nans. Also if the unit is undefined there is no need to check the value. Reviewed By: astreet Differential Revision: D4531805 fbshipit-source-id: 723e15381e9fa39837a4c99f726501eda26af11b --- java/com/facebook/yoga/YogaValue.java | 4 ++- .../com/facebook/yoga/YogaValueTest.java | 26 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 java/tests/com/facebook/yoga/YogaValueTest.java diff --git a/java/com/facebook/yoga/YogaValue.java b/java/com/facebook/yoga/YogaValue.java index 1110eded..f9c0ebfc 100644 --- a/java/com/facebook/yoga/YogaValue.java +++ b/java/com/facebook/yoga/YogaValue.java @@ -33,7 +33,9 @@ public class YogaValue { public boolean equals(Object other) { if (other instanceof YogaValue) { final YogaValue otherValue = (YogaValue) other; - return value == otherValue.value && unit == otherValue.unit; + if (unit == otherValue.unit) { + return unit == YogaUnit.UNDEFINED || Float.compare(value, otherValue.value) == 0; + } } return false; } diff --git a/java/tests/com/facebook/yoga/YogaValueTest.java b/java/tests/com/facebook/yoga/YogaValueTest.java new file mode 100644 index 00000000..e299ecbc --- /dev/null +++ b/java/tests/com/facebook/yoga/YogaValueTest.java @@ -0,0 +1,26 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +package com.facebook.yoga; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class YogaValueTest { + + @Test + public void testEquals() { + assertEquals(new YogaValue(0, YogaUnit.UNDEFINED), new YogaValue(0, YogaUnit.UNDEFINED)); + assertEquals(new YogaValue(0, YogaUnit.PIXEL), new YogaValue(0, YogaUnit.PIXEL)); + assertEquals(new YogaValue(0, YogaUnit.PERCENT), new YogaValue(0, YogaUnit.PERCENT)); + assertEquals(new YogaValue(0, YogaUnit.UNDEFINED), new YogaValue(1, YogaUnit.UNDEFINED)); + assertEquals(new YogaValue(Float.NaN, YogaUnit.PIXEL), new YogaValue(Float.NaN, YogaUnit.PIXEL)); + } +} From 3c9f620c77643d8099e24f87e1780c983560131b Mon Sep 17 00:00:00 2001 From: Dustin Shahidehpour Date: Sat, 11 Feb 2017 08:22:55 -0800 Subject: [PATCH 05/20] BREAKING CHANGE: Computed edge values are no longer returned on concrete properties, fix tests. Summary: Now that the Yoga library supports percentage values, the results returned from it's API were changed. `YGNodeStyleGetPadding` returns the explicit value that you set, whereas `YGNodeLayoutGetPadding` returns the computed value. Since we are planning to build support for percentages, I'm modifying our API so that it strictly returns the value that was set. As a result: ``` view.yoga.margin = 10; // view.yoga.margin == 10 // view.yoga.marginLeftWidth == 0 // view.yoga.marginRightWidth == 0 // etc. ``` Reviewed By: emilsjolander Differential Revision: D4543471 fbshipit-source-id: a731025cd4b47e9f1a559c766494fc5a259291ae --- YogaKit/Source/YGLayout.m | 22 ++------ YogaKit/Tests/YogaKitTests.m | 101 ++++++++++++++--------------------- 2 files changed, 43 insertions(+), 80 deletions(-) diff --git a/YogaKit/Source/YGLayout.m b/YogaKit/Source/YGLayout.m index 80d1a244..3e7516c7 100644 --- a/YogaKit/Source/YGLayout.m +++ b/YogaKit/Source/YGLayout.m @@ -43,12 +43,6 @@ return YGNodeStyleGet##property(self.node, edge); \ } -#define YG_SHORTHAND_EDGE_PROPERTY_GETTER(lowercased_name) \ -- (CGFloat)lowercased_name \ -{ \ - return YGUndefined; \ -} - #define YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge) \ - (void)set##capitalized_name:(CGFloat)lowercased_name \ { \ @@ -59,10 +53,6 @@ YG_EDGE_PROPERTY_GETTER(lowercased_name, capitalized_name, property, edge) \ YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge) -#define YG_SHORTHAND_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \ -YG_SHORTHAND_EDGE_PROPERTY_GETTER(lowercased_name) \ -YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge) - #define YG_VALUE_EDGE_PROPERTY_GETTER(objc_lowercased_name, objc_capitalized_name, c_name, edge) \ - (CGFloat)objc_lowercased_name \ { \ @@ -84,10 +74,6 @@ YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge) YG_VALUE_EDGE_PROPERTY_GETTER(lowercased_name, capitalized_name, property, edge) \ YG_VALUE_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge) -#define YG_VALUE_SHORTHAND_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \ -YG_SHORTHAND_EDGE_PROPERTY_GETTER(lowercased_name) \ -YG_VALUE_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge) - #define YG_VALUE_EDGES_PROPERTIES(lowercased_name, capitalized_name) \ YG_VALUE_EDGE_PROPERTY(lowercased_name##Left, capitalized_name##Left, capitalized_name, YGEdgeLeft) \ YG_VALUE_EDGE_PROPERTY(lowercased_name##Top, capitalized_name##Top, capitalized_name, YGEdgeTop) \ @@ -95,9 +81,9 @@ YG_VALUE_EDGE_PROPERTY(lowercased_name##Right, capitalized_name##Right, capitali YG_VALUE_EDGE_PROPERTY(lowercased_name##Bottom, capitalized_name##Bottom, capitalized_name, YGEdgeBottom) \ YG_VALUE_EDGE_PROPERTY(lowercased_name##Start, capitalized_name##Start, capitalized_name, YGEdgeStart) \ YG_VALUE_EDGE_PROPERTY(lowercased_name##End, capitalized_name##End, capitalized_name, YGEdgeEnd) \ -YG_VALUE_SHORTHAND_EDGE_PROPERTY(lowercased_name##Horizontal, capitalized_name##Horizontal, capitalized_name, YGEdgeHorizontal) \ -YG_VALUE_SHORTHAND_EDGE_PROPERTY(lowercased_name##Vertical, capitalized_name##Vertical, capitalized_name, YGEdgeVertical) \ -YG_VALUE_SHORTHAND_EDGE_PROPERTY(lowercased_name, capitalized_name, capitalized_name, YGEdgeAll) +YG_VALUE_EDGE_PROPERTY(lowercased_name##Horizontal, capitalized_name##Horizontal, capitalized_name, YGEdgeHorizontal) \ +YG_VALUE_EDGE_PROPERTY(lowercased_name##Vertical, capitalized_name##Vertical, capitalized_name, YGEdgeVertical) \ +YG_VALUE_EDGE_PROPERTY(lowercased_name, capitalized_name, capitalized_name, YGEdgeAll) @interface YGLayout () @@ -202,7 +188,7 @@ YG_EDGE_PROPERTY(borderRightWidth, BorderRightWidth, Border, YGEdgeRight) YG_EDGE_PROPERTY(borderBottomWidth, BorderBottomWidth, Border, YGEdgeBottom) YG_EDGE_PROPERTY(borderStartWidth, BorderStartWidth, Border, YGEdgeStart) YG_EDGE_PROPERTY(borderEndWidth, BorderEndWidth, Border, YGEdgeEnd) -YG_SHORTHAND_EDGE_PROPERTY(borderWidth, BorderWidth, Border, YGEdgeAll) +YG_EDGE_PROPERTY(borderWidth, BorderWidth, Border, YGEdgeAll) YG_VALUE_PROPERTY(width, Width) YG_VALUE_PROPERTY(height, Height) diff --git a/YogaKit/Tests/YogaKitTests.m b/YogaKit/Tests/YogaKitTests.m index 2180be07..5342f9c3 100644 --- a/YogaKit/Tests/YogaKitTests.m +++ b/YogaKit/Tests/YogaKitTests.m @@ -451,39 +451,27 @@ UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; view.yoga.margin = 1; - XCTAssertEqual(view.yoga.marginLeft, 1); - XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel); - XCTAssertEqual(view.yoga.marginRight, 1); - XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeRight).unit, YGUnitPixel); - XCTAssertEqual(view.yoga.marginStart, 1); - XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeStart).unit, YGUnitPixel); - XCTAssertEqual(view.yoga.marginEnd, 1); - XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel); - XCTAssertEqual(view.yoga.marginTop, 1); - XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeTop).unit, YGUnitPixel); - XCTAssertEqual(view.yoga.marginBottom, 1); - XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.margin, 1); + XCTAssertTrue(isnan(view.yoga.marginLeft)); + XCTAssertTrue(isnan(view.yoga.marginRight)); + XCTAssertTrue(isnan(view.yoga.marginStart)); + XCTAssertTrue(isnan(view.yoga.marginEnd)); + XCTAssertTrue(isnan(view.yoga.marginTop)); + XCTAssertTrue(isnan(view.yoga.marginBottom)); XCTAssertTrue(isnan(view.yoga.marginHorizontal)); XCTAssertTrue(isnan(view.yoga.marginVertical)); - XCTAssertTrue(isnan(view.yoga.margin)); view.yoga.marginHorizontal = 2; - XCTAssertEqual(view.yoga.marginLeft, 2); - XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel); - XCTAssertEqual(view.yoga.marginRight, 2); - XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeRight).unit, YGUnitPixel); - XCTAssertEqual(view.yoga.marginStart, 2); - XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeStart).unit, YGUnitPixel); - XCTAssertEqual(view.yoga.marginEnd, 2); - XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel); - XCTAssertTrue(isnan(view.yoga.marginHorizontal)); + XCTAssertEqual(view.yoga.marginHorizontal, 2); + XCTAssertTrue(isnan(view.yoga.marginLeft)); + XCTAssertTrue(isnan(view.yoga.marginRight)); + XCTAssertTrue(isnan(view.yoga.marginStart)); + XCTAssertTrue(isnan(view.yoga.marginEnd)); view.yoga.marginVertical = 3; - XCTAssertEqual(view.yoga.marginTop, 3); - XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeTop).unit, YGUnitPixel); - XCTAssertEqual(view.yoga.marginBottom, 3); - XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel); - XCTAssertTrue(isnan(view.yoga.marginVertical)); + XCTAssertEqual(view.yoga.marginVertical, 3); + XCTAssertTrue(isnan(view.yoga.marginTop)); + XCTAssertTrue(isnan(view.yoga.marginBottom)); view.yoga.marginLeft = 4; XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeLeft).value, 4); @@ -521,39 +509,27 @@ UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; view.yoga.padding = 1; - XCTAssertEqual(view.yoga.paddingLeft, 1); - XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel); - XCTAssertEqual(view.yoga.paddingRight, 1); - XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeRight).unit, YGUnitPixel); - XCTAssertEqual(view.yoga.paddingStart, 1); - XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeStart).unit, YGUnitPixel); - XCTAssertEqual(view.yoga.paddingEnd, 1); - XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel); - XCTAssertEqual(view.yoga.paddingTop, 1); - XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeTop).unit, YGUnitPixel); - XCTAssertEqual(view.yoga.paddingBottom, 1); - XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.padding, 1); + XCTAssertTrue(isnan(view.yoga.paddingLeft)); + XCTAssertTrue(isnan(view.yoga.paddingRight)); + XCTAssertTrue(isnan(view.yoga.paddingStart)); + XCTAssertTrue(isnan(view.yoga.paddingEnd)); + XCTAssertTrue(isnan(view.yoga.paddingTop)); + XCTAssertTrue(isnan(view.yoga.paddingBottom)); XCTAssertTrue(isnan(view.yoga.paddingHorizontal)); XCTAssertTrue(isnan(view.yoga.paddingVertical)); - XCTAssertTrue(isnan(view.yoga.padding)); view.yoga.paddingHorizontal = 2; - XCTAssertEqual(view.yoga.paddingLeft, 2); - XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel); - XCTAssertEqual(view.yoga.paddingRight, 2); - XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeRight).unit, YGUnitPixel); - XCTAssertEqual(view.yoga.paddingStart, 2); - XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeStart).unit, YGUnitPixel); - XCTAssertEqual(view.yoga.paddingEnd, 2); - XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel); - XCTAssertTrue(isnan(view.yoga.paddingHorizontal)); + XCTAssertEqual(view.yoga.paddingHorizontal, 2); + XCTAssertTrue(isnan(view.yoga.paddingLeft)); + XCTAssertTrue(isnan(view.yoga.paddingRight)); + XCTAssertTrue(isnan(view.yoga.paddingStart)); + XCTAssertTrue(isnan(view.yoga.paddingEnd)); view.yoga.paddingVertical = 3; - XCTAssertEqual(view.yoga.paddingTop, 3); - XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeTop).unit, YGUnitPixel); - XCTAssertEqual(view.yoga.paddingBottom, 3); - XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel); - XCTAssertTrue(isnan(view.yoga.paddingVertical)); + XCTAssertEqual(view.yoga.paddingVertical, 3); + XCTAssertTrue(isnan(view.yoga.paddingTop)); + XCTAssertTrue(isnan(view.yoga.paddingBottom)); view.yoga.paddingLeft = 4; XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeLeft).value, 4); @@ -591,13 +567,13 @@ UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; view.yoga.borderWidth = 1; - XCTAssertEqual(view.yoga.borderLeftWidth, 1); - XCTAssertEqual(view.yoga.borderRightWidth, 1); - XCTAssertEqual(view.yoga.borderStartWidth, 1); - XCTAssertEqual(view.yoga.borderEndWidth, 1); - XCTAssertEqual(view.yoga.borderTopWidth, 1); - XCTAssertEqual(view.yoga.borderBottomWidth, 1); - XCTAssertTrue(isnan(view.yoga.borderWidth)); + XCTAssertEqual(view.yoga.borderWidth, 1); + XCTAssertTrue(isnan(view.yoga.borderLeftWidth)); + XCTAssertTrue(isnan(view.yoga.borderRightWidth)); + XCTAssertTrue(isnan(view.yoga.borderStartWidth)); + XCTAssertTrue(isnan(view.yoga.borderEndWidth)); + XCTAssertTrue(isnan(view.yoga.borderTopWidth)); + XCTAssertTrue(isnan(view.yoga.borderBottomWidth)); view.yoga.borderLeftWidth = 2; XCTAssertEqual(view.yoga.borderLeftWidth, 2); @@ -618,7 +594,8 @@ XCTAssertEqual(view.yoga.borderEndWidth, 7); } -- (void)testOriginIsPreservedOnRootOfLayout { +- (void)testOriginIsPreservedOnRootOfLayout +{ const CGSize containerSize = CGSizeMake(200, 50); UIView *container = [[UIView alloc] initWithFrame:CGRectMake(10, 10, containerSize.width, containerSize.height)]; From 247aa26d3e98c4749636d9130ff1432568c2575a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20W=C3=B6hrl?= Date: Sat, 11 Feb 2017 08:32:47 -0800 Subject: [PATCH 06/20] Make enums.py c header output resistent to format.sh Summary: This PR changes the enums.py to create the header the same as format.sh would layout it. Reduces the clutter due to missed format.sh calls after enums.py generation. Closes https://github.com/facebook/yoga/pull/380 Reviewed By: gkassabli Differential Revision: D4529593 Pulled By: emilsjolander fbshipit-source-id: 7281e0d500f79459c19cc8fe6dbc8fd77f0a537c --- format.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/format.sh b/format.sh index d1bbb9c0..ee4d91f9 100755 --- a/format.sh +++ b/format.sh @@ -2,7 +2,7 @@ BASEDIR="$(dirname "$0")" FILES=$(find "$BASEDIR" \( -path "$BASEDIR/buck-out" -o -path "$BASEDIR/lib" \) -prune -o \ - \( -name \*.h -o -name \*.c -o -name \*.cpp \) -print) + \( -name \*.h ! -name YGEnums.h -o -name \*.c -o -name \*.cpp \) -print) for f in $FILES "$@"; do clang-format \ From 6a7ad2125d2ecb1daf9c0c748b66be959dc18f06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20W=C3=B6hrl?= Date: Sat, 11 Feb 2017 08:32:48 -0800 Subject: [PATCH 07/20] Add support for space-between and space-around on align-content Summary: Adds the two missing alignments ```space-between``` and ```space-around``` for ```align-content``` . Those values are a noop on ```align-items``` in order to prevent a breaking changes for an additional enum. Fix #229 Closes https://github.com/facebook/yoga/pull/364 Reviewed By: gkassabli Differential Revision: D4528561 Pulled By: emilsjolander fbshipit-source-id: ea6291b6dd22cef05d9eec03893250d50371236e --- csharp/Facebook.Yoga/YogaAlign.cs | 2 + .../tests/Facebook.Yoga/YGAlignContentTest.cs | 337 +++++++++++++---- enums.py | 2 + gentest/fixtures/YGAlignContentTest.html | 24 +- gentest/gentest-cpp.js | 3 +- gentest/gentest-cs.js | 2 + gentest/gentest-java.js | 2 + gentest/gentest-javascript.js | 2 + gentest/gentest.js | 2 + java/com/facebook/yoga/YogaAlign.java | 6 +- .../com/facebook/yoga/YGAlignContentTest.java | 335 +++++++++++++---- javascript/sources/YGEnums.js | 4 +- .../tests/Facebook.Yoga/YGAlignContentTest.js | 339 ++++++++++++++---- tests/YGAlignContentTest.cpp | 333 +++++++++++++---- yoga/YGEnums.h | 4 +- yoga/Yoga.c | 19 +- 16 files changed, 1143 insertions(+), 273 deletions(-) diff --git a/csharp/Facebook.Yoga/YogaAlign.cs b/csharp/Facebook.Yoga/YogaAlign.cs index 71b8b33b..62ff9269 100644 --- a/csharp/Facebook.Yoga/YogaAlign.cs +++ b/csharp/Facebook.Yoga/YogaAlign.cs @@ -17,5 +17,7 @@ namespace Facebook.Yoga FlexEnd, Stretch, Baseline, + SpaceBetween, + SpaceAround, } } diff --git a/csharp/tests/Facebook.Yoga/YGAlignContentTest.cs b/csharp/tests/Facebook.Yoga/YGAlignContentTest.cs index 560fa3c7..c73d6761 100644 --- a/csharp/tests/Facebook.Yoga/YGAlignContentTest.cs +++ b/csharp/tests/Facebook.Yoga/YGAlignContentTest.cs @@ -21,8 +21,9 @@ namespace Facebook.Yoga public void Test_align_content_flex_start() { YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; root.Wrap = YogaWrap.Wrap; - root.Width = 100; + root.Width = 130; root.Height = 100; YogaNode root_child0 = new YogaNode(); @@ -54,7 +55,7 @@ namespace Facebook.Yoga Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(130f, root.LayoutWidth); Assert.AreEqual(100f, root.LayoutHeight); Assert.AreEqual(0f, root_child0.LayoutX); @@ -62,23 +63,23 @@ namespace Facebook.Yoga Assert.AreEqual(50f, root_child0.LayoutWidth); Assert.AreEqual(10f, root_child0.LayoutHeight); - Assert.AreEqual(0f, root_child1.LayoutX); - Assert.AreEqual(10f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); Assert.AreEqual(50f, root_child1.LayoutWidth); Assert.AreEqual(10f, root_child1.LayoutHeight); Assert.AreEqual(0f, root_child2.LayoutX); - Assert.AreEqual(20f, root_child2.LayoutY); + Assert.AreEqual(10f, root_child2.LayoutY); Assert.AreEqual(50f, root_child2.LayoutWidth); Assert.AreEqual(10f, root_child2.LayoutHeight); - Assert.AreEqual(0f, root_child3.LayoutX); - Assert.AreEqual(30f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutX); + Assert.AreEqual(10f, root_child3.LayoutY); Assert.AreEqual(50f, root_child3.LayoutWidth); Assert.AreEqual(10f, root_child3.LayoutHeight); Assert.AreEqual(0f, root_child4.LayoutX); - Assert.AreEqual(40f, root_child4.LayoutY); + Assert.AreEqual(20f, root_child4.LayoutY); Assert.AreEqual(50f, root_child4.LayoutWidth); Assert.AreEqual(10f, root_child4.LayoutHeight); @@ -87,31 +88,31 @@ namespace Facebook.Yoga Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(130f, root.LayoutWidth); Assert.AreEqual(100f, root.LayoutHeight); - Assert.AreEqual(50f, root_child0.LayoutX); + Assert.AreEqual(80f, root_child0.LayoutX); Assert.AreEqual(0f, root_child0.LayoutY); Assert.AreEqual(50f, root_child0.LayoutWidth); Assert.AreEqual(10f, root_child0.LayoutHeight); - Assert.AreEqual(50f, root_child1.LayoutX); - Assert.AreEqual(10f, root_child1.LayoutY); + Assert.AreEqual(30f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); Assert.AreEqual(50f, root_child1.LayoutWidth); Assert.AreEqual(10f, root_child1.LayoutHeight); - Assert.AreEqual(50f, root_child2.LayoutX); - Assert.AreEqual(20f, root_child2.LayoutY); + Assert.AreEqual(80f, root_child2.LayoutX); + Assert.AreEqual(10f, root_child2.LayoutY); Assert.AreEqual(50f, root_child2.LayoutWidth); Assert.AreEqual(10f, root_child2.LayoutHeight); - Assert.AreEqual(50f, root_child3.LayoutX); - Assert.AreEqual(30f, root_child3.LayoutY); + Assert.AreEqual(30f, root_child3.LayoutX); + Assert.AreEqual(10f, root_child3.LayoutY); Assert.AreEqual(50f, root_child3.LayoutWidth); Assert.AreEqual(10f, root_child3.LayoutHeight); - Assert.AreEqual(50f, root_child4.LayoutX); - Assert.AreEqual(40f, root_child4.LayoutY); + Assert.AreEqual(80f, root_child4.LayoutX); + Assert.AreEqual(20f, root_child4.LayoutY); Assert.AreEqual(50f, root_child4.LayoutWidth); Assert.AreEqual(10f, root_child4.LayoutHeight); } @@ -120,9 +121,10 @@ namespace Facebook.Yoga public void Test_align_content_flex_end() { YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; root.AlignContent = YogaAlign.FlexEnd; root.Wrap = YogaWrap.Wrap; - root.Width = 100; + root.Width = 130; root.Height = 100; YogaNode root_child0 = new YogaNode(); @@ -154,31 +156,31 @@ namespace Facebook.Yoga Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(130f, root.LayoutWidth); Assert.AreEqual(100f, root.LayoutHeight); Assert.AreEqual(0f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(70f, root_child0.LayoutY); Assert.AreEqual(50f, root_child0.LayoutWidth); Assert.AreEqual(10f, root_child0.LayoutHeight); - Assert.AreEqual(0f, root_child1.LayoutX); - Assert.AreEqual(10f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(70f, root_child1.LayoutY); Assert.AreEqual(50f, root_child1.LayoutWidth); Assert.AreEqual(10f, root_child1.LayoutHeight); Assert.AreEqual(0f, root_child2.LayoutX); - Assert.AreEqual(20f, root_child2.LayoutY); + Assert.AreEqual(80f, root_child2.LayoutY); Assert.AreEqual(50f, root_child2.LayoutWidth); Assert.AreEqual(10f, root_child2.LayoutHeight); - Assert.AreEqual(0f, root_child3.LayoutX); - Assert.AreEqual(30f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutX); + Assert.AreEqual(80f, root_child3.LayoutY); Assert.AreEqual(50f, root_child3.LayoutWidth); Assert.AreEqual(10f, root_child3.LayoutHeight); Assert.AreEqual(0f, root_child4.LayoutX); - Assert.AreEqual(40f, root_child4.LayoutY); + Assert.AreEqual(90f, root_child4.LayoutY); Assert.AreEqual(50f, root_child4.LayoutWidth); Assert.AreEqual(10f, root_child4.LayoutHeight); @@ -187,31 +189,31 @@ namespace Facebook.Yoga Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(130f, root.LayoutWidth); Assert.AreEqual(100f, root.LayoutHeight); - Assert.AreEqual(50f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(80f, root_child0.LayoutX); + Assert.AreEqual(70f, root_child0.LayoutY); Assert.AreEqual(50f, root_child0.LayoutWidth); Assert.AreEqual(10f, root_child0.LayoutHeight); - Assert.AreEqual(50f, root_child1.LayoutX); - Assert.AreEqual(10f, root_child1.LayoutY); + Assert.AreEqual(30f, root_child1.LayoutX); + Assert.AreEqual(70f, root_child1.LayoutY); Assert.AreEqual(50f, root_child1.LayoutWidth); Assert.AreEqual(10f, root_child1.LayoutHeight); - Assert.AreEqual(50f, root_child2.LayoutX); - Assert.AreEqual(20f, root_child2.LayoutY); + Assert.AreEqual(80f, root_child2.LayoutX); + Assert.AreEqual(80f, root_child2.LayoutY); Assert.AreEqual(50f, root_child2.LayoutWidth); Assert.AreEqual(10f, root_child2.LayoutHeight); - Assert.AreEqual(50f, root_child3.LayoutX); - Assert.AreEqual(30f, root_child3.LayoutY); + Assert.AreEqual(30f, root_child3.LayoutX); + Assert.AreEqual(80f, root_child3.LayoutY); Assert.AreEqual(50f, root_child3.LayoutWidth); Assert.AreEqual(10f, root_child3.LayoutHeight); - Assert.AreEqual(50f, root_child4.LayoutX); - Assert.AreEqual(40f, root_child4.LayoutY); + Assert.AreEqual(80f, root_child4.LayoutX); + Assert.AreEqual(90f, root_child4.LayoutY); Assert.AreEqual(50f, root_child4.LayoutWidth); Assert.AreEqual(10f, root_child4.LayoutHeight); } @@ -220,9 +222,10 @@ namespace Facebook.Yoga public void Test_align_content_center() { YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; root.AlignContent = YogaAlign.Center; root.Wrap = YogaWrap.Wrap; - root.Width = 100; + root.Width = 130; root.Height = 100; YogaNode root_child0 = new YogaNode(); @@ -254,31 +257,31 @@ namespace Facebook.Yoga Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(130f, root.LayoutWidth); Assert.AreEqual(100f, root.LayoutHeight); Assert.AreEqual(0f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(35f, root_child0.LayoutY); Assert.AreEqual(50f, root_child0.LayoutWidth); Assert.AreEqual(10f, root_child0.LayoutHeight); - Assert.AreEqual(0f, root_child1.LayoutX); - Assert.AreEqual(10f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(35f, root_child1.LayoutY); Assert.AreEqual(50f, root_child1.LayoutWidth); Assert.AreEqual(10f, root_child1.LayoutHeight); Assert.AreEqual(0f, root_child2.LayoutX); - Assert.AreEqual(20f, root_child2.LayoutY); + Assert.AreEqual(45f, root_child2.LayoutY); Assert.AreEqual(50f, root_child2.LayoutWidth); Assert.AreEqual(10f, root_child2.LayoutHeight); - Assert.AreEqual(0f, root_child3.LayoutX); - Assert.AreEqual(30f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutX); + Assert.AreEqual(45f, root_child3.LayoutY); Assert.AreEqual(50f, root_child3.LayoutWidth); Assert.AreEqual(10f, root_child3.LayoutHeight); Assert.AreEqual(0f, root_child4.LayoutX); - Assert.AreEqual(40f, root_child4.LayoutY); + Assert.AreEqual(55f, root_child4.LayoutY); Assert.AreEqual(50f, root_child4.LayoutWidth); Assert.AreEqual(10f, root_child4.LayoutHeight); @@ -287,31 +290,31 @@ namespace Facebook.Yoga Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(130f, root.LayoutWidth); Assert.AreEqual(100f, root.LayoutHeight); - Assert.AreEqual(50f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(80f, root_child0.LayoutX); + Assert.AreEqual(35f, root_child0.LayoutY); Assert.AreEqual(50f, root_child0.LayoutWidth); Assert.AreEqual(10f, root_child0.LayoutHeight); - Assert.AreEqual(50f, root_child1.LayoutX); - Assert.AreEqual(10f, root_child1.LayoutY); + Assert.AreEqual(30f, root_child1.LayoutX); + Assert.AreEqual(35f, root_child1.LayoutY); Assert.AreEqual(50f, root_child1.LayoutWidth); Assert.AreEqual(10f, root_child1.LayoutHeight); - Assert.AreEqual(50f, root_child2.LayoutX); - Assert.AreEqual(20f, root_child2.LayoutY); + Assert.AreEqual(80f, root_child2.LayoutX); + Assert.AreEqual(45f, root_child2.LayoutY); Assert.AreEqual(50f, root_child2.LayoutWidth); Assert.AreEqual(10f, root_child2.LayoutHeight); - Assert.AreEqual(50f, root_child3.LayoutX); - Assert.AreEqual(30f, root_child3.LayoutY); + Assert.AreEqual(30f, root_child3.LayoutX); + Assert.AreEqual(45f, root_child3.LayoutY); Assert.AreEqual(50f, root_child3.LayoutWidth); Assert.AreEqual(10f, root_child3.LayoutHeight); - Assert.AreEqual(50f, root_child4.LayoutX); - Assert.AreEqual(40f, root_child4.LayoutY); + Assert.AreEqual(80f, root_child4.LayoutX); + Assert.AreEqual(55f, root_child4.LayoutY); Assert.AreEqual(50f, root_child4.LayoutWidth); Assert.AreEqual(10f, root_child4.LayoutHeight); } @@ -322,7 +325,7 @@ namespace Facebook.Yoga YogaNode root = new YogaNode(); root.AlignContent = YogaAlign.Stretch; root.Wrap = YogaWrap.Wrap; - root.Width = 100; + root.Width = 150; root.Height = 100; YogaNode root_child0 = new YogaNode(); @@ -349,7 +352,7 @@ namespace Facebook.Yoga Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(150f, root.LayoutWidth); Assert.AreEqual(100f, root.LayoutHeight); Assert.AreEqual(0f, root_child0.LayoutX); @@ -382,34 +385,236 @@ namespace Facebook.Yoga Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(150f, root.LayoutWidth); Assert.AreEqual(100f, root.LayoutHeight); - Assert.AreEqual(50f, root_child0.LayoutX); + Assert.AreEqual(100f, root_child0.LayoutX); Assert.AreEqual(0f, root_child0.LayoutY); Assert.AreEqual(50f, root_child0.LayoutWidth); Assert.AreEqual(0f, root_child0.LayoutHeight); - Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(100f, root_child1.LayoutX); Assert.AreEqual(0f, root_child1.LayoutY); Assert.AreEqual(50f, root_child1.LayoutWidth); Assert.AreEqual(0f, root_child1.LayoutHeight); - Assert.AreEqual(50f, root_child2.LayoutX); + Assert.AreEqual(100f, root_child2.LayoutX); Assert.AreEqual(0f, root_child2.LayoutY); Assert.AreEqual(50f, root_child2.LayoutWidth); Assert.AreEqual(0f, root_child2.LayoutHeight); - Assert.AreEqual(50f, root_child3.LayoutX); + Assert.AreEqual(100f, root_child3.LayoutX); Assert.AreEqual(0f, root_child3.LayoutY); Assert.AreEqual(50f, root_child3.LayoutWidth); Assert.AreEqual(0f, root_child3.LayoutHeight); - Assert.AreEqual(50f, root_child4.LayoutX); + Assert.AreEqual(100f, root_child4.LayoutX); Assert.AreEqual(0f, root_child4.LayoutY); Assert.AreEqual(50f, root_child4.LayoutWidth); Assert.AreEqual(0f, root_child4.LayoutHeight); } + [Test] + public void Test_align_content_spacebetween() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.AlignContent = YogaAlign.SpaceBetween; + root.Wrap = YogaWrap.Wrap; + root.Width = 130; + root.Height = 100; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 50; + root_child0.Height = 10; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Width = 50; + root_child1.Height = 10; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 50; + root_child2.Height = 10; + root.Insert(2, root_child2); + + YogaNode root_child3 = new YogaNode(); + root_child3.Width = 50; + root_child3.Height = 10; + root.Insert(3, root_child3); + + YogaNode root_child4 = new YogaNode(); + root_child4.Width = 50; + root_child4.Height = 10; + root.Insert(4, root_child4); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(130f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(10f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(45f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(10f, root_child2.LayoutHeight); + + Assert.AreEqual(50f, root_child3.LayoutX); + Assert.AreEqual(45f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(10f, root_child3.LayoutHeight); + + Assert.AreEqual(0f, root_child4.LayoutX); + Assert.AreEqual(90f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(10f, root_child4.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(130f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(80f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(30f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(10f, root_child1.LayoutHeight); + + Assert.AreEqual(80f, root_child2.LayoutX); + Assert.AreEqual(45f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(10f, root_child2.LayoutHeight); + + Assert.AreEqual(30f, root_child3.LayoutX); + Assert.AreEqual(45f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(10f, root_child3.LayoutHeight); + + Assert.AreEqual(80f, root_child4.LayoutX); + Assert.AreEqual(90f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(10f, root_child4.LayoutHeight); + } + + [Test] + public void Test_align_content_spacearound() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.AlignContent = YogaAlign.SpaceAround; + root.Wrap = YogaWrap.Wrap; + root.Width = 140; + root.Height = 120; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 50; + root_child0.Height = 10; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Width = 50; + root_child1.Height = 10; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 50; + root_child2.Height = 10; + root.Insert(2, root_child2); + + YogaNode root_child3 = new YogaNode(); + root_child3.Width = 50; + root_child3.Height = 10; + root.Insert(3, root_child3); + + YogaNode root_child4 = new YogaNode(); + root_child4.Width = 50; + root_child4.Height = 10; + root.Insert(4, root_child4); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(140f, root.LayoutWidth); + Assert.AreEqual(120f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(15f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(15f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(10f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(55f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(10f, root_child2.LayoutHeight); + + Assert.AreEqual(50f, root_child3.LayoutX); + Assert.AreEqual(55f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(10f, root_child3.LayoutHeight); + + Assert.AreEqual(0f, root_child4.LayoutX); + Assert.AreEqual(95f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(10f, root_child4.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(140f, root.LayoutWidth); + Assert.AreEqual(120f, root.LayoutHeight); + + Assert.AreEqual(90f, root_child0.LayoutX); + Assert.AreEqual(15f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(40f, root_child1.LayoutX); + Assert.AreEqual(15f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(10f, root_child1.LayoutHeight); + + Assert.AreEqual(90f, root_child2.LayoutX); + Assert.AreEqual(55f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(10f, root_child2.LayoutHeight); + + Assert.AreEqual(40f, root_child3.LayoutX); + Assert.AreEqual(55f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(10f, root_child3.LayoutHeight); + + Assert.AreEqual(90f, root_child4.LayoutX); + Assert.AreEqual(95f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(10f, root_child4.LayoutHeight); + } + } } diff --git a/enums.py b/enums.py index 47ff69ca..83c582db 100644 --- a/enums.py +++ b/enums.py @@ -47,6 +47,8 @@ ENUMS = { 'FlexEnd', 'Stretch', 'Baseline', + 'SpaceBetween', + 'SpaceAround', ], 'PositionType': [ 'Relative', diff --git a/gentest/fixtures/YGAlignContentTest.html b/gentest/fixtures/YGAlignContentTest.html index e0ead38f..b1f23050 100644 --- a/gentest/fixtures/YGAlignContentTest.html +++ b/gentest/fixtures/YGAlignContentTest.html @@ -1,4 +1,4 @@ -
+
@@ -6,7 +6,7 @@
-
+
@@ -14,7 +14,7 @@
-
+
@@ -22,10 +22,26 @@
-
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
diff --git a/gentest/gentest-cpp.js b/gentest/gentest-cpp.js index d8a74a1c..4a4896f4 100644 --- a/gentest/gentest-cpp.js +++ b/gentest/gentest-cpp.js @@ -82,7 +82,8 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, { YGAlignFlexEnd:{value:'YGAlignFlexEnd'}, YGAlignFlexStart:{value:'YGAlignFlexStart'}, YGAlignStretch:{value:'YGAlignStretch'}, - + YGAlignSpaceBetween:{value:'YGAlignSpaceBetween'}, + YGAlignSpaceAround:{value:'YGAlignSpaceAround'}, YGAlignBaseline:{value:'YGAlignBaseline'}, YGDirectionInherit:{value:'YGDirectionInherit'}, diff --git a/gentest/gentest-cs.js b/gentest/gentest-cs.js index 3650d862..06c0c3f3 100644 --- a/gentest/gentest-cs.js +++ b/gentest/gentest-cs.js @@ -96,6 +96,8 @@ CSEmitter.prototype = Object.create(Emitter.prototype, { YGAlignFlexEnd:{value:'YogaAlign.FlexEnd'}, YGAlignFlexStart:{value:'YogaAlign.FlexStart'}, YGAlignStretch:{value:'YogaAlign.Stretch'}, + YGAlignSpaceBetween:{value:'YogaAlign.SpaceBetween'}, + YGAlignSpaceAround:{value:'YogaAlign.SpaceAround'}, YGAlignBaseline:{value:'YogaAlign.Baseline'}, YGDirectionInherit:{value:'YogaDirection.Inherit'}, diff --git a/gentest/gentest-java.js b/gentest/gentest-java.js index e5b1858d..6ca39952 100644 --- a/gentest/gentest-java.js +++ b/gentest/gentest-java.js @@ -100,6 +100,8 @@ JavaEmitter.prototype = Object.create(Emitter.prototype, { YGAlignFlexEnd:{value:'YogaAlign.FLEX_END'}, YGAlignFlexStart:{value:'YogaAlign.FLEX_START'}, YGAlignStretch:{value:'YogaAlign.STRETCH'}, + YGAlignSpaceBetween:{value:'YogaAlign.SPACE_BETWEEN'}, + YGAlignSpaceAround:{value:'YogaAlign.SPACE_AROUND'}, YGAlignBaseline:{value:'YogaAlign.BASELINE'}, YGDirectionInherit:{value:'YogaDirection.INHERIT'}, diff --git a/gentest/gentest-javascript.js b/gentest/gentest-javascript.js index 67c38e83..803a5a3b 100644 --- a/gentest/gentest-javascript.js +++ b/gentest/gentest-javascript.js @@ -90,6 +90,8 @@ JavascriptEmitter.prototype = Object.create(Emitter.prototype, { YGAlignFlexEnd:{value:'Yoga.ALIGN_FLEX_END'}, YGAlignFlexStart:{value:'Yoga.ALIGN_FLEX_START'}, YGAlignStretch:{value:'Yoga.ALIGN_STRETCH'}, + YGAlignSpaceBetween:{value:'Yoga.ALIGN_SPACE_BETWEEN'}, + YGAlignSpaceAround:{value:'Yoga.ALIGN_SPACE_AROUND'}, YGAlignBaseline:{value:'Yoga.ALIGN_BASELINE'}, YGDirectionInherit:{value:'Yoga.DIRECTION_INHERIT'}, diff --git a/gentest/gentest.js b/gentest/gentest.js index 98559988..72c252f8 100755 --- a/gentest/gentest.js +++ b/gentest/gentest.js @@ -381,6 +381,8 @@ function alignValue(e, value) { case 'stretch': return e.YGAlignStretch; case 'flex-start': return e.YGAlignFlexStart; case 'flex-end': return e.YGAlignFlexEnd; + case 'space-between': return e.YGAlignSpaceBetween; + case 'space-around': return e.YGAlignSpaceAround; case 'baseline': return e.YGAlignBaseline; } } diff --git a/java/com/facebook/yoga/YogaAlign.java b/java/com/facebook/yoga/YogaAlign.java index 885ecda0..7a3e13e9 100644 --- a/java/com/facebook/yoga/YogaAlign.java +++ b/java/com/facebook/yoga/YogaAlign.java @@ -18,7 +18,9 @@ public enum YogaAlign { CENTER(2), FLEX_END(3), STRETCH(4), - BASELINE(5); + BASELINE(5), + SPACE_BETWEEN(6), + SPACE_AROUND(7); private int mIntValue; @@ -38,6 +40,8 @@ public enum YogaAlign { case 3: return FLEX_END; case 4: return STRETCH; case 5: return BASELINE; + case 6: return SPACE_BETWEEN; + case 7: return SPACE_AROUND; default: throw new IllegalArgumentException("Unknown enum value: " + value); } } diff --git a/java/tests/com/facebook/yoga/YGAlignContentTest.java b/java/tests/com/facebook/yoga/YGAlignContentTest.java index 5c57fc4c..de9daa1b 100644 --- a/java/tests/com/facebook/yoga/YGAlignContentTest.java +++ b/java/tests/com/facebook/yoga/YGAlignContentTest.java @@ -19,8 +19,9 @@ public class YGAlignContentTest { @Test public void test_align_content_flex_start() { final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); root.setWrap(YogaWrap.WRAP); - root.setWidth(100f); + root.setWidth(130f); root.setHeight(100f); final YogaNode root_child0 = new YogaNode(); @@ -52,7 +53,7 @@ public class YGAlignContentTest { assertEquals(0f, root.getLayoutX(), 0.0f); assertEquals(0f, root.getLayoutY(), 0.0f); - assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(130f, root.getLayoutWidth(), 0.0f); assertEquals(100f, root.getLayoutHeight(), 0.0f); assertEquals(0f, root_child0.getLayoutX(), 0.0f); @@ -60,23 +61,23 @@ public class YGAlignContentTest { assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); - assertEquals(0f, root_child1.getLayoutX(), 0.0f); - assertEquals(10f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); assertEquals(0f, root_child2.getLayoutX(), 0.0f); - assertEquals(20f, root_child2.getLayoutY(), 0.0f); + assertEquals(10f, root_child2.getLayoutY(), 0.0f); assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); - assertEquals(0f, root_child3.getLayoutX(), 0.0f); - assertEquals(30f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutX(), 0.0f); + assertEquals(10f, root_child3.getLayoutY(), 0.0f); assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); assertEquals(0f, root_child4.getLayoutX(), 0.0f); - assertEquals(40f, root_child4.getLayoutY(), 0.0f); + assertEquals(20f, root_child4.getLayoutY(), 0.0f); assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); assertEquals(10f, root_child4.getLayoutHeight(), 0.0f); @@ -85,31 +86,31 @@ public class YGAlignContentTest { assertEquals(0f, root.getLayoutX(), 0.0f); assertEquals(0f, root.getLayoutY(), 0.0f); - assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(130f, root.getLayoutWidth(), 0.0f); assertEquals(100f, root.getLayoutHeight(), 0.0f); - assertEquals(50f, root_child0.getLayoutX(), 0.0f); + assertEquals(80f, root_child0.getLayoutX(), 0.0f); assertEquals(0f, root_child0.getLayoutY(), 0.0f); assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); - assertEquals(50f, root_child1.getLayoutX(), 0.0f); - assertEquals(10f, root_child1.getLayoutY(), 0.0f); + assertEquals(30f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); - assertEquals(50f, root_child2.getLayoutX(), 0.0f); - assertEquals(20f, root_child2.getLayoutY(), 0.0f); + assertEquals(80f, root_child2.getLayoutX(), 0.0f); + assertEquals(10f, root_child2.getLayoutY(), 0.0f); assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); - assertEquals(50f, root_child3.getLayoutX(), 0.0f); - assertEquals(30f, root_child3.getLayoutY(), 0.0f); + assertEquals(30f, root_child3.getLayoutX(), 0.0f); + assertEquals(10f, root_child3.getLayoutY(), 0.0f); assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); - assertEquals(50f, root_child4.getLayoutX(), 0.0f); - assertEquals(40f, root_child4.getLayoutY(), 0.0f); + assertEquals(80f, root_child4.getLayoutX(), 0.0f); + assertEquals(20f, root_child4.getLayoutY(), 0.0f); assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); assertEquals(10f, root_child4.getLayoutHeight(), 0.0f); } @@ -117,9 +118,10 @@ public class YGAlignContentTest { @Test public void test_align_content_flex_end() { final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignContent(YogaAlign.FLEX_END); root.setWrap(YogaWrap.WRAP); - root.setWidth(100f); + root.setWidth(130f); root.setHeight(100f); final YogaNode root_child0 = new YogaNode(); @@ -151,31 +153,31 @@ public class YGAlignContentTest { assertEquals(0f, root.getLayoutX(), 0.0f); assertEquals(0f, root.getLayoutY(), 0.0f); - assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(130f, root.getLayoutWidth(), 0.0f); assertEquals(100f, root.getLayoutHeight(), 0.0f); assertEquals(0f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(70f, root_child0.getLayoutY(), 0.0f); assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); - assertEquals(0f, root_child1.getLayoutX(), 0.0f); - assertEquals(10f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(70f, root_child1.getLayoutY(), 0.0f); assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); assertEquals(0f, root_child2.getLayoutX(), 0.0f); - assertEquals(20f, root_child2.getLayoutY(), 0.0f); + assertEquals(80f, root_child2.getLayoutY(), 0.0f); assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); - assertEquals(0f, root_child3.getLayoutX(), 0.0f); - assertEquals(30f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutX(), 0.0f); + assertEquals(80f, root_child3.getLayoutY(), 0.0f); assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); assertEquals(0f, root_child4.getLayoutX(), 0.0f); - assertEquals(40f, root_child4.getLayoutY(), 0.0f); + assertEquals(90f, root_child4.getLayoutY(), 0.0f); assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); assertEquals(10f, root_child4.getLayoutHeight(), 0.0f); @@ -184,31 +186,31 @@ public class YGAlignContentTest { assertEquals(0f, root.getLayoutX(), 0.0f); assertEquals(0f, root.getLayoutY(), 0.0f); - assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(130f, root.getLayoutWidth(), 0.0f); assertEquals(100f, root.getLayoutHeight(), 0.0f); - assertEquals(50f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(80f, root_child0.getLayoutX(), 0.0f); + assertEquals(70f, root_child0.getLayoutY(), 0.0f); assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); - assertEquals(50f, root_child1.getLayoutX(), 0.0f); - assertEquals(10f, root_child1.getLayoutY(), 0.0f); + assertEquals(30f, root_child1.getLayoutX(), 0.0f); + assertEquals(70f, root_child1.getLayoutY(), 0.0f); assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); - assertEquals(50f, root_child2.getLayoutX(), 0.0f); - assertEquals(20f, root_child2.getLayoutY(), 0.0f); + assertEquals(80f, root_child2.getLayoutX(), 0.0f); + assertEquals(80f, root_child2.getLayoutY(), 0.0f); assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); - assertEquals(50f, root_child3.getLayoutX(), 0.0f); - assertEquals(30f, root_child3.getLayoutY(), 0.0f); + assertEquals(30f, root_child3.getLayoutX(), 0.0f); + assertEquals(80f, root_child3.getLayoutY(), 0.0f); assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); - assertEquals(50f, root_child4.getLayoutX(), 0.0f); - assertEquals(40f, root_child4.getLayoutY(), 0.0f); + assertEquals(80f, root_child4.getLayoutX(), 0.0f); + assertEquals(90f, root_child4.getLayoutY(), 0.0f); assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); assertEquals(10f, root_child4.getLayoutHeight(), 0.0f); } @@ -216,9 +218,10 @@ public class YGAlignContentTest { @Test public void test_align_content_center() { final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignContent(YogaAlign.CENTER); root.setWrap(YogaWrap.WRAP); - root.setWidth(100f); + root.setWidth(130f); root.setHeight(100f); final YogaNode root_child0 = new YogaNode(); @@ -250,31 +253,31 @@ public class YGAlignContentTest { assertEquals(0f, root.getLayoutX(), 0.0f); assertEquals(0f, root.getLayoutY(), 0.0f); - assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(130f, root.getLayoutWidth(), 0.0f); assertEquals(100f, root.getLayoutHeight(), 0.0f); assertEquals(0f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(35f, root_child0.getLayoutY(), 0.0f); assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); - assertEquals(0f, root_child1.getLayoutX(), 0.0f); - assertEquals(10f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(35f, root_child1.getLayoutY(), 0.0f); assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); assertEquals(0f, root_child2.getLayoutX(), 0.0f); - assertEquals(20f, root_child2.getLayoutY(), 0.0f); + assertEquals(45f, root_child2.getLayoutY(), 0.0f); assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); - assertEquals(0f, root_child3.getLayoutX(), 0.0f); - assertEquals(30f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutX(), 0.0f); + assertEquals(45f, root_child3.getLayoutY(), 0.0f); assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); assertEquals(0f, root_child4.getLayoutX(), 0.0f); - assertEquals(40f, root_child4.getLayoutY(), 0.0f); + assertEquals(55f, root_child4.getLayoutY(), 0.0f); assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); assertEquals(10f, root_child4.getLayoutHeight(), 0.0f); @@ -283,31 +286,31 @@ public class YGAlignContentTest { assertEquals(0f, root.getLayoutX(), 0.0f); assertEquals(0f, root.getLayoutY(), 0.0f); - assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(130f, root.getLayoutWidth(), 0.0f); assertEquals(100f, root.getLayoutHeight(), 0.0f); - assertEquals(50f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(80f, root_child0.getLayoutX(), 0.0f); + assertEquals(35f, root_child0.getLayoutY(), 0.0f); assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); - assertEquals(50f, root_child1.getLayoutX(), 0.0f); - assertEquals(10f, root_child1.getLayoutY(), 0.0f); + assertEquals(30f, root_child1.getLayoutX(), 0.0f); + assertEquals(35f, root_child1.getLayoutY(), 0.0f); assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); - assertEquals(50f, root_child2.getLayoutX(), 0.0f); - assertEquals(20f, root_child2.getLayoutY(), 0.0f); + assertEquals(80f, root_child2.getLayoutX(), 0.0f); + assertEquals(45f, root_child2.getLayoutY(), 0.0f); assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); - assertEquals(50f, root_child3.getLayoutX(), 0.0f); - assertEquals(30f, root_child3.getLayoutY(), 0.0f); + assertEquals(30f, root_child3.getLayoutX(), 0.0f); + assertEquals(45f, root_child3.getLayoutY(), 0.0f); assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); - assertEquals(50f, root_child4.getLayoutX(), 0.0f); - assertEquals(40f, root_child4.getLayoutY(), 0.0f); + assertEquals(80f, root_child4.getLayoutX(), 0.0f); + assertEquals(55f, root_child4.getLayoutY(), 0.0f); assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); assertEquals(10f, root_child4.getLayoutHeight(), 0.0f); } @@ -317,7 +320,7 @@ public class YGAlignContentTest { final YogaNode root = new YogaNode(); root.setAlignContent(YogaAlign.STRETCH); root.setWrap(YogaWrap.WRAP); - root.setWidth(100f); + root.setWidth(150f); root.setHeight(100f); final YogaNode root_child0 = new YogaNode(); @@ -344,7 +347,7 @@ public class YGAlignContentTest { assertEquals(0f, root.getLayoutX(), 0.0f); assertEquals(0f, root.getLayoutY(), 0.0f); - assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(150f, root.getLayoutWidth(), 0.0f); assertEquals(100f, root.getLayoutHeight(), 0.0f); assertEquals(0f, root_child0.getLayoutX(), 0.0f); @@ -377,33 +380,233 @@ public class YGAlignContentTest { assertEquals(0f, root.getLayoutX(), 0.0f); assertEquals(0f, root.getLayoutY(), 0.0f); - assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(150f, root.getLayoutWidth(), 0.0f); assertEquals(100f, root.getLayoutHeight(), 0.0f); - assertEquals(50f, root_child0.getLayoutX(), 0.0f); + assertEquals(100f, root_child0.getLayoutX(), 0.0f); assertEquals(0f, root_child0.getLayoutY(), 0.0f); assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); assertEquals(0f, root_child0.getLayoutHeight(), 0.0f); - assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(100f, root_child1.getLayoutX(), 0.0f); assertEquals(0f, root_child1.getLayoutY(), 0.0f); assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); assertEquals(0f, root_child1.getLayoutHeight(), 0.0f); - assertEquals(50f, root_child2.getLayoutX(), 0.0f); + assertEquals(100f, root_child2.getLayoutX(), 0.0f); assertEquals(0f, root_child2.getLayoutY(), 0.0f); assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); assertEquals(0f, root_child2.getLayoutHeight(), 0.0f); - assertEquals(50f, root_child3.getLayoutX(), 0.0f); + assertEquals(100f, root_child3.getLayoutX(), 0.0f); assertEquals(0f, root_child3.getLayoutY(), 0.0f); assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); assertEquals(0f, root_child3.getLayoutHeight(), 0.0f); - assertEquals(50f, root_child4.getLayoutX(), 0.0f); + assertEquals(100f, root_child4.getLayoutX(), 0.0f); assertEquals(0f, root_child4.getLayoutY(), 0.0f); assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); assertEquals(0f, root_child4.getLayoutHeight(), 0.0f); } + @Test + public void test_align_content_spacebetween() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setAlignContent(YogaAlign.SPACE_BETWEEN); + root.setWrap(YogaWrap.WRAP); + root.setWidth(130f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(50f); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setWidth(50f); + root_child1.setHeight(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(50f); + root_child2.setHeight(10f); + root.addChildAt(root_child2, 2); + + final YogaNode root_child3 = new YogaNode(); + root_child3.setWidth(50f); + root_child3.setHeight(10f); + root.addChildAt(root_child3, 3); + + final YogaNode root_child4 = new YogaNode(); + root_child4.setWidth(50f); + root_child4.setHeight(10f); + root.addChildAt(root_child4, 4); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(130f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(45f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child3.getLayoutX(), 0.0f); + assertEquals(45f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child4.getLayoutX(), 0.0f); + assertEquals(90f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child4.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(130f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(80f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(30f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(80f, root_child2.getLayoutX(), 0.0f); + assertEquals(45f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(30f, root_child3.getLayoutX(), 0.0f); + assertEquals(45f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(80f, root_child4.getLayoutX(), 0.0f); + assertEquals(90f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child4.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_content_spacearound() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setAlignContent(YogaAlign.SPACE_AROUND); + root.setWrap(YogaWrap.WRAP); + root.setWidth(140f); + root.setHeight(120f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(50f); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setWidth(50f); + root_child1.setHeight(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(50f); + root_child2.setHeight(10f); + root.addChildAt(root_child2, 2); + + final YogaNode root_child3 = new YogaNode(); + root_child3.setWidth(50f); + root_child3.setHeight(10f); + root.addChildAt(root_child3, 3); + + final YogaNode root_child4 = new YogaNode(); + root_child4.setWidth(50f); + root_child4.setHeight(10f); + root.addChildAt(root_child4, 4); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(140f, root.getLayoutWidth(), 0.0f); + assertEquals(120f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(15f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(15f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(55f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child3.getLayoutX(), 0.0f); + assertEquals(55f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child4.getLayoutX(), 0.0f); + assertEquals(95f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child4.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(140f, root.getLayoutWidth(), 0.0f); + assertEquals(120f, root.getLayoutHeight(), 0.0f); + + assertEquals(90f, root_child0.getLayoutX(), 0.0f); + assertEquals(15f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(40f, root_child1.getLayoutX(), 0.0f); + assertEquals(15f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(90f, root_child2.getLayoutX(), 0.0f); + assertEquals(55f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(40f, root_child3.getLayoutX(), 0.0f); + assertEquals(55f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(90f, root_child4.getLayoutX(), 0.0f); + assertEquals(95f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child4.getLayoutHeight(), 0.0f); + } + } diff --git a/javascript/sources/YGEnums.js b/javascript/sources/YGEnums.js index b48c7b7a..929a968d 100644 --- a/javascript/sources/YGEnums.js +++ b/javascript/sources/YGEnums.js @@ -9,13 +9,15 @@ module.exports = { - ALIGN_COUNT: 6, + ALIGN_COUNT: 8, ALIGN_AUTO: 0, ALIGN_FLEX_START: 1, ALIGN_CENTER: 2, ALIGN_FLEX_END: 3, ALIGN_STRETCH: 4, ALIGN_BASELINE: 5, + ALIGN_SPACE_BETWEEN: 6, + ALIGN_SPACE_AROUND: 7, DIMENSION_COUNT: 2, DIMENSION_WIDTH: 0, diff --git a/javascript/tests/Facebook.Yoga/YGAlignContentTest.js b/javascript/tests/Facebook.Yoga/YGAlignContentTest.js index 2785b8a4..14cf9820 100644 --- a/javascript/tests/Facebook.Yoga/YGAlignContentTest.js +++ b/javascript/tests/Facebook.Yoga/YGAlignContentTest.js @@ -13,8 +13,9 @@ var Yoga = Yoga || require("../../sources/entry-" + process.env.TEST_ENTRY); it("align_content_flex_start", function () { var root = Yoga.Node.create(); + root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(100); + root.setWidth(130); root.setHeight(100); var root_child0 = Yoga.Node.create(); @@ -45,7 +46,7 @@ it("align_content_flex_start", function () { console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); - console.assert(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(130 === root.getComputedWidth(), "130 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); @@ -53,23 +54,23 @@ it("align_content_flex_start", function () { console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); console.assert(10 === root_child0.getComputedHeight(), "10 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - console.assert(0 === root_child1.getComputedLeft(), "0 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(10 === root_child1.getComputedTop(), "10 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); console.assert(10 === root_child1.getComputedHeight(), "10 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(20 === root_child2.getComputedTop(), "20 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(10 === root_child2.getComputedTop(), "10 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); console.assert(10 === root_child2.getComputedHeight(), "10 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - console.assert(0 === root_child3.getComputedLeft(), "0 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(30 === root_child3.getComputedTop(), "30 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedLeft(), "50 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(10 === root_child3.getComputedTop(), "10 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); console.assert(10 === root_child3.getComputedHeight(), "10 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); console.assert(0 === root_child4.getComputedLeft(), "0 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(40 === root_child4.getComputedTop(), "40 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(20 === root_child4.getComputedTop(), "20 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); console.assert(10 === root_child4.getComputedHeight(), "10 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); @@ -77,31 +78,31 @@ it("align_content_flex_start", function () { console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); - console.assert(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(130 === root.getComputedWidth(), "130 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - console.assert(50 === root_child0.getComputedLeft(), "50 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(80 === root_child0.getComputedLeft(), "80 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); console.assert(10 === root_child0.getComputedHeight(), "10 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(10 === root_child1.getComputedTop(), "10 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(30 === root_child1.getComputedLeft(), "30 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); console.assert(10 === root_child1.getComputedHeight(), "10 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - console.assert(50 === root_child2.getComputedLeft(), "50 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(20 === root_child2.getComputedTop(), "20 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(80 === root_child2.getComputedLeft(), "80 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(10 === root_child2.getComputedTop(), "10 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); console.assert(10 === root_child2.getComputedHeight(), "10 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - console.assert(50 === root_child3.getComputedLeft(), "50 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(30 === root_child3.getComputedTop(), "30 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(30 === root_child3.getComputedLeft(), "30 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(10 === root_child3.getComputedTop(), "10 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); console.assert(10 === root_child3.getComputedHeight(), "10 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(40 === root_child4.getComputedTop(), "40 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(80 === root_child4.getComputedLeft(), "80 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(20 === root_child4.getComputedTop(), "20 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); console.assert(10 === root_child4.getComputedHeight(), "10 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); @@ -113,9 +114,10 @@ it("align_content_flex_start", function () { }); it("align_content_flex_end", function () { var root = Yoga.Node.create(); + root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); root.setAlignContent(Yoga.ALIGN_FLEX_END); root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(100); + root.setWidth(130); root.setHeight(100); var root_child0 = Yoga.Node.create(); @@ -146,31 +148,31 @@ it("align_content_flex_end", function () { console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); - console.assert(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(130 === root.getComputedWidth(), "130 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(70 === root_child0.getComputedTop(), "70 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); console.assert(10 === root_child0.getComputedHeight(), "10 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - console.assert(0 === root_child1.getComputedLeft(), "0 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(10 === root_child1.getComputedTop(), "10 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(70 === root_child1.getComputedTop(), "70 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); console.assert(10 === root_child1.getComputedHeight(), "10 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(20 === root_child2.getComputedTop(), "20 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(80 === root_child2.getComputedTop(), "80 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); console.assert(10 === root_child2.getComputedHeight(), "10 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - console.assert(0 === root_child3.getComputedLeft(), "0 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(30 === root_child3.getComputedTop(), "30 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedLeft(), "50 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(80 === root_child3.getComputedTop(), "80 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); console.assert(10 === root_child3.getComputedHeight(), "10 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); console.assert(0 === root_child4.getComputedLeft(), "0 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(40 === root_child4.getComputedTop(), "40 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(90 === root_child4.getComputedTop(), "90 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); console.assert(10 === root_child4.getComputedHeight(), "10 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); @@ -178,31 +180,31 @@ it("align_content_flex_end", function () { console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); - console.assert(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(130 === root.getComputedWidth(), "130 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - console.assert(50 === root_child0.getComputedLeft(), "50 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(80 === root_child0.getComputedLeft(), "80 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(70 === root_child0.getComputedTop(), "70 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); console.assert(10 === root_child0.getComputedHeight(), "10 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(10 === root_child1.getComputedTop(), "10 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(30 === root_child1.getComputedLeft(), "30 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(70 === root_child1.getComputedTop(), "70 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); console.assert(10 === root_child1.getComputedHeight(), "10 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - console.assert(50 === root_child2.getComputedLeft(), "50 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(20 === root_child2.getComputedTop(), "20 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(80 === root_child2.getComputedLeft(), "80 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(80 === root_child2.getComputedTop(), "80 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); console.assert(10 === root_child2.getComputedHeight(), "10 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - console.assert(50 === root_child3.getComputedLeft(), "50 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(30 === root_child3.getComputedTop(), "30 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(30 === root_child3.getComputedLeft(), "30 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(80 === root_child3.getComputedTop(), "80 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); console.assert(10 === root_child3.getComputedHeight(), "10 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(40 === root_child4.getComputedTop(), "40 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(80 === root_child4.getComputedLeft(), "80 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(90 === root_child4.getComputedTop(), "90 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); console.assert(10 === root_child4.getComputedHeight(), "10 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); @@ -214,9 +216,10 @@ it("align_content_flex_end", function () { }); it("align_content_center", function () { var root = Yoga.Node.create(); + root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); root.setAlignContent(Yoga.ALIGN_CENTER); root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(100); + root.setWidth(130); root.setHeight(100); var root_child0 = Yoga.Node.create(); @@ -247,31 +250,31 @@ it("align_content_center", function () { console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); - console.assert(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(130 === root.getComputedWidth(), "130 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(35 === root_child0.getComputedTop(), "35 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); console.assert(10 === root_child0.getComputedHeight(), "10 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - console.assert(0 === root_child1.getComputedLeft(), "0 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(10 === root_child1.getComputedTop(), "10 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(35 === root_child1.getComputedTop(), "35 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); console.assert(10 === root_child1.getComputedHeight(), "10 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(20 === root_child2.getComputedTop(), "20 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(45 === root_child2.getComputedTop(), "45 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); console.assert(10 === root_child2.getComputedHeight(), "10 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - console.assert(0 === root_child3.getComputedLeft(), "0 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(30 === root_child3.getComputedTop(), "30 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedLeft(), "50 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(45 === root_child3.getComputedTop(), "45 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); console.assert(10 === root_child3.getComputedHeight(), "10 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); console.assert(0 === root_child4.getComputedLeft(), "0 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(40 === root_child4.getComputedTop(), "40 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(55 === root_child4.getComputedTop(), "55 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); console.assert(10 === root_child4.getComputedHeight(), "10 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); @@ -279,31 +282,31 @@ it("align_content_center", function () { console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); - console.assert(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(130 === root.getComputedWidth(), "130 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - console.assert(50 === root_child0.getComputedLeft(), "50 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(80 === root_child0.getComputedLeft(), "80 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(35 === root_child0.getComputedTop(), "35 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); console.assert(10 === root_child0.getComputedHeight(), "10 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(10 === root_child1.getComputedTop(), "10 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(30 === root_child1.getComputedLeft(), "30 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(35 === root_child1.getComputedTop(), "35 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); console.assert(10 === root_child1.getComputedHeight(), "10 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - console.assert(50 === root_child2.getComputedLeft(), "50 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(20 === root_child2.getComputedTop(), "20 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(80 === root_child2.getComputedLeft(), "80 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(45 === root_child2.getComputedTop(), "45 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); console.assert(10 === root_child2.getComputedHeight(), "10 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - console.assert(50 === root_child3.getComputedLeft(), "50 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(30 === root_child3.getComputedTop(), "30 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(30 === root_child3.getComputedLeft(), "30 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(45 === root_child3.getComputedTop(), "45 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); console.assert(10 === root_child3.getComputedHeight(), "10 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(40 === root_child4.getComputedTop(), "40 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(80 === root_child4.getComputedLeft(), "80 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(55 === root_child4.getComputedTop(), "55 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); console.assert(10 === root_child4.getComputedHeight(), "10 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); @@ -317,7 +320,7 @@ it("align_content_stretch", function () { var root = Yoga.Node.create(); root.setAlignContent(Yoga.ALIGN_STRETCH); root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(100); + root.setWidth(150); root.setHeight(100); var root_child0 = Yoga.Node.create(); @@ -343,7 +346,7 @@ it("align_content_stretch", function () { console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); - console.assert(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); @@ -375,30 +378,30 @@ it("align_content_stretch", function () { console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); - console.assert(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - console.assert(50 === root_child0.getComputedLeft(), "50 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(100 === root_child0.getComputedLeft(), "100 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); console.assert(0 === root_child0.getComputedHeight(), "0 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(100 === root_child1.getComputedLeft(), "100 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); console.assert(0 === root_child1.getComputedHeight(), "0 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - console.assert(50 === root_child2.getComputedLeft(), "50 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(100 === root_child2.getComputedLeft(), "100 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); console.assert(0 === root_child2.getComputedHeight(), "0 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - console.assert(50 === root_child3.getComputedLeft(), "50 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(100 === root_child3.getComputedLeft(), "100 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); console.assert(0 === root_child3.getComputedTop(), "0 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); console.assert(0 === root_child3.getComputedHeight(), "0 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(100 === root_child4.getComputedLeft(), "100 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); console.assert(0 === root_child4.getComputedTop(), "0 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); console.assert(0 === root_child4.getComputedHeight(), "0 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); @@ -409,3 +412,207 @@ it("align_content_stretch", function () { (typeof gc !== "undefined") && gc(); console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); }); +it("align_content_spacebetween", function () { + var root = Yoga.Node.create(); + root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); + root.setAlignContent(Yoga.ALIGN_SPACE_BETWEEN); + root.setFlexWrap(Yoga.WRAP_WRAP); + root.setWidth(130); + root.setHeight(100); + + var root_child0 = Yoga.Node.create(); + root_child0.setWidth(50); + root_child0.setHeight(10); + root.insertChild(root_child0, 0); + + var root_child1 = Yoga.Node.create(); + root_child1.setWidth(50); + root_child1.setHeight(10); + root.insertChild(root_child1, 1); + + var root_child2 = Yoga.Node.create(); + root_child2.setWidth(50); + root_child2.setHeight(10); + root.insertChild(root_child2, 2); + + var root_child3 = Yoga.Node.create(); + root_child3.setWidth(50); + root_child3.setHeight(10); + root.insertChild(root_child3, 3); + + var root_child4 = Yoga.Node.create(); + root_child4.setWidth(50); + root_child4.setHeight(10); + root.insertChild(root_child4, 4); + 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(130 === root.getComputedWidth(), "130 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(10 === root_child0.getComputedHeight(), "10 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(10 === root_child1.getComputedHeight(), "10 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(45 === root_child2.getComputedTop(), "45 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); + console.assert(10 === root_child2.getComputedHeight(), "10 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + + console.assert(50 === root_child3.getComputedLeft(), "50 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(45 === root_child3.getComputedTop(), "45 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); + console.assert(10 === root_child3.getComputedHeight(), "10 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); + + console.assert(0 === root_child4.getComputedLeft(), "0 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(90 === root_child4.getComputedTop(), "90 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); + console.assert(10 === root_child4.getComputedHeight(), "10 === root_child4.getComputedHeight() (" + root_child4.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(130 === root.getComputedWidth(), "130 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(80 === root_child0.getComputedLeft(), "80 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(10 === root_child0.getComputedHeight(), "10 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(30 === root_child1.getComputedLeft(), "30 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(10 === root_child1.getComputedHeight(), "10 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + console.assert(80 === root_child2.getComputedLeft(), "80 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(45 === root_child2.getComputedTop(), "45 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); + console.assert(10 === root_child2.getComputedHeight(), "10 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + + console.assert(30 === root_child3.getComputedLeft(), "30 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(45 === root_child3.getComputedTop(), "45 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); + console.assert(10 === root_child3.getComputedHeight(), "10 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); + + console.assert(80 === root_child4.getComputedLeft(), "80 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(90 === root_child4.getComputedTop(), "90 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); + console.assert(10 === root_child4.getComputedHeight(), "10 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); + + if (typeof root !== "undefined") + root.freeRecursive(); + + (typeof gc !== "undefined") && gc(); + console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); +}); +it("align_content_spacearound", function () { + var root = Yoga.Node.create(); + root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); + root.setAlignContent(Yoga.ALIGN_SPACE_AROUND); + root.setFlexWrap(Yoga.WRAP_WRAP); + root.setWidth(140); + root.setHeight(120); + + var root_child0 = Yoga.Node.create(); + root_child0.setWidth(50); + root_child0.setHeight(10); + root.insertChild(root_child0, 0); + + var root_child1 = Yoga.Node.create(); + root_child1.setWidth(50); + root_child1.setHeight(10); + root.insertChild(root_child1, 1); + + var root_child2 = Yoga.Node.create(); + root_child2.setWidth(50); + root_child2.setHeight(10); + root.insertChild(root_child2, 2); + + var root_child3 = Yoga.Node.create(); + root_child3.setWidth(50); + root_child3.setHeight(10); + root.insertChild(root_child3, 3); + + var root_child4 = Yoga.Node.create(); + root_child4.setWidth(50); + root_child4.setHeight(10); + root.insertChild(root_child4, 4); + 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(140 === root.getComputedWidth(), "140 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(120 === root.getComputedHeight(), "120 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(15 === root_child0.getComputedTop(), "15 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(10 === root_child0.getComputedHeight(), "10 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(15 === root_child1.getComputedTop(), "15 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(10 === root_child1.getComputedHeight(), "10 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(55 === root_child2.getComputedTop(), "55 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); + console.assert(10 === root_child2.getComputedHeight(), "10 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + + console.assert(50 === root_child3.getComputedLeft(), "50 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(55 === root_child3.getComputedTop(), "55 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); + console.assert(10 === root_child3.getComputedHeight(), "10 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); + + console.assert(0 === root_child4.getComputedLeft(), "0 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(95 === root_child4.getComputedTop(), "95 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); + console.assert(10 === root_child4.getComputedHeight(), "10 === root_child4.getComputedHeight() (" + root_child4.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(140 === root.getComputedWidth(), "140 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(120 === root.getComputedHeight(), "120 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(90 === root_child0.getComputedLeft(), "90 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(15 === root_child0.getComputedTop(), "15 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(10 === root_child0.getComputedHeight(), "10 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(40 === root_child1.getComputedLeft(), "40 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(15 === root_child1.getComputedTop(), "15 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(10 === root_child1.getComputedHeight(), "10 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + console.assert(90 === root_child2.getComputedLeft(), "90 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(55 === root_child2.getComputedTop(), "55 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); + console.assert(10 === root_child2.getComputedHeight(), "10 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + + console.assert(40 === root_child3.getComputedLeft(), "40 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(55 === root_child3.getComputedTop(), "55 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); + console.assert(10 === root_child3.getComputedHeight(), "10 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); + + console.assert(90 === root_child4.getComputedLeft(), "90 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(95 === root_child4.getComputedTop(), "95 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); + console.assert(10 === root_child4.getComputedHeight(), "10 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); + + if (typeof root !== "undefined") + root.freeRecursive(); + + (typeof gc !== "undefined") && gc(); + console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); +}); diff --git a/tests/YGAlignContentTest.cpp b/tests/YGAlignContentTest.cpp index ea6365e5..2061af12 100644 --- a/tests/YGAlignContentTest.cpp +++ b/tests/YGAlignContentTest.cpp @@ -14,8 +14,9 @@ TEST(YogaTest, align_content_flex_start) { const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetWidth(root, 130); YGNodeStyleSetHeight(root, 100); const YGNodeRef root_child0 = YGNodeNew(); @@ -46,7 +47,7 @@ TEST(YogaTest, align_content_flex_start) { ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(130, YGNodeLayoutGetWidth(root)); ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); @@ -54,23 +55,23 @@ TEST(YogaTest, align_content_flex_start) { ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child2)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child3)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child4)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); @@ -78,31 +79,31 @@ TEST(YogaTest, align_content_flex_start) { ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(130, YGNodeLayoutGetWidth(root)); ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child0)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child2)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child3)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child4)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); @@ -111,9 +112,10 @@ TEST(YogaTest, align_content_flex_start) { TEST(YogaTest, align_content_flex_end) { const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); YGNodeStyleSetAlignContent(root, YGAlignFlexEnd); YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetWidth(root, 130); YGNodeStyleSetHeight(root, 100); const YGNodeRef root_child0 = YGNodeNew(); @@ -144,31 +146,31 @@ TEST(YogaTest, align_content_flex_end) { ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(130, YGNodeLayoutGetWidth(root)); ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(70, YGNodeLayoutGetTop(root_child0)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(70, YGNodeLayoutGetTop(root_child1)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child2)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child3)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetTop(root_child4)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); @@ -176,31 +178,31 @@ TEST(YogaTest, align_content_flex_end) { ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(130, YGNodeLayoutGetWidth(root)); ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(70, YGNodeLayoutGetTop(root_child0)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(70, YGNodeLayoutGetTop(root_child1)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child2)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child3)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetTop(root_child4)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); @@ -209,9 +211,10 @@ TEST(YogaTest, align_content_flex_end) { TEST(YogaTest, align_content_center) { const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); YGNodeStyleSetAlignContent(root, YGAlignCenter); YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetWidth(root, 130); YGNodeStyleSetHeight(root, 100); const YGNodeRef root_child0 = YGNodeNew(); @@ -242,31 +245,31 @@ TEST(YogaTest, align_content_center) { ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(130, YGNodeLayoutGetWidth(root)); ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(35, YGNodeLayoutGetTop(root_child0)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(35, YGNodeLayoutGetTop(root_child1)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(45, YGNodeLayoutGetTop(root_child2)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(45, YGNodeLayoutGetTop(root_child3)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(55, YGNodeLayoutGetTop(root_child4)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); @@ -274,31 +277,31 @@ TEST(YogaTest, align_content_center) { ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(130, YGNodeLayoutGetWidth(root)); ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(35, YGNodeLayoutGetTop(root_child0)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(35, YGNodeLayoutGetTop(root_child1)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(45, YGNodeLayoutGetTop(root_child2)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(45, YGNodeLayoutGetTop(root_child3)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(55, YGNodeLayoutGetTop(root_child4)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); @@ -309,7 +312,7 @@ TEST(YogaTest, align_content_stretch) { const YGNodeRef root = YGNodeNew(); YGNodeStyleSetAlignContent(root, YGAlignStretch); YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetWidth(root, 150); YGNodeStyleSetHeight(root, 100); const YGNodeRef root_child0 = YGNodeNew(); @@ -335,7 +338,7 @@ TEST(YogaTest, align_content_stretch) { ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); @@ -367,33 +370,231 @@ TEST(YogaTest, align_content_stretch) { ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child1)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child2)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child3)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child3)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child4)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child4)); YGNodeFreeRecursive(root); } + +TEST(YogaTest, align_content_spacebetween) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetAlignContent(root, YGAlignSpaceBetween); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + YGNodeStyleSetWidth(root, 130); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetWidth(root_child1, 50); + YGNodeStyleSetHeight(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 50); + YGNodeStyleSetHeight(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + + const YGNodeRef root_child3 = YGNodeNew(); + YGNodeStyleSetWidth(root_child3, 50); + YGNodeStyleSetHeight(root_child3, 10); + YGNodeInsertChild(root, root_child3, 3); + + const YGNodeRef root_child4 = YGNodeNew(); + YGNodeStyleSetWidth(root_child4, 50); + YGNodeStyleSetHeight(root_child4, 10); + YGNodeInsertChild(root, root_child4, 4); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(130, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(45, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(45, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(130, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(45, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(45, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, align_content_spacearound) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetAlignContent(root, YGAlignSpaceAround); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + YGNodeStyleSetWidth(root, 140); + YGNodeStyleSetHeight(root, 120); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetWidth(root_child1, 50); + YGNodeStyleSetHeight(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 50); + YGNodeStyleSetHeight(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + + const YGNodeRef root_child3 = YGNodeNew(); + YGNodeStyleSetWidth(root_child3, 50); + YGNodeStyleSetHeight(root_child3, 10); + YGNodeInsertChild(root, root_child3, 3); + + const YGNodeRef root_child4 = YGNodeNew(); + YGNodeStyleSetWidth(root_child4, 50); + YGNodeStyleSetHeight(root_child4, 10); + YGNodeInsertChild(root, root_child4, 4); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(140, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(120, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(15, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(15, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(55, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(55, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(95, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(140, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(120, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(15, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(15, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(55, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(55, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(95, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); + + YGNodeFreeRecursive(root); +} diff --git a/yoga/YGEnums.h b/yoga/YGEnums.h index 3e65e103..5a97ef78 100644 --- a/yoga/YGEnums.h +++ b/yoga/YGEnums.h @@ -13,7 +13,7 @@ YG_EXTERN_C_BEGIN -#define YGAlignCount 6 +#define YGAlignCount 8 typedef YG_ENUM_BEGIN(YGAlign) { YGAlignAuto, YGAlignFlexStart, @@ -21,6 +21,8 @@ typedef YG_ENUM_BEGIN(YGAlign) { YGAlignFlexEnd, YGAlignStretch, YGAlignBaseline, + YGAlignSpaceBetween, + YGAlignSpaceAround, } YG_ENUM_END(YGAlign); #define YGDimensionCount 2 diff --git a/yoga/Yoga.c b/yoga/Yoga.c index a6dde07d..402abc8a 100644 --- a/yoga/Yoga.c +++ b/yoga/Yoga.c @@ -2667,7 +2667,22 @@ static void YGNodelayoutImpl(const YGNodeRef node, break; case YGAlignStretch: if (availableInnerCrossDim > totalLineCrossDim) { - crossDimLead = (remainingAlignContentDim / lineCount); + crossDimLead = remainingAlignContentDim / lineCount; + } + break; + case YGAlignSpaceAround: + if (availableInnerCrossDim > totalLineCrossDim) { + currentLead += remainingAlignContentDim / (2 * lineCount); + if (lineCount > 1) { + crossDimLead = remainingAlignContentDim / lineCount; + } + } else { + currentLead += remainingAlignContentDim / 2; + } + break; + case YGAlignSpaceBetween: + if (availableInnerCrossDim > totalLineCrossDim && lineCount > 1) { + crossDimLead = remainingAlignContentDim / (lineCount - 1); } break; case YGAlignAuto: @@ -2755,6 +2770,8 @@ static void YGNodelayoutImpl(const YGNodeRef node, break; } case YGAlignAuto: + case YGAlignSpaceBetween: + case YGAlignSpaceAround: break; } } From adf8691093d57b75d19f5fc9c9a404a5d7f0cbc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20W=C3=B6hrl?= Date: Sat, 11 Feb 2017 08:32:50 -0800 Subject: [PATCH 08/20] Fix resolving bug on changing layout and optimized memory usage Summary: Due to the changes in 46817a38. We have a bug if the layout changes. This PR fixes this bug and adds a test for it. Additionally it correctly marks negative percentage values as undefined dim. It also changes the ```resolvedDimensions``` to use a reference instead of the full value in order to minimize the memory requirement of a ```YGNode``` and reduces the copying of the ```YGValue```. Closes https://github.com/facebook/yoga/pull/379 Reviewed By: gkassabli Differential Revision: D4528552 Pulled By: emilsjolander fbshipit-source-id: c024fe3a009c3788af319b689858ea3374c46477 --- tests/YGRelayoutTest.cpp | 19 +++++++++++++++++ yoga/Yoga.c | 44 ++++++++++++++++++++-------------------- 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/tests/YGRelayoutTest.cpp b/tests/YGRelayoutTest.cpp index 4cd22509..8a55edd3 100644 --- a/tests/YGRelayoutTest.cpp +++ b/tests/YGRelayoutTest.cpp @@ -29,3 +29,22 @@ TEST(YogaTest, dont_cache_computed_flex_basis_between_layouts) { YGSetExperimentalFeatureEnabled(YGExperimentalFeatureWebFlexBasis, false); } + +TEST(YogaTest, recalculate_resolvedDimonsion_onchange) { + const YGNodeRef root = YGNodeNew(); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetMinHeight(root_child0, 10); + YGNodeStyleSetMaxHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeStyleSetMinHeight(root_child0, YGUndefined); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} diff --git a/yoga/Yoga.c b/yoga/Yoga.c index 402abc8a..e8d5c31e 100644 --- a/yoga/Yoga.c +++ b/yoga/Yoga.c @@ -112,7 +112,7 @@ typedef struct YGNode { bool isDirty; bool hasNewLayout; - YGValue resolvedDimensions[2]; + YGValue const *resolvedDimensions[2]; } YGNode; #define YG_UNDEFINED_VALUES \ @@ -138,7 +138,8 @@ static YGNode gYGNodeDefaults = { .children = NULL, .hasNewLayout = true, .isDirty = false, - .resolvedDimensions = YG_DEFAULT_DIMENSION_VALUES_UNIT, + .resolvedDimensions = {[YGDimensionWidth] = &YGValueUndefined, + [YGDimensionHeight] = &YGValueUndefined}, .style = { @@ -643,9 +644,9 @@ static inline void YGResolveDimensions(YGNodeRef node) { for (YGDimension dim = YGDimensionWidth; dim <= YGDimensionHeight; dim++) { if (node->style.maxDimensions[dim].unit != YGUnitUndefined && YGValueEqual(node->style.maxDimensions[dim], node->style.minDimensions[dim])) { - node->resolvedDimensions[dim] = node->style.maxDimensions[dim]; + node->resolvedDimensions[dim] = &node->style.maxDimensions[dim]; } else { - node->resolvedDimensions[dim] = node->style.dimensions[dim]; + node->resolvedDimensions[dim] = &node->style.dimensions[dim]; } } } @@ -1095,11 +1096,11 @@ static inline float YGNodeDimWithMargin(const YGNodeRef node, static inline bool YGNodeIsStyleDimDefined(const YGNodeRef node, const YGFlexDirection axis, const float parentSize) { - return !(node->resolvedDimensions[dim[axis]].unit == YGUnitUndefined || - (node->resolvedDimensions[dim[axis]].unit == YGUnitPixel && - node->resolvedDimensions[dim[axis]].value < 0.0f) || - (node->resolvedDimensions[dim[axis]].unit == YGUnitPercent && - YGFloatIsUndefined(parentSize))); + return !(node->resolvedDimensions[dim[axis]]->unit == YGUnitUndefined || + (node->resolvedDimensions[dim[axis]]->unit == YGUnitPixel && + node->resolvedDimensions[dim[axis]]->value < 0.0f) || + (node->resolvedDimensions[dim[axis]]->unit == YGUnitPercent && + (node->resolvedDimensions[dim[axis]]->value < 0.0f || YGFloatIsUndefined(parentSize)))); } static inline bool YGNodeIsLayoutDimDefined(const YGNodeRef node, const YGFlexDirection axis) { @@ -1286,12 +1287,12 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node, } else if (isMainAxisRow && isRowStyleDimDefined) { // The width is definite, so use that as the flex basis. child->layout.computedFlexBasis = - fmaxf(YGValueResolve(&child->resolvedDimensions[YGDimensionWidth], parentWidth), + fmaxf(YGValueResolve(child->resolvedDimensions[YGDimensionWidth], parentWidth), YGNodePaddingAndBorderForAxis(child, YGFlexDirectionRow, parentWidth)); } else if (!isMainAxisRow && isColumnStyleDimDefined) { // The height is definite, so use that as the flex basis. child->layout.computedFlexBasis = - fmaxf(YGValueResolve(&child->resolvedDimensions[YGDimensionHeight], parentHeight), + fmaxf(YGValueResolve(child->resolvedDimensions[YGDimensionHeight], parentHeight), YGNodePaddingAndBorderForAxis(child, YGFlexDirectionColumn, parentWidth)); } else { // Compute the flex basis and hypothetical main size (i.e. the clamped @@ -1306,12 +1307,12 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node, if (isRowStyleDimDefined) { childWidth = - YGValueResolve(&child->resolvedDimensions[YGDimensionWidth], parentWidth) + marginRow; + YGValueResolve(child->resolvedDimensions[YGDimensionWidth], parentWidth) + marginRow; childWidthMeasureMode = YGMeasureModeExactly; } if (isColumnStyleDimDefined) { - childHeight = YGValueResolve(&child->resolvedDimensions[YGDimensionHeight], parentHeight) + - marginColumn; + childHeight = + YGValueResolve(child->resolvedDimensions[YGDimensionHeight], parentHeight) + marginColumn; childHeightMeasureMode = YGMeasureModeExactly; } @@ -1410,7 +1411,7 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node, const float marginColumn = YGNodeMarginForAxis(child, YGFlexDirectionColumn, width); if (YGNodeIsStyleDimDefined(child, YGFlexDirectionRow, width)) { - childWidth = YGValueResolve(&child->resolvedDimensions[YGDimensionWidth], width) + marginRow; + childWidth = YGValueResolve(child->resolvedDimensions[YGDimensionWidth], width) + marginRow; } else { // If the child doesn't have a specified width, compute the width based // on the left/right @@ -1428,7 +1429,7 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node, if (YGNodeIsStyleDimDefined(child, YGFlexDirectionColumn, height)) { childHeight = - YGValueResolve(&child->resolvedDimensions[YGDimensionHeight], height) + marginColumn; + YGValueResolve(child->resolvedDimensions[YGDimensionHeight], height) + marginColumn; } else { // If the child doesn't have a specified height, compute the height // based on the top/bottom @@ -2297,7 +2298,7 @@ static void YGNodelayoutImpl(const YGNodeRef node, YGFloatIsUndefined(childHeight) ? YGMeasureModeUndefined : YGMeasureModeAtMost; } else { childHeight = - YGValueResolve(¤tRelativeChild->resolvedDimensions[YGDimensionHeight], + YGValueResolve(currentRelativeChild->resolvedDimensions[YGDimensionHeight], availableInnerHeight) + marginColumn; childHeightMeasureMode = @@ -2322,7 +2323,7 @@ static void YGNodelayoutImpl(const YGNodeRef node, childWidthMeasureMode = YGFloatIsUndefined(childWidth) ? YGMeasureModeUndefined : YGMeasureModeAtMost; } else { - childWidth = YGValueResolve(¤tRelativeChild->resolvedDimensions[YGDimensionWidth], + childWidth = YGValueResolve(currentRelativeChild->resolvedDimensions[YGDimensionWidth], availableInnerWidth) + marginRow; childWidthMeasureMode = @@ -3201,7 +3202,7 @@ void YGNodeCalculateLayout(const YGNodeRef node, if (!YGFloatIsUndefined(width)) { widthMeasureMode = YGMeasureModeExactly; } else if (YGNodeIsStyleDimDefined(node, YGFlexDirectionRow, availableWidth)) { - width = YGValueResolve(&node->resolvedDimensions[dim[YGFlexDirectionRow]], availableWidth) + + width = YGValueResolve(node->resolvedDimensions[dim[YGFlexDirectionRow]], availableWidth) + YGNodeMarginForAxis(node, YGFlexDirectionRow, availableWidth); widthMeasureMode = YGMeasureModeExactly; } else if (YGValueResolve(&node->style.maxDimensions[YGDimensionWidth], availableWidth) >= 0.0f) { @@ -3212,9 +3213,8 @@ void YGNodeCalculateLayout(const YGNodeRef node, if (!YGFloatIsUndefined(height)) { heightMeasureMode = YGMeasureModeExactly; } else if (YGNodeIsStyleDimDefined(node, YGFlexDirectionColumn, availableHeight)) { - height = - YGValueResolve(&node->resolvedDimensions[dim[YGFlexDirectionColumn]], availableHeight) + - YGNodeMarginForAxis(node, YGFlexDirectionColumn, availableWidth); + height = YGValueResolve(node->resolvedDimensions[dim[YGFlexDirectionColumn]], availableHeight) + + YGNodeMarginForAxis(node, YGFlexDirectionColumn, availableWidth); heightMeasureMode = YGMeasureModeExactly; } else if (YGValueResolve(&node->style.maxDimensions[YGDimensionHeight], availableHeight) >= 0.0f) { From 063f65d0651c87a7e3d96b94679dacd8a35eb13e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20W=C3=B6hrl?= Date: Sat, 11 Feb 2017 08:32:51 -0800 Subject: [PATCH 09/20] Fix align-content strech with multiple lines Summary: Fixes ```align-content:strech``` on nodes without specified cross dimension, if there are multiple lines. Currently it uses the full height of the parent, but it has to use the line height. As we don't know the number of lines until here, we need to realign the relevant children. Closes https://github.com/facebook/yoga/pull/368 Reviewed By: gkassabli Differential Revision: D4528559 Pulled By: emilsjolander fbshipit-source-id: 019e6f85fa452d0c3412f711e3886f0c4452da47 --- .../tests/Facebook.Yoga/YGAlignContentTest.cs | 1284 +++++++++++++++- gentest/fixtures/YGAlignContentTest.html | 107 +- .../com/facebook/yoga/YGAlignContentTest.java | 1272 +++++++++++++++- .../tests/Facebook.Yoga/YGAlignContentTest.js | 1296 ++++++++++++++++- tests/YGAlignContentTest.cpp | 1260 +++++++++++++++- yoga/Yoga.c | 56 +- 6 files changed, 5043 insertions(+), 232 deletions(-) diff --git a/csharp/tests/Facebook.Yoga/YGAlignContentTest.cs b/csharp/tests/Facebook.Yoga/YGAlignContentTest.cs index c73d6761..0d173c1c 100644 --- a/csharp/tests/Facebook.Yoga/YGAlignContentTest.cs +++ b/csharp/tests/Facebook.Yoga/YGAlignContentTest.cs @@ -118,18 +118,15 @@ namespace Facebook.Yoga } [Test] - public void Test_align_content_flex_end() + public void Test_align_content_flex_start_without_height_on_children() { YogaNode root = new YogaNode(); - root.FlexDirection = YogaFlexDirection.Row; - root.AlignContent = YogaAlign.FlexEnd; root.Wrap = YogaWrap.Wrap; - root.Width = 130; + root.Width = 100; root.Height = 100; YogaNode root_child0 = new YogaNode(); root_child0.Width = 50; - root_child0.Height = 10; root.Insert(0, root_child0); YogaNode root_child1 = new YogaNode(); @@ -139,7 +136,6 @@ namespace Facebook.Yoga YogaNode root_child2 = new YogaNode(); root_child2.Width = 50; - root_child2.Height = 10; root.Insert(2, root_child2); YogaNode root_child3 = new YogaNode(); @@ -149,83 +145,183 @@ namespace Facebook.Yoga YogaNode root_child4 = new YogaNode(); root_child4.Width = 50; - root_child4.Height = 10; root.Insert(4, root_child4); root.StyleDirection = YogaDirection.LTR; root.CalculateLayout(); Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(130f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutWidth); Assert.AreEqual(100f, root.LayoutHeight); Assert.AreEqual(0f, root_child0.LayoutX); - Assert.AreEqual(70f, root_child0.LayoutY); + Assert.AreEqual(0f, root_child0.LayoutY); Assert.AreEqual(50f, root_child0.LayoutWidth); - Assert.AreEqual(10f, root_child0.LayoutHeight); + Assert.AreEqual(0f, root_child0.LayoutHeight); - Assert.AreEqual(50f, root_child1.LayoutX); - Assert.AreEqual(70f, root_child1.LayoutY); + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); Assert.AreEqual(50f, root_child1.LayoutWidth); Assert.AreEqual(10f, root_child1.LayoutHeight); Assert.AreEqual(0f, root_child2.LayoutX); - Assert.AreEqual(80f, root_child2.LayoutY); + Assert.AreEqual(10f, root_child2.LayoutY); Assert.AreEqual(50f, root_child2.LayoutWidth); - Assert.AreEqual(10f, root_child2.LayoutHeight); + Assert.AreEqual(0f, root_child2.LayoutHeight); - Assert.AreEqual(50f, root_child3.LayoutX); - Assert.AreEqual(80f, root_child3.LayoutY); + Assert.AreEqual(0f, root_child3.LayoutX); + Assert.AreEqual(10f, root_child3.LayoutY); Assert.AreEqual(50f, root_child3.LayoutWidth); Assert.AreEqual(10f, root_child3.LayoutHeight); Assert.AreEqual(0f, root_child4.LayoutX); - Assert.AreEqual(90f, root_child4.LayoutY); + Assert.AreEqual(20f, root_child4.LayoutY); Assert.AreEqual(50f, root_child4.LayoutWidth); - Assert.AreEqual(10f, root_child4.LayoutHeight); + Assert.AreEqual(0f, root_child4.LayoutHeight); root.StyleDirection = YogaDirection.RTL; root.CalculateLayout(); Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(130f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutWidth); Assert.AreEqual(100f, root.LayoutHeight); - Assert.AreEqual(80f, root_child0.LayoutX); - Assert.AreEqual(70f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); Assert.AreEqual(50f, root_child0.LayoutWidth); - Assert.AreEqual(10f, root_child0.LayoutHeight); + Assert.AreEqual(0f, root_child0.LayoutHeight); - Assert.AreEqual(30f, root_child1.LayoutX); - Assert.AreEqual(70f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); Assert.AreEqual(50f, root_child1.LayoutWidth); Assert.AreEqual(10f, root_child1.LayoutHeight); - Assert.AreEqual(80f, root_child2.LayoutX); - Assert.AreEqual(80f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutX); + Assert.AreEqual(10f, root_child2.LayoutY); Assert.AreEqual(50f, root_child2.LayoutWidth); - Assert.AreEqual(10f, root_child2.LayoutHeight); + Assert.AreEqual(0f, root_child2.LayoutHeight); - Assert.AreEqual(30f, root_child3.LayoutX); - Assert.AreEqual(80f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutX); + Assert.AreEqual(10f, root_child3.LayoutY); Assert.AreEqual(50f, root_child3.LayoutWidth); Assert.AreEqual(10f, root_child3.LayoutHeight); - Assert.AreEqual(80f, root_child4.LayoutX); - Assert.AreEqual(90f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutX); + Assert.AreEqual(20f, root_child4.LayoutY); Assert.AreEqual(50f, root_child4.LayoutWidth); - Assert.AreEqual(10f, root_child4.LayoutHeight); + Assert.AreEqual(0f, root_child4.LayoutHeight); } [Test] - public void Test_align_content_center() + public void Test_align_content_flex_start_with_flex() { YogaNode root = new YogaNode(); - root.FlexDirection = YogaFlexDirection.Row; - root.AlignContent = YogaAlign.Center; root.Wrap = YogaWrap.Wrap; - root.Width = 130; + root.Width = 100; + root.Height = 120; + + YogaNode root_child0 = new YogaNode(); + root_child0.FlexGrow = 1; + root_child0.FlexBasis = 0.Percent(); + root_child0.Width = 50; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.FlexGrow = 1; + root_child1.FlexBasis = 0.Percent(); + root_child1.Width = 50; + root_child1.Height = 10; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 50; + root.Insert(2, root_child2); + + YogaNode root_child3 = new YogaNode(); + root_child3.FlexGrow = 1; + root_child3.FlexShrink = 1; + root_child3.FlexBasis = 0.Percent(); + root_child3.Width = 50; + root.Insert(3, root_child3); + + YogaNode root_child4 = new YogaNode(); + root_child4.Width = 50; + root.Insert(4, root_child4); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(120f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(40f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(40f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(40f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(80f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(0f, root_child2.LayoutHeight); + + Assert.AreEqual(0f, root_child3.LayoutX); + Assert.AreEqual(80f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(40f, root_child3.LayoutHeight); + + Assert.AreEqual(0f, root_child4.LayoutX); + Assert.AreEqual(120f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(0f, root_child4.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(120f, root.LayoutHeight); + + Assert.AreEqual(50f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(40f, root_child0.LayoutHeight); + + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(40f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(40f, root_child1.LayoutHeight); + + Assert.AreEqual(50f, root_child2.LayoutX); + Assert.AreEqual(80f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(0f, root_child2.LayoutHeight); + + Assert.AreEqual(50f, root_child3.LayoutX); + Assert.AreEqual(80f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(40f, root_child3.LayoutHeight); + + Assert.AreEqual(50f, root_child4.LayoutX); + Assert.AreEqual(120f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(0f, root_child4.LayoutHeight); + } + + [Test] + public void Test_align_content_flex_end() + { + YogaNode root = new YogaNode(); + root.AlignContent = YogaAlign.FlexEnd; + root.Wrap = YogaWrap.Wrap; + root.Width = 100; root.Height = 100; YogaNode root_child0 = new YogaNode(); @@ -257,31 +353,31 @@ namespace Facebook.Yoga Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(130f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutWidth); Assert.AreEqual(100f, root.LayoutHeight); Assert.AreEqual(0f, root_child0.LayoutX); - Assert.AreEqual(35f, root_child0.LayoutY); + Assert.AreEqual(0f, root_child0.LayoutY); Assert.AreEqual(50f, root_child0.LayoutWidth); Assert.AreEqual(10f, root_child0.LayoutHeight); - Assert.AreEqual(50f, root_child1.LayoutX); - Assert.AreEqual(35f, root_child1.LayoutY); + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(10f, root_child1.LayoutY); Assert.AreEqual(50f, root_child1.LayoutWidth); Assert.AreEqual(10f, root_child1.LayoutHeight); Assert.AreEqual(0f, root_child2.LayoutX); - Assert.AreEqual(45f, root_child2.LayoutY); + Assert.AreEqual(20f, root_child2.LayoutY); Assert.AreEqual(50f, root_child2.LayoutWidth); Assert.AreEqual(10f, root_child2.LayoutHeight); - Assert.AreEqual(50f, root_child3.LayoutX); - Assert.AreEqual(45f, root_child3.LayoutY); + Assert.AreEqual(0f, root_child3.LayoutX); + Assert.AreEqual(30f, root_child3.LayoutY); Assert.AreEqual(50f, root_child3.LayoutWidth); Assert.AreEqual(10f, root_child3.LayoutHeight); Assert.AreEqual(0f, root_child4.LayoutX); - Assert.AreEqual(55f, root_child4.LayoutY); + Assert.AreEqual(40f, root_child4.LayoutY); Assert.AreEqual(50f, root_child4.LayoutWidth); Assert.AreEqual(10f, root_child4.LayoutHeight); @@ -290,31 +386,31 @@ namespace Facebook.Yoga Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(130f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutWidth); Assert.AreEqual(100f, root.LayoutHeight); - Assert.AreEqual(80f, root_child0.LayoutX); - Assert.AreEqual(35f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); Assert.AreEqual(50f, root_child0.LayoutWidth); Assert.AreEqual(10f, root_child0.LayoutHeight); - Assert.AreEqual(30f, root_child1.LayoutX); - Assert.AreEqual(35f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(10f, root_child1.LayoutY); Assert.AreEqual(50f, root_child1.LayoutWidth); Assert.AreEqual(10f, root_child1.LayoutHeight); - Assert.AreEqual(80f, root_child2.LayoutX); - Assert.AreEqual(45f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutX); + Assert.AreEqual(20f, root_child2.LayoutY); Assert.AreEqual(50f, root_child2.LayoutWidth); Assert.AreEqual(10f, root_child2.LayoutHeight); - Assert.AreEqual(30f, root_child3.LayoutX); - Assert.AreEqual(45f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutX); + Assert.AreEqual(30f, root_child3.LayoutY); Assert.AreEqual(50f, root_child3.LayoutWidth); Assert.AreEqual(10f, root_child3.LayoutHeight); - Assert.AreEqual(80f, root_child4.LayoutX); - Assert.AreEqual(55f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutX); + Assert.AreEqual(40f, root_child4.LayoutY); Assert.AreEqual(50f, root_child4.LayoutWidth); Assert.AreEqual(10f, root_child4.LayoutHeight); } @@ -616,5 +712,1083 @@ namespace Facebook.Yoga Assert.AreEqual(10f, root_child4.LayoutHeight); } + [Test] + public void Test_align_content_stretch_row() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.AlignContent = YogaAlign.Stretch; + root.Wrap = YogaWrap.Wrap; + root.Width = 150; + root.Height = 100; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 50; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Width = 50; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 50; + root.Insert(2, root_child2); + + YogaNode root_child3 = new YogaNode(); + root_child3.Width = 50; + root.Insert(3, root_child3); + + YogaNode root_child4 = new YogaNode(); + root_child4.Width = 50; + root.Insert(4, root_child4); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(150f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(50f, root_child0.LayoutHeight); + + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(50f, root_child1.LayoutHeight); + + Assert.AreEqual(100f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(50f, root_child2.LayoutHeight); + + Assert.AreEqual(0f, root_child3.LayoutX); + Assert.AreEqual(50f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(50f, root_child3.LayoutHeight); + + Assert.AreEqual(50f, root_child4.LayoutX); + Assert.AreEqual(50f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(50f, root_child4.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(150f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(100f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(50f, root_child0.LayoutHeight); + + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(50f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(50f, root_child2.LayoutHeight); + + Assert.AreEqual(100f, root_child3.LayoutX); + Assert.AreEqual(50f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(50f, root_child3.LayoutHeight); + + Assert.AreEqual(50f, root_child4.LayoutX); + Assert.AreEqual(50f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(50f, root_child4.LayoutHeight); + } + + [Test] + public void Test_align_content_stretch_row_with_children() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.AlignContent = YogaAlign.Stretch; + root.Wrap = YogaWrap.Wrap; + root.Width = 150; + root.Height = 100; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 50; + root.Insert(0, root_child0); + + YogaNode root_child0_child0 = new YogaNode(); + root_child0_child0.FlexGrow = 1; + root_child0_child0.FlexShrink = 1; + root_child0_child0.FlexBasis = 0.Percent(); + root_child0.Insert(0, root_child0_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Width = 50; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 50; + root.Insert(2, root_child2); + + YogaNode root_child3 = new YogaNode(); + root_child3.Width = 50; + root.Insert(3, root_child3); + + YogaNode root_child4 = new YogaNode(); + root_child4.Width = 50; + root.Insert(4, root_child4); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(150f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(50f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0.LayoutY); + Assert.AreEqual(50f, root_child0_child0.LayoutWidth); + Assert.AreEqual(50f, root_child0_child0.LayoutHeight); + + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(50f, root_child1.LayoutHeight); + + Assert.AreEqual(100f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(50f, root_child2.LayoutHeight); + + Assert.AreEqual(0f, root_child3.LayoutX); + Assert.AreEqual(50f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(50f, root_child3.LayoutHeight); + + Assert.AreEqual(50f, root_child4.LayoutX); + Assert.AreEqual(50f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(50f, root_child4.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(150f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(100f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(50f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0.LayoutY); + Assert.AreEqual(50f, root_child0_child0.LayoutWidth); + Assert.AreEqual(50f, root_child0_child0.LayoutHeight); + + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(50f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(50f, root_child2.LayoutHeight); + + Assert.AreEqual(100f, root_child3.LayoutX); + Assert.AreEqual(50f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(50f, root_child3.LayoutHeight); + + Assert.AreEqual(50f, root_child4.LayoutX); + Assert.AreEqual(50f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(50f, root_child4.LayoutHeight); + } + + [Test] + public void Test_align_content_stretch_row_with_flex() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.AlignContent = YogaAlign.Stretch; + root.Wrap = YogaWrap.Wrap; + root.Width = 150; + root.Height = 100; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 50; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.FlexGrow = 1; + root_child1.FlexShrink = 1; + root_child1.FlexBasis = 0.Percent(); + root_child1.Width = 50; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 50; + root.Insert(2, root_child2); + + YogaNode root_child3 = new YogaNode(); + root_child3.FlexGrow = 1; + root_child3.FlexShrink = 1; + root_child3.FlexBasis = 0.Percent(); + root_child3.Width = 50; + root.Insert(3, root_child3); + + YogaNode root_child4 = new YogaNode(); + root_child4.Width = 50; + root.Insert(4, root_child4); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(150f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(0f, root_child1.LayoutWidth); + Assert.AreEqual(100f, root_child1.LayoutHeight); + + Assert.AreEqual(50f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(100f, root_child2.LayoutHeight); + + Assert.AreEqual(100f, root_child3.LayoutX); + Assert.AreEqual(0f, root_child3.LayoutY); + Assert.AreEqual(0f, root_child3.LayoutWidth); + Assert.AreEqual(100f, root_child3.LayoutHeight); + + Assert.AreEqual(100f, root_child4.LayoutX); + Assert.AreEqual(0f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(100f, root_child4.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(150f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(100f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + Assert.AreEqual(100f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(0f, root_child1.LayoutWidth); + Assert.AreEqual(100f, root_child1.LayoutHeight); + + Assert.AreEqual(50f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(100f, root_child2.LayoutHeight); + + Assert.AreEqual(50f, root_child3.LayoutX); + Assert.AreEqual(0f, root_child3.LayoutY); + Assert.AreEqual(0f, root_child3.LayoutWidth); + Assert.AreEqual(100f, root_child3.LayoutHeight); + + Assert.AreEqual(0f, root_child4.LayoutX); + Assert.AreEqual(0f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(100f, root_child4.LayoutHeight); + } + + [Test] + public void Test_align_content_stretch_row_with_flex_no_shrink() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.AlignContent = YogaAlign.Stretch; + root.Wrap = YogaWrap.Wrap; + root.Width = 150; + root.Height = 100; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 50; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.FlexGrow = 1; + root_child1.FlexShrink = 1; + root_child1.FlexBasis = 0.Percent(); + root_child1.Width = 50; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 50; + root.Insert(2, root_child2); + + YogaNode root_child3 = new YogaNode(); + root_child3.FlexGrow = 1; + root_child3.FlexBasis = 0.Percent(); + root_child3.Width = 50; + root.Insert(3, root_child3); + + YogaNode root_child4 = new YogaNode(); + root_child4.Width = 50; + root.Insert(4, root_child4); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(150f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(0f, root_child1.LayoutWidth); + Assert.AreEqual(100f, root_child1.LayoutHeight); + + Assert.AreEqual(50f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(100f, root_child2.LayoutHeight); + + Assert.AreEqual(100f, root_child3.LayoutX); + Assert.AreEqual(0f, root_child3.LayoutY); + Assert.AreEqual(0f, root_child3.LayoutWidth); + Assert.AreEqual(100f, root_child3.LayoutHeight); + + Assert.AreEqual(100f, root_child4.LayoutX); + Assert.AreEqual(0f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(100f, root_child4.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(150f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(100f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + Assert.AreEqual(100f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(0f, root_child1.LayoutWidth); + Assert.AreEqual(100f, root_child1.LayoutHeight); + + Assert.AreEqual(50f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(100f, root_child2.LayoutHeight); + + Assert.AreEqual(50f, root_child3.LayoutX); + Assert.AreEqual(0f, root_child3.LayoutY); + Assert.AreEqual(0f, root_child3.LayoutWidth); + Assert.AreEqual(100f, root_child3.LayoutHeight); + + Assert.AreEqual(0f, root_child4.LayoutX); + Assert.AreEqual(0f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(100f, root_child4.LayoutHeight); + } + + [Test] + public void Test_align_content_stretch_row_with_margin() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.AlignContent = YogaAlign.Stretch; + root.Wrap = YogaWrap.Wrap; + root.Width = 150; + root.Height = 100; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 50; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.MarginLeft = 10; + root_child1.MarginTop = 10; + root_child1.MarginRight = 10; + root_child1.MarginBottom = 10; + root_child1.Width = 50; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 50; + root.Insert(2, root_child2); + + YogaNode root_child3 = new YogaNode(); + root_child3.MarginLeft = 10; + root_child3.MarginTop = 10; + root_child3.MarginRight = 10; + root_child3.MarginBottom = 10; + root_child3.Width = 50; + root.Insert(3, root_child3); + + YogaNode root_child4 = new YogaNode(); + root_child4.Width = 50; + root.Insert(4, root_child4); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(150f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(40f, root_child0.LayoutHeight); + + Assert.AreEqual(60f, root_child1.LayoutX); + Assert.AreEqual(10f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(20f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(40f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(40f, root_child2.LayoutHeight); + + Assert.AreEqual(60f, root_child3.LayoutX); + Assert.AreEqual(50f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(20f, root_child3.LayoutHeight); + + Assert.AreEqual(0f, root_child4.LayoutX); + Assert.AreEqual(80f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(20f, root_child4.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(150f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(100f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(40f, root_child0.LayoutHeight); + + Assert.AreEqual(40f, root_child1.LayoutX); + Assert.AreEqual(10f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(20f, root_child1.LayoutHeight); + + Assert.AreEqual(100f, root_child2.LayoutX); + Assert.AreEqual(40f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(40f, root_child2.LayoutHeight); + + Assert.AreEqual(40f, root_child3.LayoutX); + Assert.AreEqual(50f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(20f, root_child3.LayoutHeight); + + Assert.AreEqual(100f, root_child4.LayoutX); + Assert.AreEqual(80f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(20f, root_child4.LayoutHeight); + } + + [Test] + public void Test_align_content_stretch_row_with_padding() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.AlignContent = YogaAlign.Stretch; + root.Wrap = YogaWrap.Wrap; + root.Width = 150; + root.Height = 100; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 50; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.PaddingLeft = 10; + root_child1.PaddingTop = 10; + root_child1.PaddingRight = 10; + root_child1.PaddingBottom = 10; + root_child1.Width = 50; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 50; + root.Insert(2, root_child2); + + YogaNode root_child3 = new YogaNode(); + root_child3.PaddingLeft = 10; + root_child3.PaddingTop = 10; + root_child3.PaddingRight = 10; + root_child3.PaddingBottom = 10; + root_child3.Width = 50; + root.Insert(3, root_child3); + + YogaNode root_child4 = new YogaNode(); + root_child4.Width = 50; + root.Insert(4, root_child4); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(150f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(50f, root_child0.LayoutHeight); + + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(50f, root_child1.LayoutHeight); + + Assert.AreEqual(100f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(50f, root_child2.LayoutHeight); + + Assert.AreEqual(0f, root_child3.LayoutX); + Assert.AreEqual(50f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(50f, root_child3.LayoutHeight); + + Assert.AreEqual(50f, root_child4.LayoutX); + Assert.AreEqual(50f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(50f, root_child4.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(150f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(100f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(50f, root_child0.LayoutHeight); + + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(50f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(50f, root_child2.LayoutHeight); + + Assert.AreEqual(100f, root_child3.LayoutX); + Assert.AreEqual(50f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(50f, root_child3.LayoutHeight); + + Assert.AreEqual(50f, root_child4.LayoutX); + Assert.AreEqual(50f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(50f, root_child4.LayoutHeight); + } + + [Test] + public void Test_align_content_stretch_row_with_single_row() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.AlignContent = YogaAlign.Stretch; + root.Wrap = YogaWrap.Wrap; + root.Width = 150; + root.Height = 100; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 50; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Width = 50; + root.Insert(1, root_child1); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(150f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(100f, root_child1.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(150f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(100f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(100f, root_child1.LayoutHeight); + } + + [Test] + public void Test_align_content_stretch_row_with_fixed_height() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.AlignContent = YogaAlign.Stretch; + root.Wrap = YogaWrap.Wrap; + root.Width = 150; + root.Height = 100; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 50; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Width = 50; + root_child1.Height = 60; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 50; + root.Insert(2, root_child2); + + YogaNode root_child3 = new YogaNode(); + root_child3.Width = 50; + root.Insert(3, root_child3); + + YogaNode root_child4 = new YogaNode(); + root_child4.Width = 50; + root.Insert(4, root_child4); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(150f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(80f, root_child0.LayoutHeight); + + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(60f, root_child1.LayoutHeight); + + Assert.AreEqual(100f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(80f, root_child2.LayoutHeight); + + Assert.AreEqual(0f, root_child3.LayoutX); + Assert.AreEqual(80f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(20f, root_child3.LayoutHeight); + + Assert.AreEqual(50f, root_child4.LayoutX); + Assert.AreEqual(80f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(20f, root_child4.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(150f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(100f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(80f, root_child0.LayoutHeight); + + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(60f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(80f, root_child2.LayoutHeight); + + Assert.AreEqual(100f, root_child3.LayoutX); + Assert.AreEqual(80f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(20f, root_child3.LayoutHeight); + + Assert.AreEqual(50f, root_child4.LayoutX); + Assert.AreEqual(80f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(20f, root_child4.LayoutHeight); + } + + [Test] + public void Test_align_content_stretch_row_with_max_height() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.AlignContent = YogaAlign.Stretch; + root.Wrap = YogaWrap.Wrap; + root.Width = 150; + root.Height = 100; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 50; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Width = 50; + root_child1.MaxHeight = 20; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 50; + root.Insert(2, root_child2); + + YogaNode root_child3 = new YogaNode(); + root_child3.Width = 50; + root.Insert(3, root_child3); + + YogaNode root_child4 = new YogaNode(); + root_child4.Width = 50; + root.Insert(4, root_child4); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(150f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(50f, root_child0.LayoutHeight); + + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(20f, root_child1.LayoutHeight); + + Assert.AreEqual(100f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(50f, root_child2.LayoutHeight); + + Assert.AreEqual(0f, root_child3.LayoutX); + Assert.AreEqual(50f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(50f, root_child3.LayoutHeight); + + Assert.AreEqual(50f, root_child4.LayoutX); + Assert.AreEqual(50f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(50f, root_child4.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(150f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(100f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(50f, root_child0.LayoutHeight); + + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(20f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(50f, root_child2.LayoutHeight); + + Assert.AreEqual(100f, root_child3.LayoutX); + Assert.AreEqual(50f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(50f, root_child3.LayoutHeight); + + Assert.AreEqual(50f, root_child4.LayoutX); + Assert.AreEqual(50f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(50f, root_child4.LayoutHeight); + } + + [Test] + public void Test_align_content_stretch_row_with_min_height() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.AlignContent = YogaAlign.Stretch; + root.Wrap = YogaWrap.Wrap; + root.Width = 150; + root.Height = 100; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 50; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Width = 50; + root_child1.MinHeight = 80; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 50; + root.Insert(2, root_child2); + + YogaNode root_child3 = new YogaNode(); + root_child3.Width = 50; + root.Insert(3, root_child3); + + YogaNode root_child4 = new YogaNode(); + root_child4.Width = 50; + root.Insert(4, root_child4); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(150f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(90f, root_child0.LayoutHeight); + + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(90f, root_child1.LayoutHeight); + + Assert.AreEqual(100f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(90f, root_child2.LayoutHeight); + + Assert.AreEqual(0f, root_child3.LayoutX); + Assert.AreEqual(90f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(10f, root_child3.LayoutHeight); + + Assert.AreEqual(50f, root_child4.LayoutX); + Assert.AreEqual(90f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(10f, root_child4.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(150f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(100f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(90f, root_child0.LayoutHeight); + + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(90f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(90f, root_child2.LayoutHeight); + + Assert.AreEqual(100f, root_child3.LayoutX); + Assert.AreEqual(90f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(10f, root_child3.LayoutHeight); + + Assert.AreEqual(50f, root_child4.LayoutX); + Assert.AreEqual(90f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(10f, root_child4.LayoutHeight); + } + + [Test] + public void Test_align_content_stretch_column() + { + YogaNode root = new YogaNode(); + root.AlignContent = YogaAlign.Stretch; + root.Wrap = YogaWrap.Wrap; + root.Width = 100; + root.Height = 150; + + YogaNode root_child0 = new YogaNode(); + root_child0.Height = 50; + root.Insert(0, root_child0); + + YogaNode root_child0_child0 = new YogaNode(); + root_child0_child0.FlexGrow = 1; + root_child0_child0.FlexShrink = 1; + root_child0_child0.FlexBasis = 0.Percent(); + root_child0.Insert(0, root_child0_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.FlexGrow = 1; + root_child1.FlexShrink = 1; + root_child1.FlexBasis = 0.Percent(); + root_child1.Height = 50; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Height = 50; + root.Insert(2, root_child2); + + YogaNode root_child3 = new YogaNode(); + root_child3.Height = 50; + root.Insert(3, root_child3); + + YogaNode root_child4 = new YogaNode(); + root_child4.Height = 50; + root.Insert(4, root_child4); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(150f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(50f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0.LayoutY); + Assert.AreEqual(50f, root_child0_child0.LayoutWidth); + Assert.AreEqual(50f, root_child0_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(50f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(0f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(50f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(50f, root_child2.LayoutHeight); + + Assert.AreEqual(0f, root_child3.LayoutX); + Assert.AreEqual(100f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(50f, root_child3.LayoutHeight); + + Assert.AreEqual(50f, root_child4.LayoutX); + Assert.AreEqual(0f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(50f, root_child4.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(150f, root.LayoutHeight); + + Assert.AreEqual(50f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(50f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0.LayoutY); + Assert.AreEqual(50f, root_child0_child0.LayoutWidth); + Assert.AreEqual(50f, root_child0_child0.LayoutHeight); + + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(50f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(0f, root_child1.LayoutHeight); + + Assert.AreEqual(50f, root_child2.LayoutX); + Assert.AreEqual(50f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(50f, root_child2.LayoutHeight); + + Assert.AreEqual(50f, root_child3.LayoutX); + Assert.AreEqual(100f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(50f, root_child3.LayoutHeight); + + Assert.AreEqual(0f, root_child4.LayoutX); + Assert.AreEqual(0f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(50f, root_child4.LayoutHeight); + } + } } diff --git a/gentest/fixtures/YGAlignContentTest.html b/gentest/fixtures/YGAlignContentTest.html index b1f23050..de7938fb 100644 --- a/gentest/fixtures/YGAlignContentTest.html +++ b/gentest/fixtures/YGAlignContentTest.html @@ -6,15 +6,23 @@
-
-
-
-
+
+
+
+
-
+
+
+
+
+
+
+
+ +
@@ -45,3 +53,92 @@
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
diff --git a/java/tests/com/facebook/yoga/YGAlignContentTest.java b/java/tests/com/facebook/yoga/YGAlignContentTest.java index de9daa1b..122f26cc 100644 --- a/java/tests/com/facebook/yoga/YGAlignContentTest.java +++ b/java/tests/com/facebook/yoga/YGAlignContentTest.java @@ -116,17 +116,14 @@ public class YGAlignContentTest { } @Test - public void test_align_content_flex_end() { + public void test_align_content_flex_start_without_height_on_children() { final YogaNode root = new YogaNode(); - root.setFlexDirection(YogaFlexDirection.ROW); - root.setAlignContent(YogaAlign.FLEX_END); root.setWrap(YogaWrap.WRAP); - root.setWidth(130f); + root.setWidth(100f); root.setHeight(100f); final YogaNode root_child0 = new YogaNode(); root_child0.setWidth(50f); - root_child0.setHeight(10f); root.addChildAt(root_child0, 0); final YogaNode root_child1 = new YogaNode(); @@ -136,7 +133,6 @@ public class YGAlignContentTest { final YogaNode root_child2 = new YogaNode(); root_child2.setWidth(50f); - root_child2.setHeight(10f); root.addChildAt(root_child2, 2); final YogaNode root_child3 = new YogaNode(); @@ -146,82 +142,181 @@ public class YGAlignContentTest { final YogaNode root_child4 = new YogaNode(); root_child4.setWidth(50f); - root_child4.setHeight(10f); root.addChildAt(root_child4, 4); root.setDirection(YogaDirection.LTR); root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); assertEquals(0f, root.getLayoutX(), 0.0f); assertEquals(0f, root.getLayoutY(), 0.0f); - assertEquals(130f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); assertEquals(100f, root.getLayoutHeight(), 0.0f); assertEquals(0f, root_child0.getLayoutX(), 0.0f); - assertEquals(70f, root_child0.getLayoutY(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + assertEquals(0f, root_child0.getLayoutHeight(), 0.0f); - assertEquals(50f, root_child1.getLayoutX(), 0.0f); - assertEquals(70f, root_child1.getLayoutY(), 0.0f); + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); assertEquals(0f, root_child2.getLayoutX(), 0.0f); - assertEquals(80f, root_child2.getLayoutY(), 0.0f); + assertEquals(10f, root_child2.getLayoutY(), 0.0f); assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); - assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + assertEquals(0f, root_child2.getLayoutHeight(), 0.0f); - assertEquals(50f, root_child3.getLayoutX(), 0.0f); - assertEquals(80f, root_child3.getLayoutY(), 0.0f); + assertEquals(0f, root_child3.getLayoutX(), 0.0f); + assertEquals(10f, root_child3.getLayoutY(), 0.0f); assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); assertEquals(0f, root_child4.getLayoutX(), 0.0f); - assertEquals(90f, root_child4.getLayoutY(), 0.0f); + assertEquals(20f, root_child4.getLayoutY(), 0.0f); assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); - assertEquals(10f, root_child4.getLayoutHeight(), 0.0f); + assertEquals(0f, root_child4.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(130f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); assertEquals(100f, root.getLayoutHeight(), 0.0f); - assertEquals(80f, root_child0.getLayoutX(), 0.0f); - assertEquals(70f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + assertEquals(0f, root_child0.getLayoutHeight(), 0.0f); - assertEquals(30f, root_child1.getLayoutX(), 0.0f); - assertEquals(70f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); - assertEquals(80f, root_child2.getLayoutX(), 0.0f); - assertEquals(80f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutX(), 0.0f); + assertEquals(10f, root_child2.getLayoutY(), 0.0f); assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); - assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + assertEquals(0f, root_child2.getLayoutHeight(), 0.0f); - assertEquals(30f, root_child3.getLayoutX(), 0.0f); - assertEquals(80f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutX(), 0.0f); + assertEquals(10f, root_child3.getLayoutY(), 0.0f); assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); - assertEquals(80f, root_child4.getLayoutX(), 0.0f); - assertEquals(90f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutX(), 0.0f); + assertEquals(20f, root_child4.getLayoutY(), 0.0f); assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); - assertEquals(10f, root_child4.getLayoutHeight(), 0.0f); + assertEquals(0f, root_child4.getLayoutHeight(), 0.0f); } @Test - public void test_align_content_center() { + public void test_align_content_flex_start_with_flex() { final YogaNode root = new YogaNode(); - root.setFlexDirection(YogaFlexDirection.ROW); - root.setAlignContent(YogaAlign.CENTER); root.setWrap(YogaWrap.WRAP); - root.setWidth(130f); + root.setWidth(100f); + root.setHeight(120f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setFlexGrow(1f); + root_child0.setFlexBasisPercent(0f); + root_child0.setWidth(50f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setFlexGrow(1f); + root_child1.setFlexBasisPercent(0f); + root_child1.setWidth(50f); + root_child1.setHeight(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(50f); + root.addChildAt(root_child2, 2); + + final YogaNode root_child3 = new YogaNode(); + root_child3.setFlexGrow(1f); + root_child3.setFlexShrink(1f); + root_child3.setFlexBasisPercent(0f); + root_child3.setWidth(50f); + root.addChildAt(root_child3, 3); + + final YogaNode root_child4 = new YogaNode(); + root_child4.setWidth(50f); + root.addChildAt(root_child4, 4); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(120f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(40f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(40f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(40f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(80f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child3.getLayoutX(), 0.0f); + assertEquals(80f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(40f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child4.getLayoutX(), 0.0f); + assertEquals(120f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child4.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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(120f, root.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(40f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(40f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(40f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child2.getLayoutX(), 0.0f); + assertEquals(80f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child3.getLayoutX(), 0.0f); + assertEquals(80f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(40f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child4.getLayoutX(), 0.0f); + assertEquals(120f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child4.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_content_flex_end() { + final YogaNode root = new YogaNode(); + root.setAlignContent(YogaAlign.FLEX_END); + root.setWrap(YogaWrap.WRAP); + root.setWidth(100f); root.setHeight(100f); final YogaNode root_child0 = new YogaNode(); @@ -253,31 +348,31 @@ public class YGAlignContentTest { assertEquals(0f, root.getLayoutX(), 0.0f); assertEquals(0f, root.getLayoutY(), 0.0f); - assertEquals(130f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); assertEquals(100f, root.getLayoutHeight(), 0.0f); assertEquals(0f, root_child0.getLayoutX(), 0.0f); - assertEquals(35f, root_child0.getLayoutY(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); - assertEquals(50f, root_child1.getLayoutX(), 0.0f); - assertEquals(35f, root_child1.getLayoutY(), 0.0f); + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(10f, root_child1.getLayoutY(), 0.0f); assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); assertEquals(0f, root_child2.getLayoutX(), 0.0f); - assertEquals(45f, root_child2.getLayoutY(), 0.0f); + assertEquals(20f, root_child2.getLayoutY(), 0.0f); assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); - assertEquals(50f, root_child3.getLayoutX(), 0.0f); - assertEquals(45f, root_child3.getLayoutY(), 0.0f); + assertEquals(0f, root_child3.getLayoutX(), 0.0f); + assertEquals(30f, root_child3.getLayoutY(), 0.0f); assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); assertEquals(0f, root_child4.getLayoutX(), 0.0f); - assertEquals(55f, root_child4.getLayoutY(), 0.0f); + assertEquals(40f, root_child4.getLayoutY(), 0.0f); assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); assertEquals(10f, root_child4.getLayoutHeight(), 0.0f); @@ -286,31 +381,31 @@ public class YGAlignContentTest { assertEquals(0f, root.getLayoutX(), 0.0f); assertEquals(0f, root.getLayoutY(), 0.0f); - assertEquals(130f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); assertEquals(100f, root.getLayoutHeight(), 0.0f); - assertEquals(80f, root_child0.getLayoutX(), 0.0f); - assertEquals(35f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); - assertEquals(30f, root_child1.getLayoutX(), 0.0f); - assertEquals(35f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(10f, root_child1.getLayoutY(), 0.0f); assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); - assertEquals(80f, root_child2.getLayoutX(), 0.0f); - assertEquals(45f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutX(), 0.0f); + assertEquals(20f, root_child2.getLayoutY(), 0.0f); assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); - assertEquals(30f, root_child3.getLayoutX(), 0.0f); - assertEquals(45f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutX(), 0.0f); + assertEquals(30f, root_child3.getLayoutY(), 0.0f); assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); - assertEquals(80f, root_child4.getLayoutX(), 0.0f); - assertEquals(55f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutX(), 0.0f); + assertEquals(40f, root_child4.getLayoutY(), 0.0f); assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); assertEquals(10f, root_child4.getLayoutHeight(), 0.0f); } @@ -609,4 +704,1071 @@ public class YGAlignContentTest { assertEquals(10f, root_child4.getLayoutHeight(), 0.0f); } + @Test + public void test_align_content_stretch_row() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setAlignContent(YogaAlign.STRETCH); + root.setWrap(YogaWrap.WRAP); + root.setWidth(150f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(50f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setWidth(50f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(50f); + root.addChildAt(root_child2, 2); + + final YogaNode root_child3 = new YogaNode(); + root_child3.setWidth(50f); + root.addChildAt(root_child3, 3); + + final YogaNode root_child4 = new YogaNode(); + root_child4.setWidth(50f); + root.addChildAt(root_child4, 4); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(150f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child3.getLayoutX(), 0.0f); + assertEquals(50f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child4.getLayoutX(), 0.0f); + assertEquals(50f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child4.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(150f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child3.getLayoutX(), 0.0f); + assertEquals(50f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child4.getLayoutX(), 0.0f); + assertEquals(50f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child4.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_content_stretch_row_with_children() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setAlignContent(YogaAlign.STRETCH); + root.setWrap(YogaWrap.WRAP); + root.setWidth(150f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(50f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child0_child0 = new YogaNode(); + root_child0_child0.setFlexGrow(1f); + root_child0_child0.setFlexShrink(1f); + root_child0_child0.setFlexBasisPercent(0f); + root_child0.addChildAt(root_child0_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setWidth(50f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(50f); + root.addChildAt(root_child2, 2); + + final YogaNode root_child3 = new YogaNode(); + root_child3.setWidth(50f); + root.addChildAt(root_child3, 3); + + final YogaNode root_child4 = new YogaNode(); + root_child4.setWidth(50f); + root.addChildAt(root_child4, 4); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(150f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child3.getLayoutX(), 0.0f); + assertEquals(50f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child4.getLayoutX(), 0.0f); + assertEquals(50f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child4.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(150f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child3.getLayoutX(), 0.0f); + assertEquals(50f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child4.getLayoutX(), 0.0f); + assertEquals(50f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child4.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_content_stretch_row_with_flex() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setAlignContent(YogaAlign.STRETCH); + root.setWrap(YogaWrap.WRAP); + root.setWidth(150f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(50f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setFlexGrow(1f); + root_child1.setFlexShrink(1f); + root_child1.setFlexBasisPercent(0f); + root_child1.setWidth(50f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(50f); + root.addChildAt(root_child2, 2); + + final YogaNode root_child3 = new YogaNode(); + root_child3.setFlexGrow(1f); + root_child3.setFlexShrink(1f); + root_child3.setFlexBasisPercent(0f); + root_child3.setWidth(50f); + root.addChildAt(root_child3, 3); + + final YogaNode root_child4 = new YogaNode(); + root_child4.setWidth(50f); + root.addChildAt(root_child4, 4); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(150f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(0f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child3.getLayoutX(), 0.0f); + assertEquals(0f, root_child3.getLayoutY(), 0.0f); + assertEquals(0f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child4.getLayoutX(), 0.0f); + assertEquals(0f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child4.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(150f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(0f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child3.getLayoutX(), 0.0f); + assertEquals(0f, root_child3.getLayoutY(), 0.0f); + assertEquals(0f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child4.getLayoutX(), 0.0f); + assertEquals(0f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child4.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_content_stretch_row_with_flex_no_shrink() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setAlignContent(YogaAlign.STRETCH); + root.setWrap(YogaWrap.WRAP); + root.setWidth(150f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(50f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setFlexGrow(1f); + root_child1.setFlexShrink(1f); + root_child1.setFlexBasisPercent(0f); + root_child1.setWidth(50f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(50f); + root.addChildAt(root_child2, 2); + + final YogaNode root_child3 = new YogaNode(); + root_child3.setFlexGrow(1f); + root_child3.setFlexBasisPercent(0f); + root_child3.setWidth(50f); + root.addChildAt(root_child3, 3); + + final YogaNode root_child4 = new YogaNode(); + root_child4.setWidth(50f); + root.addChildAt(root_child4, 4); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(150f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(0f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child3.getLayoutX(), 0.0f); + assertEquals(0f, root_child3.getLayoutY(), 0.0f); + assertEquals(0f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child4.getLayoutX(), 0.0f); + assertEquals(0f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child4.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(150f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(0f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child3.getLayoutX(), 0.0f); + assertEquals(0f, root_child3.getLayoutY(), 0.0f); + assertEquals(0f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child4.getLayoutX(), 0.0f); + assertEquals(0f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child4.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_content_stretch_row_with_margin() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setAlignContent(YogaAlign.STRETCH); + root.setWrap(YogaWrap.WRAP); + root.setWidth(150f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(50f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setMargin(YogaEdge.LEFT, 10f); + root_child1.setMargin(YogaEdge.TOP, 10f); + root_child1.setMargin(YogaEdge.RIGHT, 10f); + root_child1.setMargin(YogaEdge.BOTTOM, 10f); + root_child1.setWidth(50f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(50f); + root.addChildAt(root_child2, 2); + + final YogaNode root_child3 = new YogaNode(); + root_child3.setMargin(YogaEdge.LEFT, 10f); + root_child3.setMargin(YogaEdge.TOP, 10f); + root_child3.setMargin(YogaEdge.RIGHT, 10f); + root_child3.setMargin(YogaEdge.BOTTOM, 10f); + root_child3.setWidth(50f); + root.addChildAt(root_child3, 3); + + final YogaNode root_child4 = new YogaNode(); + root_child4.setWidth(50f); + root.addChildAt(root_child4, 4); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(150f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(40f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(60f, root_child1.getLayoutX(), 0.0f); + assertEquals(10f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(40f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(40f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(60f, root_child3.getLayoutX(), 0.0f); + assertEquals(50f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child4.getLayoutX(), 0.0f); + assertEquals(80f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child4.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(150f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(40f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(40f, root_child1.getLayoutX(), 0.0f); + assertEquals(10f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child2.getLayoutX(), 0.0f); + assertEquals(40f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(40f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(40f, root_child3.getLayoutX(), 0.0f); + assertEquals(50f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child4.getLayoutX(), 0.0f); + assertEquals(80f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child4.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_content_stretch_row_with_padding() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setAlignContent(YogaAlign.STRETCH); + root.setWrap(YogaWrap.WRAP); + root.setWidth(150f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(50f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setPadding(YogaEdge.LEFT, 10); + root_child1.setPadding(YogaEdge.TOP, 10); + root_child1.setPadding(YogaEdge.RIGHT, 10); + root_child1.setPadding(YogaEdge.BOTTOM, 10); + root_child1.setWidth(50f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(50f); + root.addChildAt(root_child2, 2); + + final YogaNode root_child3 = new YogaNode(); + root_child3.setPadding(YogaEdge.LEFT, 10); + root_child3.setPadding(YogaEdge.TOP, 10); + root_child3.setPadding(YogaEdge.RIGHT, 10); + root_child3.setPadding(YogaEdge.BOTTOM, 10); + root_child3.setWidth(50f); + root.addChildAt(root_child3, 3); + + final YogaNode root_child4 = new YogaNode(); + root_child4.setWidth(50f); + root.addChildAt(root_child4, 4); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(150f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child3.getLayoutX(), 0.0f); + assertEquals(50f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child4.getLayoutX(), 0.0f); + assertEquals(50f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child4.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(150f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child3.getLayoutX(), 0.0f); + assertEquals(50f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child4.getLayoutX(), 0.0f); + assertEquals(50f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child4.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_content_stretch_row_with_single_row() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setAlignContent(YogaAlign.STRETCH); + root.setWrap(YogaWrap.WRAP); + root.setWidth(150f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(50f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setWidth(50f); + root.addChildAt(root_child1, 1); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(150f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child1.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(150f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_content_stretch_row_with_fixed_height() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setAlignContent(YogaAlign.STRETCH); + root.setWrap(YogaWrap.WRAP); + root.setWidth(150f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(50f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setWidth(50f); + root_child1.setHeight(60f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(50f); + root.addChildAt(root_child2, 2); + + final YogaNode root_child3 = new YogaNode(); + root_child3.setWidth(50f); + root.addChildAt(root_child3, 3); + + final YogaNode root_child4 = new YogaNode(); + root_child4.setWidth(50f); + root.addChildAt(root_child4, 4); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(150f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(80f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(60f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(80f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child3.getLayoutX(), 0.0f); + assertEquals(80f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child4.getLayoutX(), 0.0f); + assertEquals(80f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child4.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(150f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(80f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(60f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(80f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child3.getLayoutX(), 0.0f); + assertEquals(80f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child4.getLayoutX(), 0.0f); + assertEquals(80f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child4.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_content_stretch_row_with_max_height() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setAlignContent(YogaAlign.STRETCH); + root.setWrap(YogaWrap.WRAP); + root.setWidth(150f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(50f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setWidth(50f); + root_child1.setMaxHeight(20f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(50f); + root.addChildAt(root_child2, 2); + + final YogaNode root_child3 = new YogaNode(); + root_child3.setWidth(50f); + root.addChildAt(root_child3, 3); + + final YogaNode root_child4 = new YogaNode(); + root_child4.setWidth(50f); + root.addChildAt(root_child4, 4); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(150f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child3.getLayoutX(), 0.0f); + assertEquals(50f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child4.getLayoutX(), 0.0f); + assertEquals(50f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child4.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(150f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child3.getLayoutX(), 0.0f); + assertEquals(50f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child4.getLayoutX(), 0.0f); + assertEquals(50f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child4.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_content_stretch_row_with_min_height() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setAlignContent(YogaAlign.STRETCH); + root.setWrap(YogaWrap.WRAP); + root.setWidth(150f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(50f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setWidth(50f); + root_child1.setMinHeight(80f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(50f); + root.addChildAt(root_child2, 2); + + final YogaNode root_child3 = new YogaNode(); + root_child3.setWidth(50f); + root.addChildAt(root_child3, 3); + + final YogaNode root_child4 = new YogaNode(); + root_child4.setWidth(50f); + root.addChildAt(root_child4, 4); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(150f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(90f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(90f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(90f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child3.getLayoutX(), 0.0f); + assertEquals(90f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child4.getLayoutX(), 0.0f); + assertEquals(90f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child4.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(150f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(90f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(90f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(90f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child3.getLayoutX(), 0.0f); + assertEquals(90f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child4.getLayoutX(), 0.0f); + assertEquals(90f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child4.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_content_stretch_column() { + final YogaNode root = new YogaNode(); + root.setAlignContent(YogaAlign.STRETCH); + root.setWrap(YogaWrap.WRAP); + root.setWidth(100f); + root.setHeight(150f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setHeight(50f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child0_child0 = new YogaNode(); + root_child0_child0.setFlexGrow(1f); + root_child0_child0.setFlexShrink(1f); + root_child0_child0.setFlexBasisPercent(0f); + root_child0.addChildAt(root_child0_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setFlexGrow(1f); + root_child1.setFlexShrink(1f); + root_child1.setFlexBasisPercent(0f); + root_child1.setHeight(50f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setHeight(50f); + root.addChildAt(root_child2, 2); + + final YogaNode root_child3 = new YogaNode(); + root_child3.setHeight(50f); + root.addChildAt(root_child3, 3); + + final YogaNode root_child4 = new YogaNode(); + root_child4.setHeight(50f); + root.addChildAt(root_child4, 4); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(150f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(50f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(50f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child3.getLayoutX(), 0.0f); + assertEquals(100f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child4.getLayoutX(), 0.0f); + assertEquals(0f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child4.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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(150f, root.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(50f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child2.getLayoutX(), 0.0f); + assertEquals(50f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child3.getLayoutX(), 0.0f); + assertEquals(100f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child4.getLayoutX(), 0.0f); + assertEquals(0f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child4.getLayoutHeight(), 0.0f); + } + } diff --git a/javascript/tests/Facebook.Yoga/YGAlignContentTest.js b/javascript/tests/Facebook.Yoga/YGAlignContentTest.js index 14cf9820..d18fce9a 100644 --- a/javascript/tests/Facebook.Yoga/YGAlignContentTest.js +++ b/javascript/tests/Facebook.Yoga/YGAlignContentTest.js @@ -112,17 +112,14 @@ it("align_content_flex_start", function () { (typeof gc !== "undefined") && gc(); console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); }); -it("align_content_flex_end", function () { +it("align_content_flex_start_without_height_on_children", function () { var root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignContent(Yoga.ALIGN_FLEX_END); root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(130); + root.setWidth(100); root.setHeight(100); var root_child0 = Yoga.Node.create(); root_child0.setWidth(50); - root_child0.setHeight(10); root.insertChild(root_child0, 0); var root_child1 = Yoga.Node.create(); @@ -132,7 +129,6 @@ it("align_content_flex_end", function () { var root_child2 = Yoga.Node.create(); root_child2.setWidth(50); - root_child2.setHeight(10); root.insertChild(root_child2, 2); var root_child3 = Yoga.Node.create(); @@ -142,71 +138,70 @@ it("align_content_flex_end", function () { var root_child4 = Yoga.Node.create(); root_child4.setWidth(50); - root_child4.setHeight(10); root.insertChild(root_child4, 4); 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(130 === root.getComputedWidth(), "130 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(70 === root_child0.getComputedTop(), "70 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(10 === root_child0.getComputedHeight(), "10 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + console.assert(0 === root_child0.getComputedHeight(), "0 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(70 === root_child1.getComputedTop(), "70 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(0 === root_child1.getComputedLeft(), "0 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); console.assert(10 === root_child1.getComputedHeight(), "10 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(80 === root_child2.getComputedTop(), "80 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(10 === root_child2.getComputedTop(), "10 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); - console.assert(10 === root_child2.getComputedHeight(), "10 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + console.assert(0 === root_child2.getComputedHeight(), "0 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - console.assert(50 === root_child3.getComputedLeft(), "50 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(80 === root_child3.getComputedTop(), "80 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(0 === root_child3.getComputedLeft(), "0 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(10 === root_child3.getComputedTop(), "10 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); console.assert(10 === root_child3.getComputedHeight(), "10 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); console.assert(0 === root_child4.getComputedLeft(), "0 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(90 === root_child4.getComputedTop(), "90 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(20 === root_child4.getComputedTop(), "20 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); - console.assert(10 === root_child4.getComputedHeight(), "10 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); + console.assert(0 === root_child4.getComputedHeight(), "0 === root_child4.getComputedHeight() (" + root_child4.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(130 === root.getComputedWidth(), "130 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - console.assert(80 === root_child0.getComputedLeft(), "80 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(70 === root_child0.getComputedTop(), "70 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedLeft(), "50 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(10 === root_child0.getComputedHeight(), "10 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + console.assert(0 === root_child0.getComputedHeight(), "0 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - console.assert(30 === root_child1.getComputedLeft(), "30 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(70 === root_child1.getComputedTop(), "70 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); console.assert(10 === root_child1.getComputedHeight(), "10 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - console.assert(80 === root_child2.getComputedLeft(), "80 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(80 === root_child2.getComputedTop(), "80 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedLeft(), "50 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(10 === root_child2.getComputedTop(), "10 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); - console.assert(10 === root_child2.getComputedHeight(), "10 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + console.assert(0 === root_child2.getComputedHeight(), "0 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - console.assert(30 === root_child3.getComputedLeft(), "30 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(80 === root_child3.getComputedTop(), "80 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedLeft(), "50 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(10 === root_child3.getComputedTop(), "10 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); console.assert(10 === root_child3.getComputedHeight(), "10 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - console.assert(80 === root_child4.getComputedLeft(), "80 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(90 === root_child4.getComputedTop(), "90 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(20 === root_child4.getComputedTop(), "20 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); - console.assert(10 === root_child4.getComputedHeight(), "10 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); + console.assert(0 === root_child4.getComputedHeight(), "0 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); if (typeof root !== "undefined") root.freeRecursive(); @@ -214,12 +209,114 @@ it("align_content_flex_end", function () { (typeof gc !== "undefined") && gc(); console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); }); -it("align_content_center", function () { +it("align_content_flex_start_with_flex", function () { var root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignContent(Yoga.ALIGN_CENTER); root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(130); + root.setWidth(100); + root.setHeight(120); + + var root_child0 = Yoga.Node.create(); + root_child0.setFlexGrow(1); + root_child0.setFlexBasis("0%"); + root_child0.setWidth(50); + root.insertChild(root_child0, 0); + + var root_child1 = Yoga.Node.create(); + root_child1.setFlexGrow(1); + root_child1.setFlexBasis("0%"); + root_child1.setWidth(50); + root_child1.setHeight(10); + root.insertChild(root_child1, 1); + + var root_child2 = Yoga.Node.create(); + root_child2.setWidth(50); + root.insertChild(root_child2, 2); + + var root_child3 = Yoga.Node.create(); + root_child3.setFlexGrow(1); + root_child3.setFlexShrink(1); + root_child3.setFlexBasis("0%"); + root_child3.setWidth(50); + root.insertChild(root_child3, 3); + + var root_child4 = Yoga.Node.create(); + root_child4.setWidth(50); + root.insertChild(root_child4, 4); + 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(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(120 === root.getComputedHeight(), "120 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(40 === root_child0.getComputedHeight(), "40 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(0 === root_child1.getComputedLeft(), "0 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(40 === root_child1.getComputedTop(), "40 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(40 === root_child1.getComputedHeight(), "40 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(80 === root_child2.getComputedTop(), "80 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); + console.assert(0 === root_child2.getComputedHeight(), "0 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + + console.assert(0 === root_child3.getComputedLeft(), "0 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(80 === root_child3.getComputedTop(), "80 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); + console.assert(40 === root_child3.getComputedHeight(), "40 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); + + console.assert(0 === root_child4.getComputedLeft(), "0 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(120 === root_child4.getComputedTop(), "120 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); + console.assert(0 === root_child4.getComputedHeight(), "0 === root_child4.getComputedHeight() (" + root_child4.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(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(120 === root.getComputedHeight(), "120 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(50 === root_child0.getComputedLeft(), "50 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(40 === root_child0.getComputedHeight(), "40 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(40 === root_child1.getComputedTop(), "40 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(40 === root_child1.getComputedHeight(), "40 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + console.assert(50 === root_child2.getComputedLeft(), "50 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(80 === root_child2.getComputedTop(), "80 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); + console.assert(0 === root_child2.getComputedHeight(), "0 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + + console.assert(50 === root_child3.getComputedLeft(), "50 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(80 === root_child3.getComputedTop(), "80 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); + console.assert(40 === root_child3.getComputedHeight(), "40 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); + + console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(120 === root_child4.getComputedTop(), "120 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); + console.assert(0 === root_child4.getComputedHeight(), "0 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); + + if (typeof root !== "undefined") + root.freeRecursive(); + + (typeof gc !== "undefined") && gc(); + console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); +}); +it("align_content_flex_end", function () { + var root = Yoga.Node.create(); + root.setAlignContent(Yoga.ALIGN_FLEX_END); + root.setFlexWrap(Yoga.WRAP_WRAP); + root.setWidth(100); root.setHeight(100); var root_child0 = Yoga.Node.create(); @@ -250,31 +347,31 @@ it("align_content_center", function () { console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); - console.assert(130 === root.getComputedWidth(), "130 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(35 === root_child0.getComputedTop(), "35 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); console.assert(10 === root_child0.getComputedHeight(), "10 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(35 === root_child1.getComputedTop(), "35 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(0 === root_child1.getComputedLeft(), "0 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(10 === root_child1.getComputedTop(), "10 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); console.assert(10 === root_child1.getComputedHeight(), "10 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(45 === root_child2.getComputedTop(), "45 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(20 === root_child2.getComputedTop(), "20 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); console.assert(10 === root_child2.getComputedHeight(), "10 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - console.assert(50 === root_child3.getComputedLeft(), "50 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(45 === root_child3.getComputedTop(), "45 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(0 === root_child3.getComputedLeft(), "0 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(30 === root_child3.getComputedTop(), "30 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); console.assert(10 === root_child3.getComputedHeight(), "10 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); console.assert(0 === root_child4.getComputedLeft(), "0 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(55 === root_child4.getComputedTop(), "55 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(40 === root_child4.getComputedTop(), "40 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); console.assert(10 === root_child4.getComputedHeight(), "10 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); @@ -282,31 +379,31 @@ it("align_content_center", function () { console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); - console.assert(130 === root.getComputedWidth(), "130 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - console.assert(80 === root_child0.getComputedLeft(), "80 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(35 === root_child0.getComputedTop(), "35 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedLeft(), "50 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); console.assert(10 === root_child0.getComputedHeight(), "10 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - console.assert(30 === root_child1.getComputedLeft(), "30 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(35 === root_child1.getComputedTop(), "35 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(10 === root_child1.getComputedTop(), "10 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); console.assert(10 === root_child1.getComputedHeight(), "10 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - console.assert(80 === root_child2.getComputedLeft(), "80 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(45 === root_child2.getComputedTop(), "45 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedLeft(), "50 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(20 === root_child2.getComputedTop(), "20 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); console.assert(10 === root_child2.getComputedHeight(), "10 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - console.assert(30 === root_child3.getComputedLeft(), "30 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(45 === root_child3.getComputedTop(), "45 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedLeft(), "50 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(30 === root_child3.getComputedTop(), "30 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); console.assert(10 === root_child3.getComputedHeight(), "10 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - console.assert(80 === root_child4.getComputedLeft(), "80 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(55 === root_child4.getComputedTop(), "55 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(40 === root_child4.getComputedTop(), "40 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); console.assert(10 === root_child4.getComputedHeight(), "10 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); @@ -616,3 +713,1092 @@ it("align_content_spacearound", function () { (typeof gc !== "undefined") && gc(); console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); }); +it("align_content_stretch_row", function () { + var root = Yoga.Node.create(); + root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); + root.setAlignContent(Yoga.ALIGN_STRETCH); + root.setFlexWrap(Yoga.WRAP_WRAP); + root.setWidth(150); + root.setHeight(100); + + var root_child0 = Yoga.Node.create(); + root_child0.setWidth(50); + root.insertChild(root_child0, 0); + + var root_child1 = Yoga.Node.create(); + root_child1.setWidth(50); + root.insertChild(root_child1, 1); + + var root_child2 = Yoga.Node.create(); + root_child2.setWidth(50); + root.insertChild(root_child2, 2); + + var root_child3 = Yoga.Node.create(); + root_child3.setWidth(50); + root.insertChild(root_child3, 3); + + var root_child4 = Yoga.Node.create(); + root_child4.setWidth(50); + root.insertChild(root_child4, 4); + 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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(50 === root_child0.getComputedHeight(), "50 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(50 === root_child1.getComputedHeight(), "50 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + console.assert(100 === root_child2.getComputedLeft(), "100 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); + console.assert(50 === root_child2.getComputedHeight(), "50 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + + console.assert(0 === root_child3.getComputedLeft(), "0 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(50 === root_child3.getComputedTop(), "50 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); + console.assert(50 === root_child3.getComputedHeight(), "50 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); + + console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(50 === root_child4.getComputedTop(), "50 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); + console.assert(50 === root_child4.getComputedHeight(), "50 === root_child4.getComputedHeight() (" + root_child4.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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(100 === root_child0.getComputedLeft(), "100 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(50 === root_child0.getComputedHeight(), "50 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(50 === root_child1.getComputedHeight(), "50 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); + console.assert(50 === root_child2.getComputedHeight(), "50 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + + console.assert(100 === root_child3.getComputedLeft(), "100 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(50 === root_child3.getComputedTop(), "50 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); + console.assert(50 === root_child3.getComputedHeight(), "50 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); + + console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(50 === root_child4.getComputedTop(), "50 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); + console.assert(50 === root_child4.getComputedHeight(), "50 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); + + if (typeof root !== "undefined") + root.freeRecursive(); + + (typeof gc !== "undefined") && gc(); + console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); +}); +it("align_content_stretch_row_with_children", function () { + var root = Yoga.Node.create(); + root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); + root.setAlignContent(Yoga.ALIGN_STRETCH); + root.setFlexWrap(Yoga.WRAP_WRAP); + root.setWidth(150); + root.setHeight(100); + + var root_child0 = Yoga.Node.create(); + root_child0.setWidth(50); + root.insertChild(root_child0, 0); + + var root_child0_child0 = Yoga.Node.create(); + root_child0_child0.setFlexGrow(1); + root_child0_child0.setFlexShrink(1); + root_child0_child0.setFlexBasis("0%"); + root_child0.insertChild(root_child0_child0, 0); + + var root_child1 = Yoga.Node.create(); + root_child1.setWidth(50); + root.insertChild(root_child1, 1); + + var root_child2 = Yoga.Node.create(); + root_child2.setWidth(50); + root.insertChild(root_child2, 2); + + var root_child3 = Yoga.Node.create(); + root_child3.setWidth(50); + root.insertChild(root_child3, 3); + + var root_child4 = Yoga.Node.create(); + root_child4.setWidth(50); + root.insertChild(root_child4, 4); + 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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(50 === root_child0.getComputedHeight(), "50 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(0 === root_child0_child0.getComputedLeft(), "0 === 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(50 === root_child0_child0.getComputedWidth(), "50 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")"); + console.assert(50 === root_child0_child0.getComputedHeight(), "50 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")"); + + console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(50 === root_child1.getComputedHeight(), "50 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + console.assert(100 === root_child2.getComputedLeft(), "100 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); + console.assert(50 === root_child2.getComputedHeight(), "50 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + + console.assert(0 === root_child3.getComputedLeft(), "0 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(50 === root_child3.getComputedTop(), "50 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); + console.assert(50 === root_child3.getComputedHeight(), "50 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); + + console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(50 === root_child4.getComputedTop(), "50 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); + console.assert(50 === root_child4.getComputedHeight(), "50 === root_child4.getComputedHeight() (" + root_child4.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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(100 === root_child0.getComputedLeft(), "100 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(50 === root_child0.getComputedHeight(), "50 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(0 === root_child0_child0.getComputedLeft(), "0 === 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(50 === root_child0_child0.getComputedWidth(), "50 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")"); + console.assert(50 === root_child0_child0.getComputedHeight(), "50 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")"); + + console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(50 === root_child1.getComputedHeight(), "50 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); + console.assert(50 === root_child2.getComputedHeight(), "50 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + + console.assert(100 === root_child3.getComputedLeft(), "100 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(50 === root_child3.getComputedTop(), "50 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); + console.assert(50 === root_child3.getComputedHeight(), "50 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); + + console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(50 === root_child4.getComputedTop(), "50 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); + console.assert(50 === root_child4.getComputedHeight(), "50 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); + + if (typeof root !== "undefined") + root.freeRecursive(); + + (typeof gc !== "undefined") && gc(); + console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); +}); +it("align_content_stretch_row_with_flex", function () { + var root = Yoga.Node.create(); + root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); + root.setAlignContent(Yoga.ALIGN_STRETCH); + root.setFlexWrap(Yoga.WRAP_WRAP); + root.setWidth(150); + root.setHeight(100); + + var root_child0 = Yoga.Node.create(); + root_child0.setWidth(50); + root.insertChild(root_child0, 0); + + var root_child1 = Yoga.Node.create(); + root_child1.setFlexGrow(1); + root_child1.setFlexShrink(1); + root_child1.setFlexBasis("0%"); + root_child1.setWidth(50); + root.insertChild(root_child1, 1); + + var root_child2 = Yoga.Node.create(); + root_child2.setWidth(50); + root.insertChild(root_child2, 2); + + var root_child3 = Yoga.Node.create(); + root_child3.setFlexGrow(1); + root_child3.setFlexShrink(1); + root_child3.setFlexBasis("0%"); + root_child3.setWidth(50); + root.insertChild(root_child3, 3); + + var root_child4 = Yoga.Node.create(); + root_child4.setWidth(50); + root.insertChild(root_child4, 4); + 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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(100 === root_child0.getComputedHeight(), "100 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(0 === root_child1.getComputedWidth(), "0 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(100 === root_child1.getComputedHeight(), "100 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + console.assert(50 === root_child2.getComputedLeft(), "50 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); + console.assert(100 === root_child2.getComputedHeight(), "100 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + + console.assert(100 === root_child3.getComputedLeft(), "100 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(0 === root_child3.getComputedTop(), "0 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(0 === root_child3.getComputedWidth(), "0 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); + console.assert(100 === root_child3.getComputedHeight(), "100 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); + + console.assert(100 === root_child4.getComputedLeft(), "100 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(0 === root_child4.getComputedTop(), "0 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); + console.assert(100 === root_child4.getComputedHeight(), "100 === root_child4.getComputedHeight() (" + root_child4.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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(100 === root_child0.getComputedLeft(), "100 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(100 === root_child0.getComputedHeight(), "100 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(100 === root_child1.getComputedLeft(), "100 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(0 === root_child1.getComputedWidth(), "0 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(100 === root_child1.getComputedHeight(), "100 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + console.assert(50 === root_child2.getComputedLeft(), "50 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); + console.assert(100 === root_child2.getComputedHeight(), "100 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + + console.assert(50 === root_child3.getComputedLeft(), "50 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(0 === root_child3.getComputedTop(), "0 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(0 === root_child3.getComputedWidth(), "0 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); + console.assert(100 === root_child3.getComputedHeight(), "100 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); + + console.assert(0 === root_child4.getComputedLeft(), "0 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(0 === root_child4.getComputedTop(), "0 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); + console.assert(100 === root_child4.getComputedHeight(), "100 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); + + if (typeof root !== "undefined") + root.freeRecursive(); + + (typeof gc !== "undefined") && gc(); + console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); +}); +it("align_content_stretch_row_with_flex_no_shrink", function () { + var root = Yoga.Node.create(); + root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); + root.setAlignContent(Yoga.ALIGN_STRETCH); + root.setFlexWrap(Yoga.WRAP_WRAP); + root.setWidth(150); + root.setHeight(100); + + var root_child0 = Yoga.Node.create(); + root_child0.setWidth(50); + root.insertChild(root_child0, 0); + + var root_child1 = Yoga.Node.create(); + root_child1.setFlexGrow(1); + root_child1.setFlexShrink(1); + root_child1.setFlexBasis("0%"); + root_child1.setWidth(50); + root.insertChild(root_child1, 1); + + var root_child2 = Yoga.Node.create(); + root_child2.setWidth(50); + root.insertChild(root_child2, 2); + + var root_child3 = Yoga.Node.create(); + root_child3.setFlexGrow(1); + root_child3.setFlexBasis("0%"); + root_child3.setWidth(50); + root.insertChild(root_child3, 3); + + var root_child4 = Yoga.Node.create(); + root_child4.setWidth(50); + root.insertChild(root_child4, 4); + 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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(100 === root_child0.getComputedHeight(), "100 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(0 === root_child1.getComputedWidth(), "0 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(100 === root_child1.getComputedHeight(), "100 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + console.assert(50 === root_child2.getComputedLeft(), "50 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); + console.assert(100 === root_child2.getComputedHeight(), "100 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + + console.assert(100 === root_child3.getComputedLeft(), "100 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(0 === root_child3.getComputedTop(), "0 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(0 === root_child3.getComputedWidth(), "0 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); + console.assert(100 === root_child3.getComputedHeight(), "100 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); + + console.assert(100 === root_child4.getComputedLeft(), "100 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(0 === root_child4.getComputedTop(), "0 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); + console.assert(100 === root_child4.getComputedHeight(), "100 === root_child4.getComputedHeight() (" + root_child4.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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(100 === root_child0.getComputedLeft(), "100 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(100 === root_child0.getComputedHeight(), "100 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(100 === root_child1.getComputedLeft(), "100 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(0 === root_child1.getComputedWidth(), "0 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(100 === root_child1.getComputedHeight(), "100 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + console.assert(50 === root_child2.getComputedLeft(), "50 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); + console.assert(100 === root_child2.getComputedHeight(), "100 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + + console.assert(50 === root_child3.getComputedLeft(), "50 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(0 === root_child3.getComputedTop(), "0 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(0 === root_child3.getComputedWidth(), "0 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); + console.assert(100 === root_child3.getComputedHeight(), "100 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); + + console.assert(0 === root_child4.getComputedLeft(), "0 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(0 === root_child4.getComputedTop(), "0 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); + console.assert(100 === root_child4.getComputedHeight(), "100 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); + + if (typeof root !== "undefined") + root.freeRecursive(); + + (typeof gc !== "undefined") && gc(); + console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); +}); +it("align_content_stretch_row_with_margin", function () { + var root = Yoga.Node.create(); + root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); + root.setAlignContent(Yoga.ALIGN_STRETCH); + root.setFlexWrap(Yoga.WRAP_WRAP); + root.setWidth(150); + root.setHeight(100); + + var root_child0 = Yoga.Node.create(); + root_child0.setWidth(50); + root.insertChild(root_child0, 0); + + var root_child1 = Yoga.Node.create(); + root_child1.setMargin(Yoga.EDGE_LEFT, 10); + root_child1.setMargin(Yoga.EDGE_TOP, 10); + root_child1.setMargin(Yoga.EDGE_RIGHT, 10); + root_child1.setMargin(Yoga.EDGE_BOTTOM, 10); + root_child1.setWidth(50); + root.insertChild(root_child1, 1); + + var root_child2 = Yoga.Node.create(); + root_child2.setWidth(50); + root.insertChild(root_child2, 2); + + var root_child3 = Yoga.Node.create(); + root_child3.setMargin(Yoga.EDGE_LEFT, 10); + root_child3.setMargin(Yoga.EDGE_TOP, 10); + root_child3.setMargin(Yoga.EDGE_RIGHT, 10); + root_child3.setMargin(Yoga.EDGE_BOTTOM, 10); + root_child3.setWidth(50); + root.insertChild(root_child3, 3); + + var root_child4 = Yoga.Node.create(); + root_child4.setWidth(50); + root.insertChild(root_child4, 4); + 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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(40 === root_child0.getComputedHeight(), "40 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(60 === root_child1.getComputedLeft(), "60 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(10 === root_child1.getComputedTop(), "10 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(20 === root_child1.getComputedHeight(), "20 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(40 === root_child2.getComputedTop(), "40 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); + console.assert(40 === root_child2.getComputedHeight(), "40 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + + console.assert(60 === root_child3.getComputedLeft(), "60 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(50 === root_child3.getComputedTop(), "50 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); + console.assert(20 === root_child3.getComputedHeight(), "20 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); + + console.assert(0 === root_child4.getComputedLeft(), "0 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(80 === root_child4.getComputedTop(), "80 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); + console.assert(20 === root_child4.getComputedHeight(), "20 === root_child4.getComputedHeight() (" + root_child4.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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(100 === root_child0.getComputedLeft(), "100 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(40 === root_child0.getComputedHeight(), "40 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(40 === root_child1.getComputedLeft(), "40 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(10 === root_child1.getComputedTop(), "10 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(20 === root_child1.getComputedHeight(), "20 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + console.assert(100 === root_child2.getComputedLeft(), "100 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(40 === root_child2.getComputedTop(), "40 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); + console.assert(40 === root_child2.getComputedHeight(), "40 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + + console.assert(40 === root_child3.getComputedLeft(), "40 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(50 === root_child3.getComputedTop(), "50 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); + console.assert(20 === root_child3.getComputedHeight(), "20 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); + + console.assert(100 === root_child4.getComputedLeft(), "100 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(80 === root_child4.getComputedTop(), "80 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); + console.assert(20 === root_child4.getComputedHeight(), "20 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); + + if (typeof root !== "undefined") + root.freeRecursive(); + + (typeof gc !== "undefined") && gc(); + console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); +}); +it("align_content_stretch_row_with_padding", function () { + var root = Yoga.Node.create(); + root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); + root.setAlignContent(Yoga.ALIGN_STRETCH); + root.setFlexWrap(Yoga.WRAP_WRAP); + root.setWidth(150); + root.setHeight(100); + + var root_child0 = Yoga.Node.create(); + root_child0.setWidth(50); + root.insertChild(root_child0, 0); + + var root_child1 = Yoga.Node.create(); + root_child1.setPadding(Yoga.EDGE_LEFT, 10); + root_child1.setPadding(Yoga.EDGE_TOP, 10); + root_child1.setPadding(Yoga.EDGE_RIGHT, 10); + root_child1.setPadding(Yoga.EDGE_BOTTOM, 10); + root_child1.setWidth(50); + root.insertChild(root_child1, 1); + + var root_child2 = Yoga.Node.create(); + root_child2.setWidth(50); + root.insertChild(root_child2, 2); + + var root_child3 = Yoga.Node.create(); + root_child3.setPadding(Yoga.EDGE_LEFT, 10); + root_child3.setPadding(Yoga.EDGE_TOP, 10); + root_child3.setPadding(Yoga.EDGE_RIGHT, 10); + root_child3.setPadding(Yoga.EDGE_BOTTOM, 10); + root_child3.setWidth(50); + root.insertChild(root_child3, 3); + + var root_child4 = Yoga.Node.create(); + root_child4.setWidth(50); + root.insertChild(root_child4, 4); + 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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(50 === root_child0.getComputedHeight(), "50 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(50 === root_child1.getComputedHeight(), "50 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + console.assert(100 === root_child2.getComputedLeft(), "100 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); + console.assert(50 === root_child2.getComputedHeight(), "50 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + + console.assert(0 === root_child3.getComputedLeft(), "0 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(50 === root_child3.getComputedTop(), "50 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); + console.assert(50 === root_child3.getComputedHeight(), "50 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); + + console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(50 === root_child4.getComputedTop(), "50 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); + console.assert(50 === root_child4.getComputedHeight(), "50 === root_child4.getComputedHeight() (" + root_child4.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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(100 === root_child0.getComputedLeft(), "100 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(50 === root_child0.getComputedHeight(), "50 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(50 === root_child1.getComputedHeight(), "50 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); + console.assert(50 === root_child2.getComputedHeight(), "50 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + + console.assert(100 === root_child3.getComputedLeft(), "100 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(50 === root_child3.getComputedTop(), "50 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); + console.assert(50 === root_child3.getComputedHeight(), "50 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); + + console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(50 === root_child4.getComputedTop(), "50 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); + console.assert(50 === root_child4.getComputedHeight(), "50 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); + + if (typeof root !== "undefined") + root.freeRecursive(); + + (typeof gc !== "undefined") && gc(); + console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); +}); +it("align_content_stretch_row_with_single_row", function () { + var root = Yoga.Node.create(); + root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); + root.setAlignContent(Yoga.ALIGN_STRETCH); + root.setFlexWrap(Yoga.WRAP_WRAP); + root.setWidth(150); + root.setHeight(100); + + var root_child0 = Yoga.Node.create(); + root_child0.setWidth(50); + root.insertChild(root_child0, 0); + + var root_child1 = Yoga.Node.create(); + root_child1.setWidth(50); + root.insertChild(root_child1, 1); + 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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(100 === root_child0.getComputedHeight(), "100 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(100 === root_child1.getComputedHeight(), "100 === root_child1.getComputedHeight() (" + root_child1.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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(100 === root_child0.getComputedLeft(), "100 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(100 === root_child0.getComputedHeight(), "100 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(100 === root_child1.getComputedHeight(), "100 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + if (typeof root !== "undefined") + root.freeRecursive(); + + (typeof gc !== "undefined") && gc(); + console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); +}); +it("align_content_stretch_row_with_fixed_height", function () { + var root = Yoga.Node.create(); + root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); + root.setAlignContent(Yoga.ALIGN_STRETCH); + root.setFlexWrap(Yoga.WRAP_WRAP); + root.setWidth(150); + root.setHeight(100); + + var root_child0 = Yoga.Node.create(); + root_child0.setWidth(50); + root.insertChild(root_child0, 0); + + var root_child1 = Yoga.Node.create(); + root_child1.setWidth(50); + root_child1.setHeight(60); + root.insertChild(root_child1, 1); + + var root_child2 = Yoga.Node.create(); + root_child2.setWidth(50); + root.insertChild(root_child2, 2); + + var root_child3 = Yoga.Node.create(); + root_child3.setWidth(50); + root.insertChild(root_child3, 3); + + var root_child4 = Yoga.Node.create(); + root_child4.setWidth(50); + root.insertChild(root_child4, 4); + 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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(80 === root_child0.getComputedHeight(), "80 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(60 === root_child1.getComputedHeight(), "60 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + console.assert(100 === root_child2.getComputedLeft(), "100 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); + console.assert(80 === root_child2.getComputedHeight(), "80 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + + console.assert(0 === root_child3.getComputedLeft(), "0 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(80 === root_child3.getComputedTop(), "80 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); + console.assert(20 === root_child3.getComputedHeight(), "20 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); + + console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(80 === root_child4.getComputedTop(), "80 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); + console.assert(20 === root_child4.getComputedHeight(), "20 === root_child4.getComputedHeight() (" + root_child4.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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(100 === root_child0.getComputedLeft(), "100 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(80 === root_child0.getComputedHeight(), "80 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(60 === root_child1.getComputedHeight(), "60 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); + console.assert(80 === root_child2.getComputedHeight(), "80 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + + console.assert(100 === root_child3.getComputedLeft(), "100 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(80 === root_child3.getComputedTop(), "80 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); + console.assert(20 === root_child3.getComputedHeight(), "20 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); + + console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(80 === root_child4.getComputedTop(), "80 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); + console.assert(20 === root_child4.getComputedHeight(), "20 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); + + if (typeof root !== "undefined") + root.freeRecursive(); + + (typeof gc !== "undefined") && gc(); + console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); +}); +it("align_content_stretch_row_with_max_height", function () { + var root = Yoga.Node.create(); + root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); + root.setAlignContent(Yoga.ALIGN_STRETCH); + root.setFlexWrap(Yoga.WRAP_WRAP); + root.setWidth(150); + root.setHeight(100); + + var root_child0 = Yoga.Node.create(); + root_child0.setWidth(50); + root.insertChild(root_child0, 0); + + var root_child1 = Yoga.Node.create(); + root_child1.setWidth(50); + root_child1.setMaxHeight(20); + root.insertChild(root_child1, 1); + + var root_child2 = Yoga.Node.create(); + root_child2.setWidth(50); + root.insertChild(root_child2, 2); + + var root_child3 = Yoga.Node.create(); + root_child3.setWidth(50); + root.insertChild(root_child3, 3); + + var root_child4 = Yoga.Node.create(); + root_child4.setWidth(50); + root.insertChild(root_child4, 4); + 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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(50 === root_child0.getComputedHeight(), "50 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(20 === root_child1.getComputedHeight(), "20 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + console.assert(100 === root_child2.getComputedLeft(), "100 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); + console.assert(50 === root_child2.getComputedHeight(), "50 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + + console.assert(0 === root_child3.getComputedLeft(), "0 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(50 === root_child3.getComputedTop(), "50 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); + console.assert(50 === root_child3.getComputedHeight(), "50 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); + + console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(50 === root_child4.getComputedTop(), "50 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); + console.assert(50 === root_child4.getComputedHeight(), "50 === root_child4.getComputedHeight() (" + root_child4.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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(100 === root_child0.getComputedLeft(), "100 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(50 === root_child0.getComputedHeight(), "50 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(20 === root_child1.getComputedHeight(), "20 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); + console.assert(50 === root_child2.getComputedHeight(), "50 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + + console.assert(100 === root_child3.getComputedLeft(), "100 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(50 === root_child3.getComputedTop(), "50 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); + console.assert(50 === root_child3.getComputedHeight(), "50 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); + + console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(50 === root_child4.getComputedTop(), "50 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); + console.assert(50 === root_child4.getComputedHeight(), "50 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); + + if (typeof root !== "undefined") + root.freeRecursive(); + + (typeof gc !== "undefined") && gc(); + console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); +}); +it("align_content_stretch_row_with_min_height", function () { + var root = Yoga.Node.create(); + root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); + root.setAlignContent(Yoga.ALIGN_STRETCH); + root.setFlexWrap(Yoga.WRAP_WRAP); + root.setWidth(150); + root.setHeight(100); + + var root_child0 = Yoga.Node.create(); + root_child0.setWidth(50); + root.insertChild(root_child0, 0); + + var root_child1 = Yoga.Node.create(); + root_child1.setWidth(50); + root_child1.setMinHeight(80); + root.insertChild(root_child1, 1); + + var root_child2 = Yoga.Node.create(); + root_child2.setWidth(50); + root.insertChild(root_child2, 2); + + var root_child3 = Yoga.Node.create(); + root_child3.setWidth(50); + root.insertChild(root_child3, 3); + + var root_child4 = Yoga.Node.create(); + root_child4.setWidth(50); + root.insertChild(root_child4, 4); + 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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(90 === root_child0.getComputedHeight(), "90 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(90 === root_child1.getComputedHeight(), "90 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + console.assert(100 === root_child2.getComputedLeft(), "100 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); + console.assert(90 === root_child2.getComputedHeight(), "90 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + + console.assert(0 === root_child3.getComputedLeft(), "0 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(90 === root_child3.getComputedTop(), "90 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); + console.assert(10 === root_child3.getComputedHeight(), "10 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); + + console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(90 === root_child4.getComputedTop(), "90 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); + console.assert(10 === root_child4.getComputedHeight(), "10 === root_child4.getComputedHeight() (" + root_child4.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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(100 === root_child0.getComputedLeft(), "100 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(90 === root_child0.getComputedHeight(), "90 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(90 === root_child1.getComputedHeight(), "90 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); + console.assert(90 === root_child2.getComputedHeight(), "90 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + + console.assert(100 === root_child3.getComputedLeft(), "100 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(90 === root_child3.getComputedTop(), "90 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); + console.assert(10 === root_child3.getComputedHeight(), "10 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); + + console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(90 === root_child4.getComputedTop(), "90 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); + console.assert(10 === root_child4.getComputedHeight(), "10 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); + + if (typeof root !== "undefined") + root.freeRecursive(); + + (typeof gc !== "undefined") && gc(); + console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); +}); +it("align_content_stretch_column", function () { + var root = Yoga.Node.create(); + root.setAlignContent(Yoga.ALIGN_STRETCH); + root.setFlexWrap(Yoga.WRAP_WRAP); + root.setWidth(100); + root.setHeight(150); + + var root_child0 = Yoga.Node.create(); + root_child0.setHeight(50); + root.insertChild(root_child0, 0); + + var root_child0_child0 = Yoga.Node.create(); + root_child0_child0.setFlexGrow(1); + root_child0_child0.setFlexShrink(1); + root_child0_child0.setFlexBasis("0%"); + root_child0.insertChild(root_child0_child0, 0); + + var root_child1 = Yoga.Node.create(); + root_child1.setFlexGrow(1); + root_child1.setFlexShrink(1); + root_child1.setFlexBasis("0%"); + root_child1.setHeight(50); + root.insertChild(root_child1, 1); + + var root_child2 = Yoga.Node.create(); + root_child2.setHeight(50); + root.insertChild(root_child2, 2); + + var root_child3 = Yoga.Node.create(); + root_child3.setHeight(50); + root.insertChild(root_child3, 3); + + var root_child4 = Yoga.Node.create(); + root_child4.setHeight(50); + root.insertChild(root_child4, 4); + 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(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(150 === root.getComputedHeight(), "150 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(50 === root_child0.getComputedHeight(), "50 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(0 === root_child0_child0.getComputedLeft(), "0 === 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(50 === root_child0_child0.getComputedWidth(), "50 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")"); + console.assert(50 === root_child0_child0.getComputedHeight(), "50 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")"); + + console.assert(0 === root_child1.getComputedLeft(), "0 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(50 === root_child1.getComputedTop(), "50 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(0 === root_child1.getComputedHeight(), "0 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(50 === root_child2.getComputedTop(), "50 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); + console.assert(50 === root_child2.getComputedHeight(), "50 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + + console.assert(0 === root_child3.getComputedLeft(), "0 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(100 === root_child3.getComputedTop(), "100 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); + console.assert(50 === root_child3.getComputedHeight(), "50 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); + + console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(0 === root_child4.getComputedTop(), "0 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); + console.assert(50 === root_child4.getComputedHeight(), "50 === root_child4.getComputedHeight() (" + root_child4.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(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(150 === root.getComputedHeight(), "150 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(50 === root_child0.getComputedLeft(), "50 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(50 === root_child0.getComputedHeight(), "50 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(0 === root_child0_child0.getComputedLeft(), "0 === 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(50 === root_child0_child0.getComputedWidth(), "50 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")"); + console.assert(50 === root_child0_child0.getComputedHeight(), "50 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")"); + + console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(50 === root_child1.getComputedTop(), "50 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(0 === root_child1.getComputedHeight(), "0 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + console.assert(50 === root_child2.getComputedLeft(), "50 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(50 === root_child2.getComputedTop(), "50 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); + console.assert(50 === root_child2.getComputedHeight(), "50 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + + console.assert(50 === root_child3.getComputedLeft(), "50 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(100 === root_child3.getComputedTop(), "100 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); + console.assert(50 === root_child3.getComputedHeight(), "50 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); + + console.assert(0 === root_child4.getComputedLeft(), "0 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(0 === root_child4.getComputedTop(), "0 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); + console.assert(50 === root_child4.getComputedHeight(), "50 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); + + if (typeof root !== "undefined") + root.freeRecursive(); + + (typeof gc !== "undefined") && gc(); + console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); +}); diff --git a/tests/YGAlignContentTest.cpp b/tests/YGAlignContentTest.cpp index 2061af12..d6dac67a 100644 --- a/tests/YGAlignContentTest.cpp +++ b/tests/YGAlignContentTest.cpp @@ -110,17 +110,14 @@ TEST(YogaTest, align_content_flex_start) { YGNodeFreeRecursive(root); } -TEST(YogaTest, align_content_flex_end) { +TEST(YogaTest, align_content_flex_start_without_height_on_children) { const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root, YGAlignFlexEnd); YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 130); + YGNodeStyleSetWidth(root, 100); YGNodeStyleSetHeight(root, 100); const YGNodeRef root_child0 = YGNodeNew(); YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 10); YGNodeInsertChild(root, root_child0, 0); const YGNodeRef root_child1 = YGNodeNew(); @@ -130,7 +127,6 @@ TEST(YogaTest, align_content_flex_end) { const YGNodeRef root_child2 = YGNodeNew(); YGNodeStyleSetWidth(root_child2, 50); - YGNodeStyleSetHeight(root_child2, 10); YGNodeInsertChild(root, root_child2, 2); const YGNodeRef root_child3 = YGNodeNew(); @@ -140,81 +136,179 @@ TEST(YogaTest, align_content_flex_end) { const YGNodeRef root_child4 = YGNodeNew(); YGNodeStyleSetWidth(root_child4, 50); - YGNodeStyleSetHeight(root_child4, 10); YGNodeInsertChild(root, root_child4, 4); YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(130, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(70, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(70, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child2)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child3)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child4)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child4)); YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(130, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(70, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(70, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child2)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child2)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child3)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child4)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child4)); YGNodeFreeRecursive(root); } -TEST(YogaTest, align_content_center) { +TEST(YogaTest, align_content_flex_start_with_flex) { const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root, YGAlignCenter); YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 130); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 120); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeStyleSetFlexBasisPercent(root_child0, 0); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child1, 1); + YGNodeStyleSetFlexBasisPercent(root_child1, 0); + YGNodeStyleSetWidth(root_child1, 50); + YGNodeStyleSetHeight(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 50); + YGNodeInsertChild(root, root_child2, 2); + + const YGNodeRef root_child3 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child3, 1); + YGNodeStyleSetFlexShrink(root_child3, 1); + YGNodeStyleSetFlexBasisPercent(root_child3, 0); + YGNodeStyleSetWidth(root_child3, 50); + YGNodeInsertChild(root, root_child3, 3); + + const YGNodeRef root_child4 = YGNodeNew(); + YGNodeStyleSetWidth(root_child4, 50); + YGNodeInsertChild(root, root_child4, 4); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(120, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(120, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child4)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(120, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(120, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child4)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, align_content_flex_end) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignContent(root, YGAlignFlexEnd); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + YGNodeStyleSetWidth(root, 100); YGNodeStyleSetHeight(root, 100); const YGNodeRef root_child0 = YGNodeNew(); @@ -245,31 +339,31 @@ TEST(YogaTest, align_content_center) { ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(130, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(35, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(35, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(45, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child2)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(45, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child3)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(55, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child4)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); @@ -277,31 +371,31 @@ TEST(YogaTest, align_content_center) { ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(130, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(35, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(35, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(45, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child2)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(45, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child3)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(55, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child4)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); @@ -598,3 +692,1059 @@ TEST(YogaTest, align_content_spacearound) { YGNodeFreeRecursive(root); } + +TEST(YogaTest, align_content_stretch_row) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetAlignContent(root, YGAlignStretch); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + YGNodeStyleSetWidth(root, 150); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetWidth(root_child1, 50); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 50); + YGNodeInsertChild(root, root_child2, 2); + + const YGNodeRef root_child3 = YGNodeNew(); + YGNodeStyleSetWidth(root_child3, 50); + YGNodeInsertChild(root, root_child3, 3); + + const YGNodeRef root_child4 = YGNodeNew(); + YGNodeStyleSetWidth(root_child4, 50); + YGNodeInsertChild(root, root_child4, 4); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, align_content_stretch_row_with_children) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetAlignContent(root, YGAlignStretch); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + YGNodeStyleSetWidth(root, 150); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child0_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0_child0, 1); + YGNodeStyleSetFlexShrink(root_child0_child0, 1); + YGNodeStyleSetFlexBasisPercent(root_child0_child0, 0); + YGNodeInsertChild(root_child0, root_child0_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetWidth(root_child1, 50); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 50); + YGNodeInsertChild(root, root_child2, 2); + + const YGNodeRef root_child3 = YGNodeNew(); + YGNodeStyleSetWidth(root_child3, 50); + YGNodeInsertChild(root, root_child3, 3); + + const YGNodeRef root_child4 = YGNodeNew(); + YGNodeStyleSetWidth(root_child4, 50); + YGNodeInsertChild(root, root_child4, 4); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, align_content_stretch_row_with_flex) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetAlignContent(root, YGAlignStretch); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + YGNodeStyleSetWidth(root, 150); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child1, 1); + YGNodeStyleSetFlexShrink(root_child1, 1); + YGNodeStyleSetFlexBasisPercent(root_child1, 0); + YGNodeStyleSetWidth(root_child1, 50); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 50); + YGNodeInsertChild(root, root_child2, 2); + + const YGNodeRef root_child3 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child3, 1); + YGNodeStyleSetFlexShrink(root_child3, 1); + YGNodeStyleSetFlexBasisPercent(root_child3, 0); + YGNodeStyleSetWidth(root_child3, 50); + YGNodeInsertChild(root, root_child3, 3); + + const YGNodeRef root_child4 = YGNodeNew(); + YGNodeStyleSetWidth(root_child4, 50); + YGNodeInsertChild(root, root_child4, 4); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child4)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child4)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, align_content_stretch_row_with_flex_no_shrink) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetAlignContent(root, YGAlignStretch); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + YGNodeStyleSetWidth(root, 150); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child1, 1); + YGNodeStyleSetFlexShrink(root_child1, 1); + YGNodeStyleSetFlexBasisPercent(root_child1, 0); + YGNodeStyleSetWidth(root_child1, 50); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 50); + YGNodeInsertChild(root, root_child2, 2); + + const YGNodeRef root_child3 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child3, 1); + YGNodeStyleSetFlexBasisPercent(root_child3, 0); + YGNodeStyleSetWidth(root_child3, 50); + YGNodeInsertChild(root, root_child3, 3); + + const YGNodeRef root_child4 = YGNodeNew(); + YGNodeStyleSetWidth(root_child4, 50); + YGNodeInsertChild(root, root_child4, 4); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child4)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child4)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, align_content_stretch_row_with_margin) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetAlignContent(root, YGAlignStretch); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + YGNodeStyleSetWidth(root, 150); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetMargin(root_child1, YGEdgeLeft, 10); + YGNodeStyleSetMargin(root_child1, YGEdgeTop, 10); + YGNodeStyleSetMargin(root_child1, YGEdgeRight, 10); + YGNodeStyleSetMargin(root_child1, YGEdgeBottom, 10); + YGNodeStyleSetWidth(root_child1, 50); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 50); + YGNodeInsertChild(root, root_child2, 2); + + const YGNodeRef root_child3 = YGNodeNew(); + YGNodeStyleSetMargin(root_child3, YGEdgeLeft, 10); + YGNodeStyleSetMargin(root_child3, YGEdgeTop, 10); + YGNodeStyleSetMargin(root_child3, YGEdgeRight, 10); + YGNodeStyleSetMargin(root_child3, YGEdgeBottom, 10); + YGNodeStyleSetWidth(root_child3, 50); + YGNodeInsertChild(root, root_child3, 3); + + const YGNodeRef root_child4 = YGNodeNew(); + YGNodeStyleSetWidth(root_child4, 50); + YGNodeInsertChild(root, root_child4, 4); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child4)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child4)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, align_content_stretch_row_with_padding) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetAlignContent(root, YGAlignStretch); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + YGNodeStyleSetWidth(root, 150); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetPadding(root_child1, YGEdgeLeft, 10); + YGNodeStyleSetPadding(root_child1, YGEdgeTop, 10); + YGNodeStyleSetPadding(root_child1, YGEdgeRight, 10); + YGNodeStyleSetPadding(root_child1, YGEdgeBottom, 10); + YGNodeStyleSetWidth(root_child1, 50); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 50); + YGNodeInsertChild(root, root_child2, 2); + + const YGNodeRef root_child3 = YGNodeNew(); + YGNodeStyleSetPadding(root_child3, YGEdgeLeft, 10); + YGNodeStyleSetPadding(root_child3, YGEdgeTop, 10); + YGNodeStyleSetPadding(root_child3, YGEdgeRight, 10); + YGNodeStyleSetPadding(root_child3, YGEdgeBottom, 10); + YGNodeStyleSetWidth(root_child3, 50); + YGNodeInsertChild(root, root_child3, 3); + + const YGNodeRef root_child4 = YGNodeNew(); + YGNodeStyleSetWidth(root_child4, 50); + YGNodeInsertChild(root, root_child4, 4); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, align_content_stretch_row_with_single_row) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetAlignContent(root, YGAlignStretch); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + YGNodeStyleSetWidth(root, 150); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetWidth(root_child1, 50); + YGNodeInsertChild(root, root_child1, 1); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, align_content_stretch_row_with_fixed_height) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetAlignContent(root, YGAlignStretch); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + YGNodeStyleSetWidth(root, 150); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetWidth(root_child1, 50); + YGNodeStyleSetHeight(root_child1, 60); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 50); + YGNodeInsertChild(root, root_child2, 2); + + const YGNodeRef root_child3 = YGNodeNew(); + YGNodeStyleSetWidth(root_child3, 50); + YGNodeInsertChild(root, root_child3, 3); + + const YGNodeRef root_child4 = YGNodeNew(); + YGNodeStyleSetWidth(root_child4, 50); + YGNodeInsertChild(root, root_child4, 4); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child4)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child4)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, align_content_stretch_row_with_max_height) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetAlignContent(root, YGAlignStretch); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + YGNodeStyleSetWidth(root, 150); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetWidth(root_child1, 50); + YGNodeStyleSetMaxHeight(root_child1, 20); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 50); + YGNodeInsertChild(root, root_child2, 2); + + const YGNodeRef root_child3 = YGNodeNew(); + YGNodeStyleSetWidth(root_child3, 50); + YGNodeInsertChild(root, root_child3, 3); + + const YGNodeRef root_child4 = YGNodeNew(); + YGNodeStyleSetWidth(root_child4, 50); + YGNodeInsertChild(root, root_child4, 4); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, align_content_stretch_row_with_min_height) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetAlignContent(root, YGAlignStretch); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + YGNodeStyleSetWidth(root, 150); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetWidth(root_child1, 50); + YGNodeStyleSetMinHeight(root_child1, 80); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 50); + YGNodeInsertChild(root, root_child2, 2); + + const YGNodeRef root_child3 = YGNodeNew(); + YGNodeStyleSetWidth(root_child3, 50); + YGNodeInsertChild(root, root_child3, 3); + + const YGNodeRef root_child4 = YGNodeNew(); + YGNodeStyleSetWidth(root_child4, 50); + YGNodeInsertChild(root, root_child4, 4); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, align_content_stretch_column) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignContent(root, YGAlignStretch); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 150); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetHeight(root_child0, 50); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child0_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0_child0, 1); + YGNodeStyleSetFlexShrink(root_child0_child0, 1); + YGNodeStyleSetFlexBasisPercent(root_child0_child0, 0); + YGNodeInsertChild(root_child0, root_child0_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child1, 1); + YGNodeStyleSetFlexShrink(root_child1, 1); + YGNodeStyleSetFlexBasisPercent(root_child1, 0); + YGNodeStyleSetHeight(root_child1, 50); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetHeight(root_child2, 50); + YGNodeInsertChild(root, root_child2, 2); + + const YGNodeRef root_child3 = YGNodeNew(); + YGNodeStyleSetHeight(root_child3, 50); + YGNodeInsertChild(root, root_child3, 3); + + const YGNodeRef root_child4 = YGNodeNew(); + YGNodeStyleSetHeight(root_child4, 50); + YGNodeInsertChild(root, root_child4, 4); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(150, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(150, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); + + YGNodeFreeRecursive(root); +} diff --git a/yoga/Yoga.c b/yoga/Yoga.c index e8d5c31e..771a8a17 100644 --- a/yoga/Yoga.c +++ b/yoga/Yoga.c @@ -2485,10 +2485,23 @@ static void YGNodelayoutImpl(const YGNodeRef node, // the spacing. mainDim += betweenMainDim + YGNodeDimWithMargin(child, mainAxis, availableInnerWidth); - // The cross dimension is the max of the elements dimension since - // there - // can only be one element in that cross dimension. - crossDim = fmaxf(crossDim, YGNodeDimWithMargin(child, crossAxis, availableInnerWidth)); + if (YGNodeIsStyleDimDefined(child, crossAxis, availableInnerCrossDim) || + child->measure != NULL || + !isNodeFlexWrap) { + // The cross dimension is the max of the elements dimension since + // there + // can only be one element in that cross dimension. + crossDim = + fmaxf(crossDim, YGNodeDimWithMargin(child, crossAxis, availableInnerWidth)); + } else { + // If we wrap the lines we only take the space we need at least. + crossDim = fmaxf( + crossDim, + YGNodeMarginForAxis(child, crossAxis, availableInnerWidth) + + fmaxf(YGValueResolve(&child->style.minDimensions[dim[crossAxis]], + availableInnerWidth), + YGNodePaddingAndBorderForAxis(child, crossAxis, availableInnerWidth))); + } } } else if (performLayout) { child->layout.position[pos[mainAxis]] += @@ -2652,7 +2665,8 @@ static void YGNodelayoutImpl(const YGNodeRef node, } // STEP 8: MULTI-LINE CONTENT ALIGNMENT - if (performLayout && (lineCount > 1 || YGIsBaselineLayout(node)) && + if (performLayout && + (lineCount > 1 || node->style.alignContent == YGAlignStretch || YGIsBaselineLayout(node)) && !YGFloatIsUndefined(availableInnerCrossDim)) { const float remainingAlignContentDim = availableInnerCrossDim - totalLineCrossDim; @@ -2760,8 +2774,36 @@ static void YGNodelayoutImpl(const YGNodeRef node, case YGAlignStretch: { child->layout.position[pos[crossAxis]] = currentLead + YGNodeLeadingMargin(child, crossAxis, availableInnerWidth); - // TODO(prenaux): Correctly set the height of items with indefinite - // (auto) crossAxis dimension. + + // Remeasure child with the line height as it as been only measured with the + // parents height yet. + if (!YGNodeIsStyleDimDefined(child, crossAxis, availableInnerCrossDim)) { + const float childWidth = + isMainAxisRow ? (child->layout.measuredDimensions[YGDimensionWidth] + + YGNodeMarginForAxis(child, crossAxis, availableInnerWidth)) + : lineHeight; + + const float childHeight = + !isMainAxisRow ? (child->layout.measuredDimensions[YGDimensionHeight] + + YGNodeMarginForAxis(child, crossAxis, availableInnerWidth)) + : lineHeight; + + if (!(YGFloatsEqual(childWidth, + child->layout.measuredDimensions[YGDimensionWidth]) && + YGFloatsEqual(childHeight, + child->layout.measuredDimensions[YGDimensionHeight]))) { + YGLayoutNodeInternal(child, + childWidth, + childHeight, + direction, + YGMeasureModeExactly, + YGMeasureModeExactly, + availableInnerWidth, + availableInnerHeight, + true, + "stretch"); + } + } break; } case YGAlignBaseline: { From 4f6924a0c174bc4ebb5b2333d48de63d195a2da4 Mon Sep 17 00:00:00 2001 From: Dustin Shahidehpour Date: Sat, 11 Feb 2017 11:16:14 -0800 Subject: [PATCH 10/20] BREAKING CHANGE: rename applyLayout to applyLayoutPreservingOrigin. Summary: Will update on Monday Reviewed By: emilsjolander Differential Revision: D4545786 fbshipit-source-id: f8189d82f1c64cd1eac532fd2dfaa9aea35d6004 --- YogaKit/CHANGELOG.md | 23 ++++ YogaKit/Source/YGLayout.h | 5 +- YogaKit/Source/YGLayout.m | 8 +- YogaKit/Tests/YogaKitTests.m | 111 ++++++++---------- YogaKit/YogaKitSample/Podfile.lock | 10 +- .../YogaKitSample/SwiftViewController.swift | 2 +- .../YogaKitSample/ViewController.m | 6 +- docs/_docs/api/yogakit.md | 2 +- 8 files changed, 91 insertions(+), 76 deletions(-) create mode 100644 YogaKit/CHANGELOG.md diff --git a/YogaKit/CHANGELOG.md b/YogaKit/CHANGELOG.md new file mode 100644 index 00000000..6a7dda86 --- /dev/null +++ b/YogaKit/CHANGELOG.md @@ -0,0 +1,23 @@ +# CHANGELOG + +The changelog for `YogaKit`. + +1.2.0 (**upcoming release**) +----- + +### Breaking Changes + +- `applyLayout()` has now been changed to `applyLayout(preservingOrigin:)`. + +- Computed properties are no longer reflected in getter's of the affected properties. +```swift +// OLD +view.yoga.margin = 10 +view.yoga.marginTop // 10 +view.yoga.marginLeft // 10 + +// NEW +view.yoga.margin = 10 +view.yoga.marginTop // 0 +view.yoga.marginLeft // 0 +``` diff --git a/YogaKit/Source/YGLayout.h b/YogaKit/Source/YGLayout.h index 83dbf36b..e9f49b12 100644 --- a/YogaKit/Source/YGLayout.h +++ b/YogaKit/Source/YGLayout.h @@ -89,9 +89,10 @@ @property (nonatomic, readonly, assign) YGDirection resolvedDirection; /** - Perform a layout calculation and update the frames of the views in the hierarchy with the results + Perform a layout calculation and update the frames of the views in the hierarchy with the results. + If the origin is not preserved, the root view's layout results will applied from {0,0}. */ -- (void)applyLayout NS_SWIFT_NAME(applyLayout()); +- (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin NS_SWIFT_NAME(applyLayout(preservingOrigin:)); /** Returns the size of the view if no constraints were given. This could equivalent to calling [self diff --git a/YogaKit/Source/YGLayout.m b/YogaKit/Source/YGLayout.m index 3e7516c7..07c0a77d 100644 --- a/YogaKit/Source/YGLayout.m +++ b/YogaKit/Source/YGLayout.m @@ -208,7 +208,13 @@ YG_PROPERTY(CGFloat, aspectRatio, AspectRatio) - (void)applyLayout { [self calculateLayoutWithSize:self.view.bounds.size]; - YGApplyLayoutToViewHierarchy(self.view, YES); + YGApplyLayoutToViewHierarchy(self.view, NO); +} + +- (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin +{ + [self calculateLayoutWithSize:self.view.bounds.size]; + YGApplyLayoutToViewHierarchy(self.view, preserveOrigin); } - (CGSize)intrinsicSize diff --git a/YogaKit/Tests/YogaKitTests.m b/YogaKit/Tests/YogaKitTests.m index 5342f9c3..dcb089e8 100644 --- a/YogaKit/Tests/YogaKitTests.m +++ b/YogaKit/Tests/YogaKitTests.m @@ -109,6 +109,31 @@ XCTAssertEqual(longTextLabelSize.width + textBadgeView.yoga.intrinsicSize.width, containerSize.width); } +- (void)testPreservingOrigin +{ + UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0,0,50,75)]; + container.yoga.isEnabled = YES; + + UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; + view.yoga.isEnabled = YES; + view.yoga.flexBasis = 0; + view.yoga.flexGrow = 1; + [container addSubview:view]; + + UIView *view2 = [[UIView alloc] initWithFrame:CGRectZero]; + view2.yoga.isEnabled = YES; + view2.yoga.marginTop = 25; + view2.yoga.flexBasis = 0; + view2.yoga.flexGrow = 1; + [container addSubview:view2]; + + [container.yoga applyLayoutPreservingOrigin:YES]; + XCTAssertEqual(50, view2.frame.origin.y); + + [view2.yoga applyLayoutPreservingOrigin:NO]; + XCTAssertEqual(25, view2.frame.origin.y); +} + - (void)testThatMarkingLeafsAsDirtyWillTriggerASizeRecalculation { UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 50)]; @@ -116,22 +141,22 @@ container.yoga.flexDirection = YGFlexDirectionRow; container.yoga.alignItems = YGAlignFlexStart; - UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero]; - label.text = @"This is a short text."; - label.numberOfLines = 1; - label.yoga.isEnabled = YES; - [container addSubview:label]; + UILabel *view = [[UILabel alloc] initWithFrame:CGRectZero]; + view.text = @"This is a short text."; + view.numberOfLines = 1; + view.yoga.isEnabled = YES; + [container addSubview:view]; - [container.yoga applyLayout]; - CGSize const labelSizeAfterFirstPass = label.frame.size; + [container.yoga applyLayoutPreservingOrigin:YES]; + CGSize const viewSizeAfterFirstPass = view.frame.size; - label.text = @"This is a slightly longer text."; - XCTAssertTrue(CGSizeEqualToSize(label.frame.size, labelSizeAfterFirstPass)); + view.text = @"This is a slightly longer text."; + XCTAssertTrue(CGSizeEqualToSize(view.frame.size, viewSizeAfterFirstPass)); - [label.yoga markDirty]; + [view.yoga markDirty]; - [container.yoga applyLayout]; - XCTAssertFalse(CGSizeEqualToSize(label.frame.size, labelSizeAfterFirstPass)); + [container.yoga applyLayoutPreservingOrigin:YES]; + XCTAssertFalse(CGSizeEqualToSize(view.frame.size, viewSizeAfterFirstPass)); } - (void)testFrameAndOriginPlacement @@ -157,7 +182,7 @@ subview3.yoga.flexGrow = 1; [container addSubview:subview3]; - [container.yoga applyLayout]; + [container.yoga applyLayoutPreservingOrigin:YES]; XCTAssertEqualWithAccuracy(subview2.frame.origin.x, CGRectGetMaxX(subview1.frame), FLT_EPSILON); XCTAssertEqualWithAccuracy(subview3.frame.origin.x, CGRectGetMaxX(subview2.frame), FLT_EPSILON); @@ -193,7 +218,7 @@ subview3.yoga.flexGrow = 1; [container addSubview:subview3]; - [container.yoga applyLayout]; + [container.yoga applyLayoutPreservingOrigin:YES]; XCTAssertTrue(CGRectEqualToRect(subview1.frame, CGRectMake(0, 0, 100, 50))); XCTAssertTrue(CGRectEqualToRect(subview2.frame, CGRectMake(100, 0, 100, 50))); @@ -201,7 +226,7 @@ [container exchangeSubviewAtIndex:2 withSubviewAtIndex:0]; subview2.yoga.isIncludedInLayout = NO; - [container.yoga applyLayout]; + [container.yoga applyLayoutPreservingOrigin:YES]; XCTAssertTrue(CGRectEqualToRect(subview3.frame, CGRectMake(0, 0, 150, 50))); XCTAssertTrue(CGRectEqualToRect(subview1.frame, CGRectMake(150, 0, 150, 50))); @@ -233,14 +258,14 @@ subview3.yoga.flexGrow = 1; [container addSubview:subview3]; - [container.yoga applyLayout]; + [container.yoga applyLayoutPreservingOrigin:YES]; for (UIView *subview in container.subviews) { XCTAssertEqual(subview.bounds.size.width, 100); } subview3.yoga.isIncludedInLayout = NO; - [container.yoga applyLayout]; + [container.yoga applyLayoutPreservingOrigin:YES]; XCTAssertEqual(subview1.bounds.size.width, 150); XCTAssertEqual(subview2.bounds.size.width, 150); @@ -270,11 +295,11 @@ subview3.yoga.isIncludedInLayout = YES; [container addSubview:subview3]; - [container.yoga applyLayout]; + [container.yoga applyLayoutPreservingOrigin:YES]; XCTAssertEqual(container.yoga.numberOfChildren, 1); subview2.yoga.isIncludedInLayout = YES; - [container.yoga applyLayout]; + [container.yoga applyLayoutPreservingOrigin:YES]; XCTAssertEqual(container.yoga.numberOfChildren, 2); } @@ -300,14 +325,14 @@ subview3.yoga.isIncludedInLayout = NO; [container addSubview:subview3]; - [container.yoga applyLayout]; + [container.yoga applyLayoutPreservingOrigin:YES]; XCTAssertEqual(subview1.bounds.size.width, 150); XCTAssertEqual(subview2.bounds.size.width, 150); XCTAssertEqual(subview3.bounds.size.width, 0); subview3.yoga.isIncludedInLayout = YES; - [container.yoga applyLayout]; + [container.yoga applyLayoutPreservingOrigin:YES]; XCTAssertEqual(subview1.bounds.size.width, 100); XCTAssertEqual(subview2.bounds.size.width, 100); @@ -361,7 +386,7 @@ someView.yoga.flexGrow = 1; [view addSubview:someView]; } - [container.yoga applyLayout]; + [container.yoga applyLayoutPreservingOrigin:YES]; // Add the same amount of new views, reapply layout. for (UIView *view in @[subview1, subview2]) { @@ -370,7 +395,7 @@ someView.yoga.flexGrow = 1; [view addSubview:someView]; } - [container.yoga applyLayout]; + [container.yoga applyLayoutPreservingOrigin:YES]; XCTAssertEqual(subview1.bounds.size.width, 100); XCTAssertEqual(subview1.bounds.size.height, 25); @@ -406,9 +431,9 @@ subview2.yoga.isEnabled = YES; [subview1 addSubview:subview2]; - [container.yoga applyLayout]; + [container.yoga applyLayoutPreservingOrigin:YES]; [subview2 removeFromSuperview]; - [container.yoga applyLayout]; + [container.yoga applyLayoutPreservingOrigin:YES]; } - (void)testPositionalPropertiesWork @@ -594,40 +619,4 @@ XCTAssertEqual(view.yoga.borderEndWidth, 7); } -- (void)testOriginIsPreservedOnRootOfLayout -{ - const CGSize containerSize = CGSizeMake(200, 50); - - UIView *container = [[UIView alloc] initWithFrame:CGRectMake(10, 10, containerSize.width, containerSize.height)]; - container.yoga.isEnabled = YES; - container.yoga.flexDirection = YGFlexDirectionRow; - - UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero]; - subview1.yoga.isEnabled = YES; - subview1.yoga.flexGrow = 1; - [container addSubview:subview1]; - - UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero]; - subview2.yoga.isEnabled = YES; - subview2.yoga.flexGrow = 1; - subview2.yoga.flexDirection = YGFlexDirectionColumn; - subview2.yoga.marginLeft = 10; - [container addSubview:subview2]; - [container.yoga applyLayout]; - - XCTAssertTrue(CGRectEqualToRect(container.frame, CGRectMake(10, 10, 200, 50))); - XCTAssertTrue(CGRectEqualToRect(subview1.frame, CGRectMake(0, 0, 95, 50))); - XCTAssertTrue(CGRectEqualToRect(subview2.frame, CGRectMake(105, 0, 95, 50))); - - UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero]; - subview3.yoga.isEnabled = YES; - subview3.yoga.alignSelf = YGAlignFlexEnd; - subview3.yoga.height = 50; - [subview2 addSubview:subview3]; - [subview2.yoga applyLayout]; - - XCTAssertTrue(CGRectEqualToRect(subview2.frame, CGRectMake(115, 0, 85, 50))); - XCTAssertTrue(CGRectEqualToRect(subview3.frame, CGRectMake(85,0,0,50))); -} - @end diff --git a/YogaKit/YogaKitSample/Podfile.lock b/YogaKit/YogaKitSample/Podfile.lock index f2dad1e0..031125d4 100644 --- a/YogaKit/YogaKitSample/Podfile.lock +++ b/YogaKit/YogaKitSample/Podfile.lock @@ -1,7 +1,7 @@ PODS: - - Yoga (1.0.2) - - YogaKit (1.0.3): - - Yoga (~> 1.0) + - Yoga (1.1.0) + - YogaKit (1.1.0): + - Yoga (~> 1.1) DEPENDENCIES: - YogaKit (from `../../YogaKit.podspec`) @@ -11,8 +11,8 @@ EXTERNAL SOURCES: :path: "../../YogaKit.podspec" SPEC CHECKSUMS: - Yoga: ef42f88b9bcbd7daf7267c0f19d8636ce3a50618 - YogaKit: 6d9826a015c029b13731a33bf96fe6c1e33748a6 + Yoga: 0bf083b7c485b20598020dbedcea869cbe53071e + YogaKit: 80df90de9ef2900baa111f2c93476a6f9e921385 PODFILE CHECKSUM: 9db3bdea7f1b4b715ad859a449b2dc87fb6226cc diff --git a/YogaKit/YogaKitSample/YogaKitSample/SwiftViewController.swift b/YogaKit/YogaKitSample/YogaKitSample/SwiftViewController.swift index f305a7e4..66a90199 100644 --- a/YogaKit/YogaKitSample/YogaKitSample/SwiftViewController.swift +++ b/YogaKit/YogaKitSample/YogaKitSample/SwiftViewController.swift @@ -36,6 +36,6 @@ class SwiftViewController: UIViewController { child2.addSubview(child3) root.addSubview(child1) root.addSubview(child2) - root.yoga.applyLayout() + root.yoga.applyLayout(preservingOrigin: false) } } diff --git a/YogaKit/YogaKitSample/YogaKitSample/ViewController.m b/YogaKit/YogaKitSample/YogaKitSample/ViewController.m index 4184345f..102ef144 100644 --- a/YogaKit/YogaKitSample/YogaKitSample/ViewController.m +++ b/YogaKit/YogaKitSample/YogaKitSample/ViewController.m @@ -10,10 +10,6 @@ #import -@interface ViewController () - -@end - @implementation ViewController - (void)viewDidLoad @@ -53,7 +49,7 @@ [child2 addSubview:child3]; [root addSubview:child1]; [root addSubview:child2]; - [root.yoga applyLayout]; + [root.yoga applyLayoutPreservingOrigin:NO]; } diff --git a/docs/_docs/api/yogakit.md b/docs/_docs/api/yogakit.md index 9ba7b4bf..796de28a 100644 --- a/docs/_docs/api/yogakit.md +++ b/docs/_docs/api/yogakit.md @@ -22,6 +22,6 @@ Yoga relies on `UIView` subviews to build up its internal layout tree. However, It is also possible to query the number of children **included** in layout via `numberOfChildren`. ### Layout -To apply a layout to a view (and its' subviews) you need to call `[view.yoga applyLayout]`. This will do a layout calculation (if needed) and apply the calculated frames to every view included in the layout. +To apply a layout to a view (and its' subviews) you need to call `[view.yoga applyLayoutPreservingOrigin:NO]`. This will do a layout calculation (if needed) and apply the calculated frames to every view included in the layout. In the event that you need to another layout pass on a view you can mark it dirty via `[view.yoga markDirty]`. From 15309d2bdd676fac9e37b1e8bbb30e382a270120 Mon Sep 17 00:00:00 2001 From: Dustin Shahidehpour Date: Sat, 11 Feb 2017 14:09:55 -0800 Subject: [PATCH 11/20] Update README.md Summary: Closes https://github.com/facebook/yoga/pull/389 Differential Revision: D4549243 Pulled By: dshahidehpour fbshipit-source-id: 2c8d6d78af9f98994ad2f5f028494ae743c354b4 --- YogaKit/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/YogaKit/README.md b/YogaKit/README.md index 70a957da..a4d18954 100644 --- a/YogaKit/README.md +++ b/YogaKit/README.md @@ -8,7 +8,7 @@ YogaKit is available to install via [CocoaPods](https://cocoapods.org/). ``` -pod 'YogaKit', '~> 1.0.2' +pod 'YogaKit', '~> 1.1' ``` ## Getting Started From 76fbd628e1878b3d63678c3e7f2d443f56e8987c Mon Sep 17 00:00:00 2001 From: Dustin Shahidehpour Date: Sat, 11 Feb 2017 19:45:35 -0800 Subject: [PATCH 12/20] Use correct rounding function when rounding pixels. Summary: While debugging something at Instagram, I kept seeing a UILabel be truncated when it clearly had enough room to display all its' text. What I realized is that during our pixel rounding, we were losing precision because we were using the incorrect rounding function for floats. Changing from `round()` (which is for doubles) to `roundf()` fixed it. Reviewed By: amonshiz Differential Revision: D4549069 fbshipit-source-id: 78a1bb33e315e7c066b7fb625b1f5a28def76515 --- YogaKit/CHANGELOG.md | 4 ++++ YogaKit/Source/YGLayout.m | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/YogaKit/CHANGELOG.md b/YogaKit/CHANGELOG.md index 6a7dda86..49c46f2f 100644 --- a/YogaKit/CHANGELOG.md +++ b/YogaKit/CHANGELOG.md @@ -21,3 +21,7 @@ view.yoga.margin = 10 view.yoga.marginTop // 0 view.yoga.marginLeft // 0 ``` + +### Enhancements + +- Pixel Rounding now uses `roundf()` instead of `round()`. diff --git a/YogaKit/Source/YGLayout.m b/YogaKit/Source/YGLayout.m index 07c0a77d..d7240a8b 100644 --- a/YogaKit/Source/YGLayout.m +++ b/YogaKit/Source/YGLayout.m @@ -353,7 +353,7 @@ static CGFloat YGRoundPixelValue(CGFloat value) scale = [UIScreen mainScreen].scale; }); - return round(value * scale) / scale; + return roundf(value * scale) / scale; } static void YGApplyLayoutToViewHierarchy(UIView *view, BOOL preserveOrigin) From 0d2749a3fd3a449185fdce98238a5289956d5873 Mon Sep 17 00:00:00 2001 From: Emil Sjolander Date: Mon, 13 Feb 2017 01:05:23 -0800 Subject: [PATCH 13/20] Revert D4528559: [yoga][PR] Fix align-content strech with multiple lines Summary: This reverts commit 019e6f85fa452d0c3412f711e3886f0c4452da47 Differential Revision: D4528559 fbshipit-source-id: 4bd82b399cb36acb348f2c6fedcae6b360513424 --- .../tests/Facebook.Yoga/YGAlignContentTest.cs | 1414 ++-------------- gentest/fixtures/YGAlignContentTest.html | 107 +- .../com/facebook/yoga/YGAlignContentTest.java | 1400 ++-------------- .../tests/Facebook.Yoga/YGAlignContentTest.js | 1428 ++--------------- tests/YGAlignContentTest.cpp | 1386 ++-------------- yoga/Yoga.c | 56 +- 6 files changed, 490 insertions(+), 5301 deletions(-) diff --git a/csharp/tests/Facebook.Yoga/YGAlignContentTest.cs b/csharp/tests/Facebook.Yoga/YGAlignContentTest.cs index 0d173c1c..c73d6761 100644 --- a/csharp/tests/Facebook.Yoga/YGAlignContentTest.cs +++ b/csharp/tests/Facebook.Yoga/YGAlignContentTest.cs @@ -117,211 +117,14 @@ namespace Facebook.Yoga Assert.AreEqual(10f, root_child4.LayoutHeight); } - [Test] - public void Test_align_content_flex_start_without_height_on_children() - { - YogaNode root = new YogaNode(); - root.Wrap = YogaWrap.Wrap; - root.Width = 100; - root.Height = 100; - - YogaNode root_child0 = new YogaNode(); - root_child0.Width = 50; - root.Insert(0, root_child0); - - YogaNode root_child1 = new YogaNode(); - root_child1.Width = 50; - root_child1.Height = 10; - root.Insert(1, root_child1); - - YogaNode root_child2 = new YogaNode(); - root_child2.Width = 50; - root.Insert(2, root_child2); - - YogaNode root_child3 = new YogaNode(); - root_child3.Width = 50; - root_child3.Height = 10; - root.Insert(3, root_child3); - - YogaNode root_child4 = new YogaNode(); - root_child4.Width = 50; - root.Insert(4, root_child4); - root.StyleDirection = YogaDirection.LTR; - root.CalculateLayout(); - - Assert.AreEqual(0f, root.LayoutX); - Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(100f, root.LayoutWidth); - Assert.AreEqual(100f, root.LayoutHeight); - - Assert.AreEqual(0f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); - Assert.AreEqual(50f, root_child0.LayoutWidth); - Assert.AreEqual(0f, root_child0.LayoutHeight); - - Assert.AreEqual(0f, root_child1.LayoutX); - Assert.AreEqual(0f, root_child1.LayoutY); - Assert.AreEqual(50f, root_child1.LayoutWidth); - Assert.AreEqual(10f, root_child1.LayoutHeight); - - Assert.AreEqual(0f, root_child2.LayoutX); - Assert.AreEqual(10f, root_child2.LayoutY); - Assert.AreEqual(50f, root_child2.LayoutWidth); - Assert.AreEqual(0f, root_child2.LayoutHeight); - - Assert.AreEqual(0f, root_child3.LayoutX); - Assert.AreEqual(10f, root_child3.LayoutY); - Assert.AreEqual(50f, root_child3.LayoutWidth); - Assert.AreEqual(10f, root_child3.LayoutHeight); - - Assert.AreEqual(0f, root_child4.LayoutX); - Assert.AreEqual(20f, root_child4.LayoutY); - Assert.AreEqual(50f, root_child4.LayoutWidth); - Assert.AreEqual(0f, root_child4.LayoutHeight); - - root.StyleDirection = YogaDirection.RTL; - root.CalculateLayout(); - - Assert.AreEqual(0f, root.LayoutX); - Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(100f, root.LayoutWidth); - Assert.AreEqual(100f, root.LayoutHeight); - - Assert.AreEqual(50f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); - Assert.AreEqual(50f, root_child0.LayoutWidth); - Assert.AreEqual(0f, root_child0.LayoutHeight); - - Assert.AreEqual(50f, root_child1.LayoutX); - Assert.AreEqual(0f, root_child1.LayoutY); - Assert.AreEqual(50f, root_child1.LayoutWidth); - Assert.AreEqual(10f, root_child1.LayoutHeight); - - Assert.AreEqual(50f, root_child2.LayoutX); - Assert.AreEqual(10f, root_child2.LayoutY); - Assert.AreEqual(50f, root_child2.LayoutWidth); - Assert.AreEqual(0f, root_child2.LayoutHeight); - - Assert.AreEqual(50f, root_child3.LayoutX); - Assert.AreEqual(10f, root_child3.LayoutY); - Assert.AreEqual(50f, root_child3.LayoutWidth); - Assert.AreEqual(10f, root_child3.LayoutHeight); - - Assert.AreEqual(50f, root_child4.LayoutX); - Assert.AreEqual(20f, root_child4.LayoutY); - Assert.AreEqual(50f, root_child4.LayoutWidth); - Assert.AreEqual(0f, root_child4.LayoutHeight); - } - - [Test] - public void Test_align_content_flex_start_with_flex() - { - YogaNode root = new YogaNode(); - root.Wrap = YogaWrap.Wrap; - root.Width = 100; - root.Height = 120; - - YogaNode root_child0 = new YogaNode(); - root_child0.FlexGrow = 1; - root_child0.FlexBasis = 0.Percent(); - root_child0.Width = 50; - root.Insert(0, root_child0); - - YogaNode root_child1 = new YogaNode(); - root_child1.FlexGrow = 1; - root_child1.FlexBasis = 0.Percent(); - root_child1.Width = 50; - root_child1.Height = 10; - root.Insert(1, root_child1); - - YogaNode root_child2 = new YogaNode(); - root_child2.Width = 50; - root.Insert(2, root_child2); - - YogaNode root_child3 = new YogaNode(); - root_child3.FlexGrow = 1; - root_child3.FlexShrink = 1; - root_child3.FlexBasis = 0.Percent(); - root_child3.Width = 50; - root.Insert(3, root_child3); - - YogaNode root_child4 = new YogaNode(); - root_child4.Width = 50; - root.Insert(4, root_child4); - root.StyleDirection = YogaDirection.LTR; - root.CalculateLayout(); - - Assert.AreEqual(0f, root.LayoutX); - Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(100f, root.LayoutWidth); - Assert.AreEqual(120f, root.LayoutHeight); - - Assert.AreEqual(0f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); - Assert.AreEqual(50f, root_child0.LayoutWidth); - Assert.AreEqual(40f, root_child0.LayoutHeight); - - Assert.AreEqual(0f, root_child1.LayoutX); - Assert.AreEqual(40f, root_child1.LayoutY); - Assert.AreEqual(50f, root_child1.LayoutWidth); - Assert.AreEqual(40f, root_child1.LayoutHeight); - - Assert.AreEqual(0f, root_child2.LayoutX); - Assert.AreEqual(80f, root_child2.LayoutY); - Assert.AreEqual(50f, root_child2.LayoutWidth); - Assert.AreEqual(0f, root_child2.LayoutHeight); - - Assert.AreEqual(0f, root_child3.LayoutX); - Assert.AreEqual(80f, root_child3.LayoutY); - Assert.AreEqual(50f, root_child3.LayoutWidth); - Assert.AreEqual(40f, root_child3.LayoutHeight); - - Assert.AreEqual(0f, root_child4.LayoutX); - Assert.AreEqual(120f, root_child4.LayoutY); - Assert.AreEqual(50f, root_child4.LayoutWidth); - Assert.AreEqual(0f, root_child4.LayoutHeight); - - root.StyleDirection = YogaDirection.RTL; - root.CalculateLayout(); - - Assert.AreEqual(0f, root.LayoutX); - Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(100f, root.LayoutWidth); - Assert.AreEqual(120f, root.LayoutHeight); - - Assert.AreEqual(50f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); - Assert.AreEqual(50f, root_child0.LayoutWidth); - Assert.AreEqual(40f, root_child0.LayoutHeight); - - Assert.AreEqual(50f, root_child1.LayoutX); - Assert.AreEqual(40f, root_child1.LayoutY); - Assert.AreEqual(50f, root_child1.LayoutWidth); - Assert.AreEqual(40f, root_child1.LayoutHeight); - - Assert.AreEqual(50f, root_child2.LayoutX); - Assert.AreEqual(80f, root_child2.LayoutY); - Assert.AreEqual(50f, root_child2.LayoutWidth); - Assert.AreEqual(0f, root_child2.LayoutHeight); - - Assert.AreEqual(50f, root_child3.LayoutX); - Assert.AreEqual(80f, root_child3.LayoutY); - Assert.AreEqual(50f, root_child3.LayoutWidth); - Assert.AreEqual(40f, root_child3.LayoutHeight); - - Assert.AreEqual(50f, root_child4.LayoutX); - Assert.AreEqual(120f, root_child4.LayoutY); - Assert.AreEqual(50f, root_child4.LayoutWidth); - Assert.AreEqual(0f, root_child4.LayoutHeight); - } - [Test] public void Test_align_content_flex_end() { YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; root.AlignContent = YogaAlign.FlexEnd; root.Wrap = YogaWrap.Wrap; - root.Width = 100; + root.Width = 130; root.Height = 100; YogaNode root_child0 = new YogaNode(); @@ -353,31 +156,31 @@ namespace Facebook.Yoga Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(130f, root.LayoutWidth); Assert.AreEqual(100f, root.LayoutHeight); Assert.AreEqual(0f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(70f, root_child0.LayoutY); Assert.AreEqual(50f, root_child0.LayoutWidth); Assert.AreEqual(10f, root_child0.LayoutHeight); - Assert.AreEqual(0f, root_child1.LayoutX); - Assert.AreEqual(10f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(70f, root_child1.LayoutY); Assert.AreEqual(50f, root_child1.LayoutWidth); Assert.AreEqual(10f, root_child1.LayoutHeight); Assert.AreEqual(0f, root_child2.LayoutX); - Assert.AreEqual(20f, root_child2.LayoutY); + Assert.AreEqual(80f, root_child2.LayoutY); Assert.AreEqual(50f, root_child2.LayoutWidth); Assert.AreEqual(10f, root_child2.LayoutHeight); - Assert.AreEqual(0f, root_child3.LayoutX); - Assert.AreEqual(30f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutX); + Assert.AreEqual(80f, root_child3.LayoutY); Assert.AreEqual(50f, root_child3.LayoutWidth); Assert.AreEqual(10f, root_child3.LayoutHeight); Assert.AreEqual(0f, root_child4.LayoutX); - Assert.AreEqual(40f, root_child4.LayoutY); + Assert.AreEqual(90f, root_child4.LayoutY); Assert.AreEqual(50f, root_child4.LayoutWidth); Assert.AreEqual(10f, root_child4.LayoutHeight); @@ -386,31 +189,132 @@ namespace Facebook.Yoga Assert.AreEqual(0f, root.LayoutX); Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(130f, root.LayoutWidth); Assert.AreEqual(100f, root.LayoutHeight); - Assert.AreEqual(50f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(80f, root_child0.LayoutX); + Assert.AreEqual(70f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(30f, root_child1.LayoutX); + Assert.AreEqual(70f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(10f, root_child1.LayoutHeight); + + Assert.AreEqual(80f, root_child2.LayoutX); + Assert.AreEqual(80f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(10f, root_child2.LayoutHeight); + + Assert.AreEqual(30f, root_child3.LayoutX); + Assert.AreEqual(80f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(10f, root_child3.LayoutHeight); + + Assert.AreEqual(80f, root_child4.LayoutX); + Assert.AreEqual(90f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(10f, root_child4.LayoutHeight); + } + + [Test] + public void Test_align_content_center() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.AlignContent = YogaAlign.Center; + root.Wrap = YogaWrap.Wrap; + root.Width = 130; + root.Height = 100; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 50; + root_child0.Height = 10; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Width = 50; + root_child1.Height = 10; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 50; + root_child2.Height = 10; + root.Insert(2, root_child2); + + YogaNode root_child3 = new YogaNode(); + root_child3.Width = 50; + root_child3.Height = 10; + root.Insert(3, root_child3); + + YogaNode root_child4 = new YogaNode(); + root_child4.Width = 50; + root_child4.Height = 10; + root.Insert(4, root_child4); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(130f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(35f, root_child0.LayoutY); Assert.AreEqual(50f, root_child0.LayoutWidth); Assert.AreEqual(10f, root_child0.LayoutHeight); Assert.AreEqual(50f, root_child1.LayoutX); - Assert.AreEqual(10f, root_child1.LayoutY); + Assert.AreEqual(35f, root_child1.LayoutY); Assert.AreEqual(50f, root_child1.LayoutWidth); Assert.AreEqual(10f, root_child1.LayoutHeight); - Assert.AreEqual(50f, root_child2.LayoutX); - Assert.AreEqual(20f, root_child2.LayoutY); + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(45f, root_child2.LayoutY); Assert.AreEqual(50f, root_child2.LayoutWidth); Assert.AreEqual(10f, root_child2.LayoutHeight); Assert.AreEqual(50f, root_child3.LayoutX); - Assert.AreEqual(30f, root_child3.LayoutY); + Assert.AreEqual(45f, root_child3.LayoutY); Assert.AreEqual(50f, root_child3.LayoutWidth); Assert.AreEqual(10f, root_child3.LayoutHeight); - Assert.AreEqual(50f, root_child4.LayoutX); - Assert.AreEqual(40f, root_child4.LayoutY); + Assert.AreEqual(0f, root_child4.LayoutX); + Assert.AreEqual(55f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(10f, root_child4.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(130f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(80f, root_child0.LayoutX); + Assert.AreEqual(35f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(30f, root_child1.LayoutX); + Assert.AreEqual(35f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(10f, root_child1.LayoutHeight); + + Assert.AreEqual(80f, root_child2.LayoutX); + Assert.AreEqual(45f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(10f, root_child2.LayoutHeight); + + Assert.AreEqual(30f, root_child3.LayoutX); + Assert.AreEqual(45f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(10f, root_child3.LayoutHeight); + + Assert.AreEqual(80f, root_child4.LayoutX); + Assert.AreEqual(55f, root_child4.LayoutY); Assert.AreEqual(50f, root_child4.LayoutWidth); Assert.AreEqual(10f, root_child4.LayoutHeight); } @@ -712,1083 +616,5 @@ namespace Facebook.Yoga Assert.AreEqual(10f, root_child4.LayoutHeight); } - [Test] - public void Test_align_content_stretch_row() - { - YogaNode root = new YogaNode(); - root.FlexDirection = YogaFlexDirection.Row; - root.AlignContent = YogaAlign.Stretch; - root.Wrap = YogaWrap.Wrap; - root.Width = 150; - root.Height = 100; - - YogaNode root_child0 = new YogaNode(); - root_child0.Width = 50; - root.Insert(0, root_child0); - - YogaNode root_child1 = new YogaNode(); - root_child1.Width = 50; - root.Insert(1, root_child1); - - YogaNode root_child2 = new YogaNode(); - root_child2.Width = 50; - root.Insert(2, root_child2); - - YogaNode root_child3 = new YogaNode(); - root_child3.Width = 50; - root.Insert(3, root_child3); - - YogaNode root_child4 = new YogaNode(); - root_child4.Width = 50; - root.Insert(4, root_child4); - root.StyleDirection = YogaDirection.LTR; - root.CalculateLayout(); - - Assert.AreEqual(0f, root.LayoutX); - Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(150f, root.LayoutWidth); - Assert.AreEqual(100f, root.LayoutHeight); - - Assert.AreEqual(0f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); - Assert.AreEqual(50f, root_child0.LayoutWidth); - Assert.AreEqual(50f, root_child0.LayoutHeight); - - Assert.AreEqual(50f, root_child1.LayoutX); - Assert.AreEqual(0f, root_child1.LayoutY); - Assert.AreEqual(50f, root_child1.LayoutWidth); - Assert.AreEqual(50f, root_child1.LayoutHeight); - - Assert.AreEqual(100f, root_child2.LayoutX); - Assert.AreEqual(0f, root_child2.LayoutY); - Assert.AreEqual(50f, root_child2.LayoutWidth); - Assert.AreEqual(50f, root_child2.LayoutHeight); - - Assert.AreEqual(0f, root_child3.LayoutX); - Assert.AreEqual(50f, root_child3.LayoutY); - Assert.AreEqual(50f, root_child3.LayoutWidth); - Assert.AreEqual(50f, root_child3.LayoutHeight); - - Assert.AreEqual(50f, root_child4.LayoutX); - Assert.AreEqual(50f, root_child4.LayoutY); - Assert.AreEqual(50f, root_child4.LayoutWidth); - Assert.AreEqual(50f, root_child4.LayoutHeight); - - root.StyleDirection = YogaDirection.RTL; - root.CalculateLayout(); - - Assert.AreEqual(0f, root.LayoutX); - Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(150f, root.LayoutWidth); - Assert.AreEqual(100f, root.LayoutHeight); - - Assert.AreEqual(100f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); - Assert.AreEqual(50f, root_child0.LayoutWidth); - Assert.AreEqual(50f, root_child0.LayoutHeight); - - Assert.AreEqual(50f, root_child1.LayoutX); - Assert.AreEqual(0f, root_child1.LayoutY); - Assert.AreEqual(50f, root_child1.LayoutWidth); - Assert.AreEqual(50f, root_child1.LayoutHeight); - - Assert.AreEqual(0f, root_child2.LayoutX); - Assert.AreEqual(0f, root_child2.LayoutY); - Assert.AreEqual(50f, root_child2.LayoutWidth); - Assert.AreEqual(50f, root_child2.LayoutHeight); - - Assert.AreEqual(100f, root_child3.LayoutX); - Assert.AreEqual(50f, root_child3.LayoutY); - Assert.AreEqual(50f, root_child3.LayoutWidth); - Assert.AreEqual(50f, root_child3.LayoutHeight); - - Assert.AreEqual(50f, root_child4.LayoutX); - Assert.AreEqual(50f, root_child4.LayoutY); - Assert.AreEqual(50f, root_child4.LayoutWidth); - Assert.AreEqual(50f, root_child4.LayoutHeight); - } - - [Test] - public void Test_align_content_stretch_row_with_children() - { - YogaNode root = new YogaNode(); - root.FlexDirection = YogaFlexDirection.Row; - root.AlignContent = YogaAlign.Stretch; - root.Wrap = YogaWrap.Wrap; - root.Width = 150; - root.Height = 100; - - YogaNode root_child0 = new YogaNode(); - root_child0.Width = 50; - root.Insert(0, root_child0); - - YogaNode root_child0_child0 = new YogaNode(); - root_child0_child0.FlexGrow = 1; - root_child0_child0.FlexShrink = 1; - root_child0_child0.FlexBasis = 0.Percent(); - root_child0.Insert(0, root_child0_child0); - - YogaNode root_child1 = new YogaNode(); - root_child1.Width = 50; - root.Insert(1, root_child1); - - YogaNode root_child2 = new YogaNode(); - root_child2.Width = 50; - root.Insert(2, root_child2); - - YogaNode root_child3 = new YogaNode(); - root_child3.Width = 50; - root.Insert(3, root_child3); - - YogaNode root_child4 = new YogaNode(); - root_child4.Width = 50; - root.Insert(4, root_child4); - root.StyleDirection = YogaDirection.LTR; - root.CalculateLayout(); - - Assert.AreEqual(0f, root.LayoutX); - Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(150f, root.LayoutWidth); - Assert.AreEqual(100f, root.LayoutHeight); - - Assert.AreEqual(0f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); - Assert.AreEqual(50f, root_child0.LayoutWidth); - Assert.AreEqual(50f, root_child0.LayoutHeight); - - Assert.AreEqual(0f, root_child0_child0.LayoutX); - Assert.AreEqual(0f, root_child0_child0.LayoutY); - Assert.AreEqual(50f, root_child0_child0.LayoutWidth); - Assert.AreEqual(50f, root_child0_child0.LayoutHeight); - - Assert.AreEqual(50f, root_child1.LayoutX); - Assert.AreEqual(0f, root_child1.LayoutY); - Assert.AreEqual(50f, root_child1.LayoutWidth); - Assert.AreEqual(50f, root_child1.LayoutHeight); - - Assert.AreEqual(100f, root_child2.LayoutX); - Assert.AreEqual(0f, root_child2.LayoutY); - Assert.AreEqual(50f, root_child2.LayoutWidth); - Assert.AreEqual(50f, root_child2.LayoutHeight); - - Assert.AreEqual(0f, root_child3.LayoutX); - Assert.AreEqual(50f, root_child3.LayoutY); - Assert.AreEqual(50f, root_child3.LayoutWidth); - Assert.AreEqual(50f, root_child3.LayoutHeight); - - Assert.AreEqual(50f, root_child4.LayoutX); - Assert.AreEqual(50f, root_child4.LayoutY); - Assert.AreEqual(50f, root_child4.LayoutWidth); - Assert.AreEqual(50f, root_child4.LayoutHeight); - - root.StyleDirection = YogaDirection.RTL; - root.CalculateLayout(); - - Assert.AreEqual(0f, root.LayoutX); - Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(150f, root.LayoutWidth); - Assert.AreEqual(100f, root.LayoutHeight); - - Assert.AreEqual(100f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); - Assert.AreEqual(50f, root_child0.LayoutWidth); - Assert.AreEqual(50f, root_child0.LayoutHeight); - - Assert.AreEqual(0f, root_child0_child0.LayoutX); - Assert.AreEqual(0f, root_child0_child0.LayoutY); - Assert.AreEqual(50f, root_child0_child0.LayoutWidth); - Assert.AreEqual(50f, root_child0_child0.LayoutHeight); - - Assert.AreEqual(50f, root_child1.LayoutX); - Assert.AreEqual(0f, root_child1.LayoutY); - Assert.AreEqual(50f, root_child1.LayoutWidth); - Assert.AreEqual(50f, root_child1.LayoutHeight); - - Assert.AreEqual(0f, root_child2.LayoutX); - Assert.AreEqual(0f, root_child2.LayoutY); - Assert.AreEqual(50f, root_child2.LayoutWidth); - Assert.AreEqual(50f, root_child2.LayoutHeight); - - Assert.AreEqual(100f, root_child3.LayoutX); - Assert.AreEqual(50f, root_child3.LayoutY); - Assert.AreEqual(50f, root_child3.LayoutWidth); - Assert.AreEqual(50f, root_child3.LayoutHeight); - - Assert.AreEqual(50f, root_child4.LayoutX); - Assert.AreEqual(50f, root_child4.LayoutY); - Assert.AreEqual(50f, root_child4.LayoutWidth); - Assert.AreEqual(50f, root_child4.LayoutHeight); - } - - [Test] - public void Test_align_content_stretch_row_with_flex() - { - YogaNode root = new YogaNode(); - root.FlexDirection = YogaFlexDirection.Row; - root.AlignContent = YogaAlign.Stretch; - root.Wrap = YogaWrap.Wrap; - root.Width = 150; - root.Height = 100; - - YogaNode root_child0 = new YogaNode(); - root_child0.Width = 50; - root.Insert(0, root_child0); - - YogaNode root_child1 = new YogaNode(); - root_child1.FlexGrow = 1; - root_child1.FlexShrink = 1; - root_child1.FlexBasis = 0.Percent(); - root_child1.Width = 50; - root.Insert(1, root_child1); - - YogaNode root_child2 = new YogaNode(); - root_child2.Width = 50; - root.Insert(2, root_child2); - - YogaNode root_child3 = new YogaNode(); - root_child3.FlexGrow = 1; - root_child3.FlexShrink = 1; - root_child3.FlexBasis = 0.Percent(); - root_child3.Width = 50; - root.Insert(3, root_child3); - - YogaNode root_child4 = new YogaNode(); - root_child4.Width = 50; - root.Insert(4, root_child4); - root.StyleDirection = YogaDirection.LTR; - root.CalculateLayout(); - - Assert.AreEqual(0f, root.LayoutX); - Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(150f, root.LayoutWidth); - Assert.AreEqual(100f, root.LayoutHeight); - - Assert.AreEqual(0f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); - Assert.AreEqual(50f, root_child0.LayoutWidth); - Assert.AreEqual(100f, root_child0.LayoutHeight); - - Assert.AreEqual(50f, root_child1.LayoutX); - Assert.AreEqual(0f, root_child1.LayoutY); - Assert.AreEqual(0f, root_child1.LayoutWidth); - Assert.AreEqual(100f, root_child1.LayoutHeight); - - Assert.AreEqual(50f, root_child2.LayoutX); - Assert.AreEqual(0f, root_child2.LayoutY); - Assert.AreEqual(50f, root_child2.LayoutWidth); - Assert.AreEqual(100f, root_child2.LayoutHeight); - - Assert.AreEqual(100f, root_child3.LayoutX); - Assert.AreEqual(0f, root_child3.LayoutY); - Assert.AreEqual(0f, root_child3.LayoutWidth); - Assert.AreEqual(100f, root_child3.LayoutHeight); - - Assert.AreEqual(100f, root_child4.LayoutX); - Assert.AreEqual(0f, root_child4.LayoutY); - Assert.AreEqual(50f, root_child4.LayoutWidth); - Assert.AreEqual(100f, root_child4.LayoutHeight); - - root.StyleDirection = YogaDirection.RTL; - root.CalculateLayout(); - - Assert.AreEqual(0f, root.LayoutX); - Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(150f, root.LayoutWidth); - Assert.AreEqual(100f, root.LayoutHeight); - - Assert.AreEqual(100f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); - Assert.AreEqual(50f, root_child0.LayoutWidth); - Assert.AreEqual(100f, root_child0.LayoutHeight); - - Assert.AreEqual(100f, root_child1.LayoutX); - Assert.AreEqual(0f, root_child1.LayoutY); - Assert.AreEqual(0f, root_child1.LayoutWidth); - Assert.AreEqual(100f, root_child1.LayoutHeight); - - Assert.AreEqual(50f, root_child2.LayoutX); - Assert.AreEqual(0f, root_child2.LayoutY); - Assert.AreEqual(50f, root_child2.LayoutWidth); - Assert.AreEqual(100f, root_child2.LayoutHeight); - - Assert.AreEqual(50f, root_child3.LayoutX); - Assert.AreEqual(0f, root_child3.LayoutY); - Assert.AreEqual(0f, root_child3.LayoutWidth); - Assert.AreEqual(100f, root_child3.LayoutHeight); - - Assert.AreEqual(0f, root_child4.LayoutX); - Assert.AreEqual(0f, root_child4.LayoutY); - Assert.AreEqual(50f, root_child4.LayoutWidth); - Assert.AreEqual(100f, root_child4.LayoutHeight); - } - - [Test] - public void Test_align_content_stretch_row_with_flex_no_shrink() - { - YogaNode root = new YogaNode(); - root.FlexDirection = YogaFlexDirection.Row; - root.AlignContent = YogaAlign.Stretch; - root.Wrap = YogaWrap.Wrap; - root.Width = 150; - root.Height = 100; - - YogaNode root_child0 = new YogaNode(); - root_child0.Width = 50; - root.Insert(0, root_child0); - - YogaNode root_child1 = new YogaNode(); - root_child1.FlexGrow = 1; - root_child1.FlexShrink = 1; - root_child1.FlexBasis = 0.Percent(); - root_child1.Width = 50; - root.Insert(1, root_child1); - - YogaNode root_child2 = new YogaNode(); - root_child2.Width = 50; - root.Insert(2, root_child2); - - YogaNode root_child3 = new YogaNode(); - root_child3.FlexGrow = 1; - root_child3.FlexBasis = 0.Percent(); - root_child3.Width = 50; - root.Insert(3, root_child3); - - YogaNode root_child4 = new YogaNode(); - root_child4.Width = 50; - root.Insert(4, root_child4); - root.StyleDirection = YogaDirection.LTR; - root.CalculateLayout(); - - Assert.AreEqual(0f, root.LayoutX); - Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(150f, root.LayoutWidth); - Assert.AreEqual(100f, root.LayoutHeight); - - Assert.AreEqual(0f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); - Assert.AreEqual(50f, root_child0.LayoutWidth); - Assert.AreEqual(100f, root_child0.LayoutHeight); - - Assert.AreEqual(50f, root_child1.LayoutX); - Assert.AreEqual(0f, root_child1.LayoutY); - Assert.AreEqual(0f, root_child1.LayoutWidth); - Assert.AreEqual(100f, root_child1.LayoutHeight); - - Assert.AreEqual(50f, root_child2.LayoutX); - Assert.AreEqual(0f, root_child2.LayoutY); - Assert.AreEqual(50f, root_child2.LayoutWidth); - Assert.AreEqual(100f, root_child2.LayoutHeight); - - Assert.AreEqual(100f, root_child3.LayoutX); - Assert.AreEqual(0f, root_child3.LayoutY); - Assert.AreEqual(0f, root_child3.LayoutWidth); - Assert.AreEqual(100f, root_child3.LayoutHeight); - - Assert.AreEqual(100f, root_child4.LayoutX); - Assert.AreEqual(0f, root_child4.LayoutY); - Assert.AreEqual(50f, root_child4.LayoutWidth); - Assert.AreEqual(100f, root_child4.LayoutHeight); - - root.StyleDirection = YogaDirection.RTL; - root.CalculateLayout(); - - Assert.AreEqual(0f, root.LayoutX); - Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(150f, root.LayoutWidth); - Assert.AreEqual(100f, root.LayoutHeight); - - Assert.AreEqual(100f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); - Assert.AreEqual(50f, root_child0.LayoutWidth); - Assert.AreEqual(100f, root_child0.LayoutHeight); - - Assert.AreEqual(100f, root_child1.LayoutX); - Assert.AreEqual(0f, root_child1.LayoutY); - Assert.AreEqual(0f, root_child1.LayoutWidth); - Assert.AreEqual(100f, root_child1.LayoutHeight); - - Assert.AreEqual(50f, root_child2.LayoutX); - Assert.AreEqual(0f, root_child2.LayoutY); - Assert.AreEqual(50f, root_child2.LayoutWidth); - Assert.AreEqual(100f, root_child2.LayoutHeight); - - Assert.AreEqual(50f, root_child3.LayoutX); - Assert.AreEqual(0f, root_child3.LayoutY); - Assert.AreEqual(0f, root_child3.LayoutWidth); - Assert.AreEqual(100f, root_child3.LayoutHeight); - - Assert.AreEqual(0f, root_child4.LayoutX); - Assert.AreEqual(0f, root_child4.LayoutY); - Assert.AreEqual(50f, root_child4.LayoutWidth); - Assert.AreEqual(100f, root_child4.LayoutHeight); - } - - [Test] - public void Test_align_content_stretch_row_with_margin() - { - YogaNode root = new YogaNode(); - root.FlexDirection = YogaFlexDirection.Row; - root.AlignContent = YogaAlign.Stretch; - root.Wrap = YogaWrap.Wrap; - root.Width = 150; - root.Height = 100; - - YogaNode root_child0 = new YogaNode(); - root_child0.Width = 50; - root.Insert(0, root_child0); - - YogaNode root_child1 = new YogaNode(); - root_child1.MarginLeft = 10; - root_child1.MarginTop = 10; - root_child1.MarginRight = 10; - root_child1.MarginBottom = 10; - root_child1.Width = 50; - root.Insert(1, root_child1); - - YogaNode root_child2 = new YogaNode(); - root_child2.Width = 50; - root.Insert(2, root_child2); - - YogaNode root_child3 = new YogaNode(); - root_child3.MarginLeft = 10; - root_child3.MarginTop = 10; - root_child3.MarginRight = 10; - root_child3.MarginBottom = 10; - root_child3.Width = 50; - root.Insert(3, root_child3); - - YogaNode root_child4 = new YogaNode(); - root_child4.Width = 50; - root.Insert(4, root_child4); - root.StyleDirection = YogaDirection.LTR; - root.CalculateLayout(); - - Assert.AreEqual(0f, root.LayoutX); - Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(150f, root.LayoutWidth); - Assert.AreEqual(100f, root.LayoutHeight); - - Assert.AreEqual(0f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); - Assert.AreEqual(50f, root_child0.LayoutWidth); - Assert.AreEqual(40f, root_child0.LayoutHeight); - - Assert.AreEqual(60f, root_child1.LayoutX); - Assert.AreEqual(10f, root_child1.LayoutY); - Assert.AreEqual(50f, root_child1.LayoutWidth); - Assert.AreEqual(20f, root_child1.LayoutHeight); - - Assert.AreEqual(0f, root_child2.LayoutX); - Assert.AreEqual(40f, root_child2.LayoutY); - Assert.AreEqual(50f, root_child2.LayoutWidth); - Assert.AreEqual(40f, root_child2.LayoutHeight); - - Assert.AreEqual(60f, root_child3.LayoutX); - Assert.AreEqual(50f, root_child3.LayoutY); - Assert.AreEqual(50f, root_child3.LayoutWidth); - Assert.AreEqual(20f, root_child3.LayoutHeight); - - Assert.AreEqual(0f, root_child4.LayoutX); - Assert.AreEqual(80f, root_child4.LayoutY); - Assert.AreEqual(50f, root_child4.LayoutWidth); - Assert.AreEqual(20f, root_child4.LayoutHeight); - - root.StyleDirection = YogaDirection.RTL; - root.CalculateLayout(); - - Assert.AreEqual(0f, root.LayoutX); - Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(150f, root.LayoutWidth); - Assert.AreEqual(100f, root.LayoutHeight); - - Assert.AreEqual(100f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); - Assert.AreEqual(50f, root_child0.LayoutWidth); - Assert.AreEqual(40f, root_child0.LayoutHeight); - - Assert.AreEqual(40f, root_child1.LayoutX); - Assert.AreEqual(10f, root_child1.LayoutY); - Assert.AreEqual(50f, root_child1.LayoutWidth); - Assert.AreEqual(20f, root_child1.LayoutHeight); - - Assert.AreEqual(100f, root_child2.LayoutX); - Assert.AreEqual(40f, root_child2.LayoutY); - Assert.AreEqual(50f, root_child2.LayoutWidth); - Assert.AreEqual(40f, root_child2.LayoutHeight); - - Assert.AreEqual(40f, root_child3.LayoutX); - Assert.AreEqual(50f, root_child3.LayoutY); - Assert.AreEqual(50f, root_child3.LayoutWidth); - Assert.AreEqual(20f, root_child3.LayoutHeight); - - Assert.AreEqual(100f, root_child4.LayoutX); - Assert.AreEqual(80f, root_child4.LayoutY); - Assert.AreEqual(50f, root_child4.LayoutWidth); - Assert.AreEqual(20f, root_child4.LayoutHeight); - } - - [Test] - public void Test_align_content_stretch_row_with_padding() - { - YogaNode root = new YogaNode(); - root.FlexDirection = YogaFlexDirection.Row; - root.AlignContent = YogaAlign.Stretch; - root.Wrap = YogaWrap.Wrap; - root.Width = 150; - root.Height = 100; - - YogaNode root_child0 = new YogaNode(); - root_child0.Width = 50; - root.Insert(0, root_child0); - - YogaNode root_child1 = new YogaNode(); - root_child1.PaddingLeft = 10; - root_child1.PaddingTop = 10; - root_child1.PaddingRight = 10; - root_child1.PaddingBottom = 10; - root_child1.Width = 50; - root.Insert(1, root_child1); - - YogaNode root_child2 = new YogaNode(); - root_child2.Width = 50; - root.Insert(2, root_child2); - - YogaNode root_child3 = new YogaNode(); - root_child3.PaddingLeft = 10; - root_child3.PaddingTop = 10; - root_child3.PaddingRight = 10; - root_child3.PaddingBottom = 10; - root_child3.Width = 50; - root.Insert(3, root_child3); - - YogaNode root_child4 = new YogaNode(); - root_child4.Width = 50; - root.Insert(4, root_child4); - root.StyleDirection = YogaDirection.LTR; - root.CalculateLayout(); - - Assert.AreEqual(0f, root.LayoutX); - Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(150f, root.LayoutWidth); - Assert.AreEqual(100f, root.LayoutHeight); - - Assert.AreEqual(0f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); - Assert.AreEqual(50f, root_child0.LayoutWidth); - Assert.AreEqual(50f, root_child0.LayoutHeight); - - Assert.AreEqual(50f, root_child1.LayoutX); - Assert.AreEqual(0f, root_child1.LayoutY); - Assert.AreEqual(50f, root_child1.LayoutWidth); - Assert.AreEqual(50f, root_child1.LayoutHeight); - - Assert.AreEqual(100f, root_child2.LayoutX); - Assert.AreEqual(0f, root_child2.LayoutY); - Assert.AreEqual(50f, root_child2.LayoutWidth); - Assert.AreEqual(50f, root_child2.LayoutHeight); - - Assert.AreEqual(0f, root_child3.LayoutX); - Assert.AreEqual(50f, root_child3.LayoutY); - Assert.AreEqual(50f, root_child3.LayoutWidth); - Assert.AreEqual(50f, root_child3.LayoutHeight); - - Assert.AreEqual(50f, root_child4.LayoutX); - Assert.AreEqual(50f, root_child4.LayoutY); - Assert.AreEqual(50f, root_child4.LayoutWidth); - Assert.AreEqual(50f, root_child4.LayoutHeight); - - root.StyleDirection = YogaDirection.RTL; - root.CalculateLayout(); - - Assert.AreEqual(0f, root.LayoutX); - Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(150f, root.LayoutWidth); - Assert.AreEqual(100f, root.LayoutHeight); - - Assert.AreEqual(100f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); - Assert.AreEqual(50f, root_child0.LayoutWidth); - Assert.AreEqual(50f, root_child0.LayoutHeight); - - Assert.AreEqual(50f, root_child1.LayoutX); - Assert.AreEqual(0f, root_child1.LayoutY); - Assert.AreEqual(50f, root_child1.LayoutWidth); - Assert.AreEqual(50f, root_child1.LayoutHeight); - - Assert.AreEqual(0f, root_child2.LayoutX); - Assert.AreEqual(0f, root_child2.LayoutY); - Assert.AreEqual(50f, root_child2.LayoutWidth); - Assert.AreEqual(50f, root_child2.LayoutHeight); - - Assert.AreEqual(100f, root_child3.LayoutX); - Assert.AreEqual(50f, root_child3.LayoutY); - Assert.AreEqual(50f, root_child3.LayoutWidth); - Assert.AreEqual(50f, root_child3.LayoutHeight); - - Assert.AreEqual(50f, root_child4.LayoutX); - Assert.AreEqual(50f, root_child4.LayoutY); - Assert.AreEqual(50f, root_child4.LayoutWidth); - Assert.AreEqual(50f, root_child4.LayoutHeight); - } - - [Test] - public void Test_align_content_stretch_row_with_single_row() - { - YogaNode root = new YogaNode(); - root.FlexDirection = YogaFlexDirection.Row; - root.AlignContent = YogaAlign.Stretch; - root.Wrap = YogaWrap.Wrap; - root.Width = 150; - root.Height = 100; - - YogaNode root_child0 = new YogaNode(); - root_child0.Width = 50; - root.Insert(0, root_child0); - - YogaNode root_child1 = new YogaNode(); - root_child1.Width = 50; - root.Insert(1, root_child1); - root.StyleDirection = YogaDirection.LTR; - root.CalculateLayout(); - - Assert.AreEqual(0f, root.LayoutX); - Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(150f, root.LayoutWidth); - Assert.AreEqual(100f, root.LayoutHeight); - - Assert.AreEqual(0f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); - Assert.AreEqual(50f, root_child0.LayoutWidth); - Assert.AreEqual(100f, root_child0.LayoutHeight); - - Assert.AreEqual(50f, root_child1.LayoutX); - Assert.AreEqual(0f, root_child1.LayoutY); - Assert.AreEqual(50f, root_child1.LayoutWidth); - Assert.AreEqual(100f, root_child1.LayoutHeight); - - root.StyleDirection = YogaDirection.RTL; - root.CalculateLayout(); - - Assert.AreEqual(0f, root.LayoutX); - Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(150f, root.LayoutWidth); - Assert.AreEqual(100f, root.LayoutHeight); - - Assert.AreEqual(100f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); - Assert.AreEqual(50f, root_child0.LayoutWidth); - Assert.AreEqual(100f, root_child0.LayoutHeight); - - Assert.AreEqual(50f, root_child1.LayoutX); - Assert.AreEqual(0f, root_child1.LayoutY); - Assert.AreEqual(50f, root_child1.LayoutWidth); - Assert.AreEqual(100f, root_child1.LayoutHeight); - } - - [Test] - public void Test_align_content_stretch_row_with_fixed_height() - { - YogaNode root = new YogaNode(); - root.FlexDirection = YogaFlexDirection.Row; - root.AlignContent = YogaAlign.Stretch; - root.Wrap = YogaWrap.Wrap; - root.Width = 150; - root.Height = 100; - - YogaNode root_child0 = new YogaNode(); - root_child0.Width = 50; - root.Insert(0, root_child0); - - YogaNode root_child1 = new YogaNode(); - root_child1.Width = 50; - root_child1.Height = 60; - root.Insert(1, root_child1); - - YogaNode root_child2 = new YogaNode(); - root_child2.Width = 50; - root.Insert(2, root_child2); - - YogaNode root_child3 = new YogaNode(); - root_child3.Width = 50; - root.Insert(3, root_child3); - - YogaNode root_child4 = new YogaNode(); - root_child4.Width = 50; - root.Insert(4, root_child4); - root.StyleDirection = YogaDirection.LTR; - root.CalculateLayout(); - - Assert.AreEqual(0f, root.LayoutX); - Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(150f, root.LayoutWidth); - Assert.AreEqual(100f, root.LayoutHeight); - - Assert.AreEqual(0f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); - Assert.AreEqual(50f, root_child0.LayoutWidth); - Assert.AreEqual(80f, root_child0.LayoutHeight); - - Assert.AreEqual(50f, root_child1.LayoutX); - Assert.AreEqual(0f, root_child1.LayoutY); - Assert.AreEqual(50f, root_child1.LayoutWidth); - Assert.AreEqual(60f, root_child1.LayoutHeight); - - Assert.AreEqual(100f, root_child2.LayoutX); - Assert.AreEqual(0f, root_child2.LayoutY); - Assert.AreEqual(50f, root_child2.LayoutWidth); - Assert.AreEqual(80f, root_child2.LayoutHeight); - - Assert.AreEqual(0f, root_child3.LayoutX); - Assert.AreEqual(80f, root_child3.LayoutY); - Assert.AreEqual(50f, root_child3.LayoutWidth); - Assert.AreEqual(20f, root_child3.LayoutHeight); - - Assert.AreEqual(50f, root_child4.LayoutX); - Assert.AreEqual(80f, root_child4.LayoutY); - Assert.AreEqual(50f, root_child4.LayoutWidth); - Assert.AreEqual(20f, root_child4.LayoutHeight); - - root.StyleDirection = YogaDirection.RTL; - root.CalculateLayout(); - - Assert.AreEqual(0f, root.LayoutX); - Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(150f, root.LayoutWidth); - Assert.AreEqual(100f, root.LayoutHeight); - - Assert.AreEqual(100f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); - Assert.AreEqual(50f, root_child0.LayoutWidth); - Assert.AreEqual(80f, root_child0.LayoutHeight); - - Assert.AreEqual(50f, root_child1.LayoutX); - Assert.AreEqual(0f, root_child1.LayoutY); - Assert.AreEqual(50f, root_child1.LayoutWidth); - Assert.AreEqual(60f, root_child1.LayoutHeight); - - Assert.AreEqual(0f, root_child2.LayoutX); - Assert.AreEqual(0f, root_child2.LayoutY); - Assert.AreEqual(50f, root_child2.LayoutWidth); - Assert.AreEqual(80f, root_child2.LayoutHeight); - - Assert.AreEqual(100f, root_child3.LayoutX); - Assert.AreEqual(80f, root_child3.LayoutY); - Assert.AreEqual(50f, root_child3.LayoutWidth); - Assert.AreEqual(20f, root_child3.LayoutHeight); - - Assert.AreEqual(50f, root_child4.LayoutX); - Assert.AreEqual(80f, root_child4.LayoutY); - Assert.AreEqual(50f, root_child4.LayoutWidth); - Assert.AreEqual(20f, root_child4.LayoutHeight); - } - - [Test] - public void Test_align_content_stretch_row_with_max_height() - { - YogaNode root = new YogaNode(); - root.FlexDirection = YogaFlexDirection.Row; - root.AlignContent = YogaAlign.Stretch; - root.Wrap = YogaWrap.Wrap; - root.Width = 150; - root.Height = 100; - - YogaNode root_child0 = new YogaNode(); - root_child0.Width = 50; - root.Insert(0, root_child0); - - YogaNode root_child1 = new YogaNode(); - root_child1.Width = 50; - root_child1.MaxHeight = 20; - root.Insert(1, root_child1); - - YogaNode root_child2 = new YogaNode(); - root_child2.Width = 50; - root.Insert(2, root_child2); - - YogaNode root_child3 = new YogaNode(); - root_child3.Width = 50; - root.Insert(3, root_child3); - - YogaNode root_child4 = new YogaNode(); - root_child4.Width = 50; - root.Insert(4, root_child4); - root.StyleDirection = YogaDirection.LTR; - root.CalculateLayout(); - - Assert.AreEqual(0f, root.LayoutX); - Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(150f, root.LayoutWidth); - Assert.AreEqual(100f, root.LayoutHeight); - - Assert.AreEqual(0f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); - Assert.AreEqual(50f, root_child0.LayoutWidth); - Assert.AreEqual(50f, root_child0.LayoutHeight); - - Assert.AreEqual(50f, root_child1.LayoutX); - Assert.AreEqual(0f, root_child1.LayoutY); - Assert.AreEqual(50f, root_child1.LayoutWidth); - Assert.AreEqual(20f, root_child1.LayoutHeight); - - Assert.AreEqual(100f, root_child2.LayoutX); - Assert.AreEqual(0f, root_child2.LayoutY); - Assert.AreEqual(50f, root_child2.LayoutWidth); - Assert.AreEqual(50f, root_child2.LayoutHeight); - - Assert.AreEqual(0f, root_child3.LayoutX); - Assert.AreEqual(50f, root_child3.LayoutY); - Assert.AreEqual(50f, root_child3.LayoutWidth); - Assert.AreEqual(50f, root_child3.LayoutHeight); - - Assert.AreEqual(50f, root_child4.LayoutX); - Assert.AreEqual(50f, root_child4.LayoutY); - Assert.AreEqual(50f, root_child4.LayoutWidth); - Assert.AreEqual(50f, root_child4.LayoutHeight); - - root.StyleDirection = YogaDirection.RTL; - root.CalculateLayout(); - - Assert.AreEqual(0f, root.LayoutX); - Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(150f, root.LayoutWidth); - Assert.AreEqual(100f, root.LayoutHeight); - - Assert.AreEqual(100f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); - Assert.AreEqual(50f, root_child0.LayoutWidth); - Assert.AreEqual(50f, root_child0.LayoutHeight); - - Assert.AreEqual(50f, root_child1.LayoutX); - Assert.AreEqual(0f, root_child1.LayoutY); - Assert.AreEqual(50f, root_child1.LayoutWidth); - Assert.AreEqual(20f, root_child1.LayoutHeight); - - Assert.AreEqual(0f, root_child2.LayoutX); - Assert.AreEqual(0f, root_child2.LayoutY); - Assert.AreEqual(50f, root_child2.LayoutWidth); - Assert.AreEqual(50f, root_child2.LayoutHeight); - - Assert.AreEqual(100f, root_child3.LayoutX); - Assert.AreEqual(50f, root_child3.LayoutY); - Assert.AreEqual(50f, root_child3.LayoutWidth); - Assert.AreEqual(50f, root_child3.LayoutHeight); - - Assert.AreEqual(50f, root_child4.LayoutX); - Assert.AreEqual(50f, root_child4.LayoutY); - Assert.AreEqual(50f, root_child4.LayoutWidth); - Assert.AreEqual(50f, root_child4.LayoutHeight); - } - - [Test] - public void Test_align_content_stretch_row_with_min_height() - { - YogaNode root = new YogaNode(); - root.FlexDirection = YogaFlexDirection.Row; - root.AlignContent = YogaAlign.Stretch; - root.Wrap = YogaWrap.Wrap; - root.Width = 150; - root.Height = 100; - - YogaNode root_child0 = new YogaNode(); - root_child0.Width = 50; - root.Insert(0, root_child0); - - YogaNode root_child1 = new YogaNode(); - root_child1.Width = 50; - root_child1.MinHeight = 80; - root.Insert(1, root_child1); - - YogaNode root_child2 = new YogaNode(); - root_child2.Width = 50; - root.Insert(2, root_child2); - - YogaNode root_child3 = new YogaNode(); - root_child3.Width = 50; - root.Insert(3, root_child3); - - YogaNode root_child4 = new YogaNode(); - root_child4.Width = 50; - root.Insert(4, root_child4); - root.StyleDirection = YogaDirection.LTR; - root.CalculateLayout(); - - Assert.AreEqual(0f, root.LayoutX); - Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(150f, root.LayoutWidth); - Assert.AreEqual(100f, root.LayoutHeight); - - Assert.AreEqual(0f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); - Assert.AreEqual(50f, root_child0.LayoutWidth); - Assert.AreEqual(90f, root_child0.LayoutHeight); - - Assert.AreEqual(50f, root_child1.LayoutX); - Assert.AreEqual(0f, root_child1.LayoutY); - Assert.AreEqual(50f, root_child1.LayoutWidth); - Assert.AreEqual(90f, root_child1.LayoutHeight); - - Assert.AreEqual(100f, root_child2.LayoutX); - Assert.AreEqual(0f, root_child2.LayoutY); - Assert.AreEqual(50f, root_child2.LayoutWidth); - Assert.AreEqual(90f, root_child2.LayoutHeight); - - Assert.AreEqual(0f, root_child3.LayoutX); - Assert.AreEqual(90f, root_child3.LayoutY); - Assert.AreEqual(50f, root_child3.LayoutWidth); - Assert.AreEqual(10f, root_child3.LayoutHeight); - - Assert.AreEqual(50f, root_child4.LayoutX); - Assert.AreEqual(90f, root_child4.LayoutY); - Assert.AreEqual(50f, root_child4.LayoutWidth); - Assert.AreEqual(10f, root_child4.LayoutHeight); - - root.StyleDirection = YogaDirection.RTL; - root.CalculateLayout(); - - Assert.AreEqual(0f, root.LayoutX); - Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(150f, root.LayoutWidth); - Assert.AreEqual(100f, root.LayoutHeight); - - Assert.AreEqual(100f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); - Assert.AreEqual(50f, root_child0.LayoutWidth); - Assert.AreEqual(90f, root_child0.LayoutHeight); - - Assert.AreEqual(50f, root_child1.LayoutX); - Assert.AreEqual(0f, root_child1.LayoutY); - Assert.AreEqual(50f, root_child1.LayoutWidth); - Assert.AreEqual(90f, root_child1.LayoutHeight); - - Assert.AreEqual(0f, root_child2.LayoutX); - Assert.AreEqual(0f, root_child2.LayoutY); - Assert.AreEqual(50f, root_child2.LayoutWidth); - Assert.AreEqual(90f, root_child2.LayoutHeight); - - Assert.AreEqual(100f, root_child3.LayoutX); - Assert.AreEqual(90f, root_child3.LayoutY); - Assert.AreEqual(50f, root_child3.LayoutWidth); - Assert.AreEqual(10f, root_child3.LayoutHeight); - - Assert.AreEqual(50f, root_child4.LayoutX); - Assert.AreEqual(90f, root_child4.LayoutY); - Assert.AreEqual(50f, root_child4.LayoutWidth); - Assert.AreEqual(10f, root_child4.LayoutHeight); - } - - [Test] - public void Test_align_content_stretch_column() - { - YogaNode root = new YogaNode(); - root.AlignContent = YogaAlign.Stretch; - root.Wrap = YogaWrap.Wrap; - root.Width = 100; - root.Height = 150; - - YogaNode root_child0 = new YogaNode(); - root_child0.Height = 50; - root.Insert(0, root_child0); - - YogaNode root_child0_child0 = new YogaNode(); - root_child0_child0.FlexGrow = 1; - root_child0_child0.FlexShrink = 1; - root_child0_child0.FlexBasis = 0.Percent(); - root_child0.Insert(0, root_child0_child0); - - YogaNode root_child1 = new YogaNode(); - root_child1.FlexGrow = 1; - root_child1.FlexShrink = 1; - root_child1.FlexBasis = 0.Percent(); - root_child1.Height = 50; - root.Insert(1, root_child1); - - YogaNode root_child2 = new YogaNode(); - root_child2.Height = 50; - root.Insert(2, root_child2); - - YogaNode root_child3 = new YogaNode(); - root_child3.Height = 50; - root.Insert(3, root_child3); - - YogaNode root_child4 = new YogaNode(); - root_child4.Height = 50; - root.Insert(4, root_child4); - root.StyleDirection = YogaDirection.LTR; - root.CalculateLayout(); - - Assert.AreEqual(0f, root.LayoutX); - Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(100f, root.LayoutWidth); - Assert.AreEqual(150f, root.LayoutHeight); - - Assert.AreEqual(0f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); - Assert.AreEqual(50f, root_child0.LayoutWidth); - Assert.AreEqual(50f, root_child0.LayoutHeight); - - Assert.AreEqual(0f, root_child0_child0.LayoutX); - Assert.AreEqual(0f, root_child0_child0.LayoutY); - Assert.AreEqual(50f, root_child0_child0.LayoutWidth); - Assert.AreEqual(50f, root_child0_child0.LayoutHeight); - - Assert.AreEqual(0f, root_child1.LayoutX); - Assert.AreEqual(50f, root_child1.LayoutY); - Assert.AreEqual(50f, root_child1.LayoutWidth); - Assert.AreEqual(0f, root_child1.LayoutHeight); - - Assert.AreEqual(0f, root_child2.LayoutX); - Assert.AreEqual(50f, root_child2.LayoutY); - Assert.AreEqual(50f, root_child2.LayoutWidth); - Assert.AreEqual(50f, root_child2.LayoutHeight); - - Assert.AreEqual(0f, root_child3.LayoutX); - Assert.AreEqual(100f, root_child3.LayoutY); - Assert.AreEqual(50f, root_child3.LayoutWidth); - Assert.AreEqual(50f, root_child3.LayoutHeight); - - Assert.AreEqual(50f, root_child4.LayoutX); - Assert.AreEqual(0f, root_child4.LayoutY); - Assert.AreEqual(50f, root_child4.LayoutWidth); - Assert.AreEqual(50f, root_child4.LayoutHeight); - - root.StyleDirection = YogaDirection.RTL; - root.CalculateLayout(); - - Assert.AreEqual(0f, root.LayoutX); - Assert.AreEqual(0f, root.LayoutY); - Assert.AreEqual(100f, root.LayoutWidth); - Assert.AreEqual(150f, root.LayoutHeight); - - Assert.AreEqual(50f, root_child0.LayoutX); - Assert.AreEqual(0f, root_child0.LayoutY); - Assert.AreEqual(50f, root_child0.LayoutWidth); - Assert.AreEqual(50f, root_child0.LayoutHeight); - - Assert.AreEqual(0f, root_child0_child0.LayoutX); - Assert.AreEqual(0f, root_child0_child0.LayoutY); - Assert.AreEqual(50f, root_child0_child0.LayoutWidth); - Assert.AreEqual(50f, root_child0_child0.LayoutHeight); - - Assert.AreEqual(50f, root_child1.LayoutX); - Assert.AreEqual(50f, root_child1.LayoutY); - Assert.AreEqual(50f, root_child1.LayoutWidth); - Assert.AreEqual(0f, root_child1.LayoutHeight); - - Assert.AreEqual(50f, root_child2.LayoutX); - Assert.AreEqual(50f, root_child2.LayoutY); - Assert.AreEqual(50f, root_child2.LayoutWidth); - Assert.AreEqual(50f, root_child2.LayoutHeight); - - Assert.AreEqual(50f, root_child3.LayoutX); - Assert.AreEqual(100f, root_child3.LayoutY); - Assert.AreEqual(50f, root_child3.LayoutWidth); - Assert.AreEqual(50f, root_child3.LayoutHeight); - - Assert.AreEqual(0f, root_child4.LayoutX); - Assert.AreEqual(0f, root_child4.LayoutY); - Assert.AreEqual(50f, root_child4.LayoutWidth); - Assert.AreEqual(50f, root_child4.LayoutHeight); - } - } } diff --git a/gentest/fixtures/YGAlignContentTest.html b/gentest/fixtures/YGAlignContentTest.html index de7938fb..b1f23050 100644 --- a/gentest/fixtures/YGAlignContentTest.html +++ b/gentest/fixtures/YGAlignContentTest.html @@ -6,23 +6,15 @@
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
- -
+
@@ -53,92 +45,3 @@
- -
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
- -
-
-
-
-
-
-
- -
-
-
-
-
-
-
- -
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-
- -
-
-
-
-
-
-
- -
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
diff --git a/java/tests/com/facebook/yoga/YGAlignContentTest.java b/java/tests/com/facebook/yoga/YGAlignContentTest.java index 122f26cc..de9daa1b 100644 --- a/java/tests/com/facebook/yoga/YGAlignContentTest.java +++ b/java/tests/com/facebook/yoga/YGAlignContentTest.java @@ -115,208 +115,13 @@ public class YGAlignContentTest { assertEquals(10f, root_child4.getLayoutHeight(), 0.0f); } - @Test - public void test_align_content_flex_start_without_height_on_children() { - final YogaNode root = new YogaNode(); - root.setWrap(YogaWrap.WRAP); - root.setWidth(100f); - root.setHeight(100f); - - final YogaNode root_child0 = new YogaNode(); - root_child0.setWidth(50f); - root.addChildAt(root_child0, 0); - - final YogaNode root_child1 = new YogaNode(); - root_child1.setWidth(50f); - root_child1.setHeight(10f); - root.addChildAt(root_child1, 1); - - final YogaNode root_child2 = new YogaNode(); - root_child2.setWidth(50f); - root.addChildAt(root_child2, 2); - - final YogaNode root_child3 = new YogaNode(); - root_child3.setWidth(50f); - root_child3.setHeight(10f); - root.addChildAt(root_child3, 3); - - final YogaNode root_child4 = new YogaNode(); - root_child4.setWidth(50f); - root.addChildAt(root_child4, 4); - root.setDirection(YogaDirection.LTR); - root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); - - assertEquals(0f, root.getLayoutX(), 0.0f); - assertEquals(0f, root.getLayoutY(), 0.0f); - assertEquals(100f, root.getLayoutWidth(), 0.0f); - assertEquals(100f, root.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(0f, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child1.getLayoutX(), 0.0f); - assertEquals(0f, root_child1.getLayoutY(), 0.0f); - assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); - assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child2.getLayoutX(), 0.0f); - assertEquals(10f, root_child2.getLayoutY(), 0.0f); - assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); - assertEquals(0f, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child3.getLayoutX(), 0.0f); - assertEquals(10f, root_child3.getLayoutY(), 0.0f); - assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); - assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child4.getLayoutX(), 0.0f); - assertEquals(20f, root_child4.getLayoutY(), 0.0f); - assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); - assertEquals(0f, root_child4.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(100f, root.getLayoutWidth(), 0.0f); - assertEquals(100f, root.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(0f, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child1.getLayoutX(), 0.0f); - assertEquals(0f, root_child1.getLayoutY(), 0.0f); - assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); - assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child2.getLayoutX(), 0.0f); - assertEquals(10f, root_child2.getLayoutY(), 0.0f); - assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); - assertEquals(0f, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child3.getLayoutX(), 0.0f); - assertEquals(10f, root_child3.getLayoutY(), 0.0f); - assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); - assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child4.getLayoutX(), 0.0f); - assertEquals(20f, root_child4.getLayoutY(), 0.0f); - assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); - assertEquals(0f, root_child4.getLayoutHeight(), 0.0f); - } - - @Test - public void test_align_content_flex_start_with_flex() { - final YogaNode root = new YogaNode(); - root.setWrap(YogaWrap.WRAP); - root.setWidth(100f); - root.setHeight(120f); - - final YogaNode root_child0 = new YogaNode(); - root_child0.setFlexGrow(1f); - root_child0.setFlexBasisPercent(0f); - root_child0.setWidth(50f); - root.addChildAt(root_child0, 0); - - final YogaNode root_child1 = new YogaNode(); - root_child1.setFlexGrow(1f); - root_child1.setFlexBasisPercent(0f); - root_child1.setWidth(50f); - root_child1.setHeight(10f); - root.addChildAt(root_child1, 1); - - final YogaNode root_child2 = new YogaNode(); - root_child2.setWidth(50f); - root.addChildAt(root_child2, 2); - - final YogaNode root_child3 = new YogaNode(); - root_child3.setFlexGrow(1f); - root_child3.setFlexShrink(1f); - root_child3.setFlexBasisPercent(0f); - root_child3.setWidth(50f); - root.addChildAt(root_child3, 3); - - final YogaNode root_child4 = new YogaNode(); - root_child4.setWidth(50f); - root.addChildAt(root_child4, 4); - root.setDirection(YogaDirection.LTR); - root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); - - assertEquals(0f, root.getLayoutX(), 0.0f); - assertEquals(0f, root.getLayoutY(), 0.0f); - assertEquals(100f, root.getLayoutWidth(), 0.0f); - assertEquals(120f, root.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(40f, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child1.getLayoutX(), 0.0f); - assertEquals(40f, root_child1.getLayoutY(), 0.0f); - assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); - assertEquals(40f, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child2.getLayoutX(), 0.0f); - assertEquals(80f, root_child2.getLayoutY(), 0.0f); - assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); - assertEquals(0f, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child3.getLayoutX(), 0.0f); - assertEquals(80f, root_child3.getLayoutY(), 0.0f); - assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); - assertEquals(40f, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child4.getLayoutX(), 0.0f); - assertEquals(120f, root_child4.getLayoutY(), 0.0f); - assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); - assertEquals(0f, root_child4.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(100f, root.getLayoutWidth(), 0.0f); - assertEquals(120f, root.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(40f, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child1.getLayoutX(), 0.0f); - assertEquals(40f, root_child1.getLayoutY(), 0.0f); - assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); - assertEquals(40f, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child2.getLayoutX(), 0.0f); - assertEquals(80f, root_child2.getLayoutY(), 0.0f); - assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); - assertEquals(0f, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child3.getLayoutX(), 0.0f); - assertEquals(80f, root_child3.getLayoutY(), 0.0f); - assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); - assertEquals(40f, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child4.getLayoutX(), 0.0f); - assertEquals(120f, root_child4.getLayoutY(), 0.0f); - assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); - assertEquals(0f, root_child4.getLayoutHeight(), 0.0f); - } - @Test public void test_align_content_flex_end() { final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); root.setAlignContent(YogaAlign.FLEX_END); root.setWrap(YogaWrap.WRAP); - root.setWidth(100f); + root.setWidth(130f); root.setHeight(100f); final YogaNode root_child0 = new YogaNode(); @@ -348,31 +153,31 @@ public class YGAlignContentTest { assertEquals(0f, root.getLayoutX(), 0.0f); assertEquals(0f, root.getLayoutY(), 0.0f); - assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(130f, root.getLayoutWidth(), 0.0f); assertEquals(100f, root.getLayoutHeight(), 0.0f); assertEquals(0f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(70f, root_child0.getLayoutY(), 0.0f); assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); - assertEquals(0f, root_child1.getLayoutX(), 0.0f); - assertEquals(10f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(70f, root_child1.getLayoutY(), 0.0f); assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); assertEquals(0f, root_child2.getLayoutX(), 0.0f); - assertEquals(20f, root_child2.getLayoutY(), 0.0f); + assertEquals(80f, root_child2.getLayoutY(), 0.0f); assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); - assertEquals(0f, root_child3.getLayoutX(), 0.0f); - assertEquals(30f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutX(), 0.0f); + assertEquals(80f, root_child3.getLayoutY(), 0.0f); assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); assertEquals(0f, root_child4.getLayoutX(), 0.0f); - assertEquals(40f, root_child4.getLayoutY(), 0.0f); + assertEquals(90f, root_child4.getLayoutY(), 0.0f); assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); assertEquals(10f, root_child4.getLayoutHeight(), 0.0f); @@ -381,31 +186,131 @@ public class YGAlignContentTest { assertEquals(0f, root.getLayoutX(), 0.0f); assertEquals(0f, root.getLayoutY(), 0.0f); - assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(130f, root.getLayoutWidth(), 0.0f); assertEquals(100f, root.getLayoutHeight(), 0.0f); - assertEquals(50f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(80f, root_child0.getLayoutX(), 0.0f); + assertEquals(70f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(30f, root_child1.getLayoutX(), 0.0f); + assertEquals(70f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(80f, root_child2.getLayoutX(), 0.0f); + assertEquals(80f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(30f, root_child3.getLayoutX(), 0.0f); + assertEquals(80f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(80f, root_child4.getLayoutX(), 0.0f); + assertEquals(90f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child4.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_content_center() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setAlignContent(YogaAlign.CENTER); + root.setWrap(YogaWrap.WRAP); + root.setWidth(130f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(50f); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setWidth(50f); + root_child1.setHeight(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(50f); + root_child2.setHeight(10f); + root.addChildAt(root_child2, 2); + + final YogaNode root_child3 = new YogaNode(); + root_child3.setWidth(50f); + root_child3.setHeight(10f); + root.addChildAt(root_child3, 3); + + final YogaNode root_child4 = new YogaNode(); + root_child4.setWidth(50f); + root_child4.setHeight(10f); + root.addChildAt(root_child4, 4); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(130f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(35f, root_child0.getLayoutY(), 0.0f); assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); assertEquals(50f, root_child1.getLayoutX(), 0.0f); - assertEquals(10f, root_child1.getLayoutY(), 0.0f); + assertEquals(35f, root_child1.getLayoutY(), 0.0f); assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); - assertEquals(50f, root_child2.getLayoutX(), 0.0f); - assertEquals(20f, root_child2.getLayoutY(), 0.0f); + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(45f, root_child2.getLayoutY(), 0.0f); assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); assertEquals(50f, root_child3.getLayoutX(), 0.0f); - assertEquals(30f, root_child3.getLayoutY(), 0.0f); + assertEquals(45f, root_child3.getLayoutY(), 0.0f); assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); - assertEquals(50f, root_child4.getLayoutX(), 0.0f); - assertEquals(40f, root_child4.getLayoutY(), 0.0f); + assertEquals(0f, root_child4.getLayoutX(), 0.0f); + assertEquals(55f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child4.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(130f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(80f, root_child0.getLayoutX(), 0.0f); + assertEquals(35f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(30f, root_child1.getLayoutX(), 0.0f); + assertEquals(35f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(80f, root_child2.getLayoutX(), 0.0f); + assertEquals(45f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(30f, root_child3.getLayoutX(), 0.0f); + assertEquals(45f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(80f, root_child4.getLayoutX(), 0.0f); + assertEquals(55f, root_child4.getLayoutY(), 0.0f); assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); assertEquals(10f, root_child4.getLayoutHeight(), 0.0f); } @@ -704,1071 +609,4 @@ public class YGAlignContentTest { assertEquals(10f, root_child4.getLayoutHeight(), 0.0f); } - @Test - public void test_align_content_stretch_row() { - final YogaNode root = new YogaNode(); - root.setFlexDirection(YogaFlexDirection.ROW); - root.setAlignContent(YogaAlign.STRETCH); - root.setWrap(YogaWrap.WRAP); - root.setWidth(150f); - root.setHeight(100f); - - final YogaNode root_child0 = new YogaNode(); - root_child0.setWidth(50f); - root.addChildAt(root_child0, 0); - - final YogaNode root_child1 = new YogaNode(); - root_child1.setWidth(50f); - root.addChildAt(root_child1, 1); - - final YogaNode root_child2 = new YogaNode(); - root_child2.setWidth(50f); - root.addChildAt(root_child2, 2); - - final YogaNode root_child3 = new YogaNode(); - root_child3.setWidth(50f); - root.addChildAt(root_child3, 3); - - final YogaNode root_child4 = new YogaNode(); - root_child4.setWidth(50f); - root.addChildAt(root_child4, 4); - root.setDirection(YogaDirection.LTR); - root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); - - assertEquals(0f, root.getLayoutX(), 0.0f); - assertEquals(0f, root.getLayoutY(), 0.0f); - assertEquals(150f, root.getLayoutWidth(), 0.0f); - assertEquals(100f, root.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child1.getLayoutX(), 0.0f); - assertEquals(0f, root_child1.getLayoutY(), 0.0f); - assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child2.getLayoutX(), 0.0f); - assertEquals(0f, root_child2.getLayoutY(), 0.0f); - assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child3.getLayoutX(), 0.0f); - assertEquals(50f, root_child3.getLayoutY(), 0.0f); - assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child4.getLayoutX(), 0.0f); - assertEquals(50f, root_child4.getLayoutY(), 0.0f); - assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child4.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(150f, root.getLayoutWidth(), 0.0f); - assertEquals(100f, root.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child1.getLayoutX(), 0.0f); - assertEquals(0f, root_child1.getLayoutY(), 0.0f); - assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child2.getLayoutX(), 0.0f); - assertEquals(0f, root_child2.getLayoutY(), 0.0f); - assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child3.getLayoutX(), 0.0f); - assertEquals(50f, root_child3.getLayoutY(), 0.0f); - assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child4.getLayoutX(), 0.0f); - assertEquals(50f, root_child4.getLayoutY(), 0.0f); - assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child4.getLayoutHeight(), 0.0f); - } - - @Test - public void test_align_content_stretch_row_with_children() { - final YogaNode root = new YogaNode(); - root.setFlexDirection(YogaFlexDirection.ROW); - root.setAlignContent(YogaAlign.STRETCH); - root.setWrap(YogaWrap.WRAP); - root.setWidth(150f); - root.setHeight(100f); - - final YogaNode root_child0 = new YogaNode(); - root_child0.setWidth(50f); - root.addChildAt(root_child0, 0); - - final YogaNode root_child0_child0 = new YogaNode(); - root_child0_child0.setFlexGrow(1f); - root_child0_child0.setFlexShrink(1f); - root_child0_child0.setFlexBasisPercent(0f); - root_child0.addChildAt(root_child0_child0, 0); - - final YogaNode root_child1 = new YogaNode(); - root_child1.setWidth(50f); - root.addChildAt(root_child1, 1); - - final YogaNode root_child2 = new YogaNode(); - root_child2.setWidth(50f); - root.addChildAt(root_child2, 2); - - final YogaNode root_child3 = new YogaNode(); - root_child3.setWidth(50f); - root.addChildAt(root_child3, 3); - - final YogaNode root_child4 = new YogaNode(); - root_child4.setWidth(50f); - root.addChildAt(root_child4, 4); - root.setDirection(YogaDirection.LTR); - root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); - - assertEquals(0f, root.getLayoutX(), 0.0f); - assertEquals(0f, root.getLayoutY(), 0.0f); - assertEquals(150f, root.getLayoutWidth(), 0.0f); - assertEquals(100f, root.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child0_child0.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child1.getLayoutX(), 0.0f); - assertEquals(0f, root_child1.getLayoutY(), 0.0f); - assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child2.getLayoutX(), 0.0f); - assertEquals(0f, root_child2.getLayoutY(), 0.0f); - assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child3.getLayoutX(), 0.0f); - assertEquals(50f, root_child3.getLayoutY(), 0.0f); - assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child4.getLayoutX(), 0.0f); - assertEquals(50f, root_child4.getLayoutY(), 0.0f); - assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child4.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(150f, root.getLayoutWidth(), 0.0f); - assertEquals(100f, root.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child0_child0.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child1.getLayoutX(), 0.0f); - assertEquals(0f, root_child1.getLayoutY(), 0.0f); - assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child2.getLayoutX(), 0.0f); - assertEquals(0f, root_child2.getLayoutY(), 0.0f); - assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child3.getLayoutX(), 0.0f); - assertEquals(50f, root_child3.getLayoutY(), 0.0f); - assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child4.getLayoutX(), 0.0f); - assertEquals(50f, root_child4.getLayoutY(), 0.0f); - assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child4.getLayoutHeight(), 0.0f); - } - - @Test - public void test_align_content_stretch_row_with_flex() { - final YogaNode root = new YogaNode(); - root.setFlexDirection(YogaFlexDirection.ROW); - root.setAlignContent(YogaAlign.STRETCH); - root.setWrap(YogaWrap.WRAP); - root.setWidth(150f); - root.setHeight(100f); - - final YogaNode root_child0 = new YogaNode(); - root_child0.setWidth(50f); - root.addChildAt(root_child0, 0); - - final YogaNode root_child1 = new YogaNode(); - root_child1.setFlexGrow(1f); - root_child1.setFlexShrink(1f); - root_child1.setFlexBasisPercent(0f); - root_child1.setWidth(50f); - root.addChildAt(root_child1, 1); - - final YogaNode root_child2 = new YogaNode(); - root_child2.setWidth(50f); - root.addChildAt(root_child2, 2); - - final YogaNode root_child3 = new YogaNode(); - root_child3.setFlexGrow(1f); - root_child3.setFlexShrink(1f); - root_child3.setFlexBasisPercent(0f); - root_child3.setWidth(50f); - root.addChildAt(root_child3, 3); - - final YogaNode root_child4 = new YogaNode(); - root_child4.setWidth(50f); - root.addChildAt(root_child4, 4); - root.setDirection(YogaDirection.LTR); - root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); - - assertEquals(0f, root.getLayoutX(), 0.0f); - assertEquals(0f, root.getLayoutY(), 0.0f); - assertEquals(150f, root.getLayoutWidth(), 0.0f); - assertEquals(100f, root.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child1.getLayoutX(), 0.0f); - assertEquals(0f, root_child1.getLayoutY(), 0.0f); - assertEquals(0f, root_child1.getLayoutWidth(), 0.0f); - assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child2.getLayoutX(), 0.0f); - assertEquals(0f, root_child2.getLayoutY(), 0.0f); - assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); - assertEquals(100f, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child3.getLayoutX(), 0.0f); - assertEquals(0f, root_child3.getLayoutY(), 0.0f); - assertEquals(0f, root_child3.getLayoutWidth(), 0.0f); - assertEquals(100f, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child4.getLayoutX(), 0.0f); - assertEquals(0f, root_child4.getLayoutY(), 0.0f); - assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); - assertEquals(100f, root_child4.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(150f, root.getLayoutWidth(), 0.0f); - assertEquals(100f, root.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child1.getLayoutX(), 0.0f); - assertEquals(0f, root_child1.getLayoutY(), 0.0f); - assertEquals(0f, root_child1.getLayoutWidth(), 0.0f); - assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child2.getLayoutX(), 0.0f); - assertEquals(0f, root_child2.getLayoutY(), 0.0f); - assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); - assertEquals(100f, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child3.getLayoutX(), 0.0f); - assertEquals(0f, root_child3.getLayoutY(), 0.0f); - assertEquals(0f, root_child3.getLayoutWidth(), 0.0f); - assertEquals(100f, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child4.getLayoutX(), 0.0f); - assertEquals(0f, root_child4.getLayoutY(), 0.0f); - assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); - assertEquals(100f, root_child4.getLayoutHeight(), 0.0f); - } - - @Test - public void test_align_content_stretch_row_with_flex_no_shrink() { - final YogaNode root = new YogaNode(); - root.setFlexDirection(YogaFlexDirection.ROW); - root.setAlignContent(YogaAlign.STRETCH); - root.setWrap(YogaWrap.WRAP); - root.setWidth(150f); - root.setHeight(100f); - - final YogaNode root_child0 = new YogaNode(); - root_child0.setWidth(50f); - root.addChildAt(root_child0, 0); - - final YogaNode root_child1 = new YogaNode(); - root_child1.setFlexGrow(1f); - root_child1.setFlexShrink(1f); - root_child1.setFlexBasisPercent(0f); - root_child1.setWidth(50f); - root.addChildAt(root_child1, 1); - - final YogaNode root_child2 = new YogaNode(); - root_child2.setWidth(50f); - root.addChildAt(root_child2, 2); - - final YogaNode root_child3 = new YogaNode(); - root_child3.setFlexGrow(1f); - root_child3.setFlexBasisPercent(0f); - root_child3.setWidth(50f); - root.addChildAt(root_child3, 3); - - final YogaNode root_child4 = new YogaNode(); - root_child4.setWidth(50f); - root.addChildAt(root_child4, 4); - root.setDirection(YogaDirection.LTR); - root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); - - assertEquals(0f, root.getLayoutX(), 0.0f); - assertEquals(0f, root.getLayoutY(), 0.0f); - assertEquals(150f, root.getLayoutWidth(), 0.0f); - assertEquals(100f, root.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child1.getLayoutX(), 0.0f); - assertEquals(0f, root_child1.getLayoutY(), 0.0f); - assertEquals(0f, root_child1.getLayoutWidth(), 0.0f); - assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child2.getLayoutX(), 0.0f); - assertEquals(0f, root_child2.getLayoutY(), 0.0f); - assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); - assertEquals(100f, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child3.getLayoutX(), 0.0f); - assertEquals(0f, root_child3.getLayoutY(), 0.0f); - assertEquals(0f, root_child3.getLayoutWidth(), 0.0f); - assertEquals(100f, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child4.getLayoutX(), 0.0f); - assertEquals(0f, root_child4.getLayoutY(), 0.0f); - assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); - assertEquals(100f, root_child4.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(150f, root.getLayoutWidth(), 0.0f); - assertEquals(100f, root.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child1.getLayoutX(), 0.0f); - assertEquals(0f, root_child1.getLayoutY(), 0.0f); - assertEquals(0f, root_child1.getLayoutWidth(), 0.0f); - assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child2.getLayoutX(), 0.0f); - assertEquals(0f, root_child2.getLayoutY(), 0.0f); - assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); - assertEquals(100f, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child3.getLayoutX(), 0.0f); - assertEquals(0f, root_child3.getLayoutY(), 0.0f); - assertEquals(0f, root_child3.getLayoutWidth(), 0.0f); - assertEquals(100f, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child4.getLayoutX(), 0.0f); - assertEquals(0f, root_child4.getLayoutY(), 0.0f); - assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); - assertEquals(100f, root_child4.getLayoutHeight(), 0.0f); - } - - @Test - public void test_align_content_stretch_row_with_margin() { - final YogaNode root = new YogaNode(); - root.setFlexDirection(YogaFlexDirection.ROW); - root.setAlignContent(YogaAlign.STRETCH); - root.setWrap(YogaWrap.WRAP); - root.setWidth(150f); - root.setHeight(100f); - - final YogaNode root_child0 = new YogaNode(); - root_child0.setWidth(50f); - root.addChildAt(root_child0, 0); - - final YogaNode root_child1 = new YogaNode(); - root_child1.setMargin(YogaEdge.LEFT, 10f); - root_child1.setMargin(YogaEdge.TOP, 10f); - root_child1.setMargin(YogaEdge.RIGHT, 10f); - root_child1.setMargin(YogaEdge.BOTTOM, 10f); - root_child1.setWidth(50f); - root.addChildAt(root_child1, 1); - - final YogaNode root_child2 = new YogaNode(); - root_child2.setWidth(50f); - root.addChildAt(root_child2, 2); - - final YogaNode root_child3 = new YogaNode(); - root_child3.setMargin(YogaEdge.LEFT, 10f); - root_child3.setMargin(YogaEdge.TOP, 10f); - root_child3.setMargin(YogaEdge.RIGHT, 10f); - root_child3.setMargin(YogaEdge.BOTTOM, 10f); - root_child3.setWidth(50f); - root.addChildAt(root_child3, 3); - - final YogaNode root_child4 = new YogaNode(); - root_child4.setWidth(50f); - root.addChildAt(root_child4, 4); - root.setDirection(YogaDirection.LTR); - root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); - - assertEquals(0f, root.getLayoutX(), 0.0f); - assertEquals(0f, root.getLayoutY(), 0.0f); - assertEquals(150f, root.getLayoutWidth(), 0.0f); - assertEquals(100f, root.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(40f, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(60f, root_child1.getLayoutX(), 0.0f); - assertEquals(10f, root_child1.getLayoutY(), 0.0f); - assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); - assertEquals(20f, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child2.getLayoutX(), 0.0f); - assertEquals(40f, root_child2.getLayoutY(), 0.0f); - assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); - assertEquals(40f, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(60f, root_child3.getLayoutX(), 0.0f); - assertEquals(50f, root_child3.getLayoutY(), 0.0f); - assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); - assertEquals(20f, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child4.getLayoutX(), 0.0f); - assertEquals(80f, root_child4.getLayoutY(), 0.0f); - assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); - assertEquals(20f, root_child4.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(150f, root.getLayoutWidth(), 0.0f); - assertEquals(100f, root.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(40f, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(40f, root_child1.getLayoutX(), 0.0f); - assertEquals(10f, root_child1.getLayoutY(), 0.0f); - assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); - assertEquals(20f, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child2.getLayoutX(), 0.0f); - assertEquals(40f, root_child2.getLayoutY(), 0.0f); - assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); - assertEquals(40f, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(40f, root_child3.getLayoutX(), 0.0f); - assertEquals(50f, root_child3.getLayoutY(), 0.0f); - assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); - assertEquals(20f, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child4.getLayoutX(), 0.0f); - assertEquals(80f, root_child4.getLayoutY(), 0.0f); - assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); - assertEquals(20f, root_child4.getLayoutHeight(), 0.0f); - } - - @Test - public void test_align_content_stretch_row_with_padding() { - final YogaNode root = new YogaNode(); - root.setFlexDirection(YogaFlexDirection.ROW); - root.setAlignContent(YogaAlign.STRETCH); - root.setWrap(YogaWrap.WRAP); - root.setWidth(150f); - root.setHeight(100f); - - final YogaNode root_child0 = new YogaNode(); - root_child0.setWidth(50f); - root.addChildAt(root_child0, 0); - - final YogaNode root_child1 = new YogaNode(); - root_child1.setPadding(YogaEdge.LEFT, 10); - root_child1.setPadding(YogaEdge.TOP, 10); - root_child1.setPadding(YogaEdge.RIGHT, 10); - root_child1.setPadding(YogaEdge.BOTTOM, 10); - root_child1.setWidth(50f); - root.addChildAt(root_child1, 1); - - final YogaNode root_child2 = new YogaNode(); - root_child2.setWidth(50f); - root.addChildAt(root_child2, 2); - - final YogaNode root_child3 = new YogaNode(); - root_child3.setPadding(YogaEdge.LEFT, 10); - root_child3.setPadding(YogaEdge.TOP, 10); - root_child3.setPadding(YogaEdge.RIGHT, 10); - root_child3.setPadding(YogaEdge.BOTTOM, 10); - root_child3.setWidth(50f); - root.addChildAt(root_child3, 3); - - final YogaNode root_child4 = new YogaNode(); - root_child4.setWidth(50f); - root.addChildAt(root_child4, 4); - root.setDirection(YogaDirection.LTR); - root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); - - assertEquals(0f, root.getLayoutX(), 0.0f); - assertEquals(0f, root.getLayoutY(), 0.0f); - assertEquals(150f, root.getLayoutWidth(), 0.0f); - assertEquals(100f, root.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child1.getLayoutX(), 0.0f); - assertEquals(0f, root_child1.getLayoutY(), 0.0f); - assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child2.getLayoutX(), 0.0f); - assertEquals(0f, root_child2.getLayoutY(), 0.0f); - assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child3.getLayoutX(), 0.0f); - assertEquals(50f, root_child3.getLayoutY(), 0.0f); - assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child4.getLayoutX(), 0.0f); - assertEquals(50f, root_child4.getLayoutY(), 0.0f); - assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child4.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(150f, root.getLayoutWidth(), 0.0f); - assertEquals(100f, root.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child1.getLayoutX(), 0.0f); - assertEquals(0f, root_child1.getLayoutY(), 0.0f); - assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child2.getLayoutX(), 0.0f); - assertEquals(0f, root_child2.getLayoutY(), 0.0f); - assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child3.getLayoutX(), 0.0f); - assertEquals(50f, root_child3.getLayoutY(), 0.0f); - assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child4.getLayoutX(), 0.0f); - assertEquals(50f, root_child4.getLayoutY(), 0.0f); - assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child4.getLayoutHeight(), 0.0f); - } - - @Test - public void test_align_content_stretch_row_with_single_row() { - final YogaNode root = new YogaNode(); - root.setFlexDirection(YogaFlexDirection.ROW); - root.setAlignContent(YogaAlign.STRETCH); - root.setWrap(YogaWrap.WRAP); - root.setWidth(150f); - root.setHeight(100f); - - final YogaNode root_child0 = new YogaNode(); - root_child0.setWidth(50f); - root.addChildAt(root_child0, 0); - - final YogaNode root_child1 = new YogaNode(); - root_child1.setWidth(50f); - root.addChildAt(root_child1, 1); - root.setDirection(YogaDirection.LTR); - root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); - - assertEquals(0f, root.getLayoutX(), 0.0f); - assertEquals(0f, root.getLayoutY(), 0.0f); - assertEquals(150f, root.getLayoutWidth(), 0.0f); - assertEquals(100f, root.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child1.getLayoutX(), 0.0f); - assertEquals(0f, root_child1.getLayoutY(), 0.0f); - assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); - assertEquals(100f, root_child1.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(150f, root.getLayoutWidth(), 0.0f); - assertEquals(100f, root.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child1.getLayoutX(), 0.0f); - assertEquals(0f, root_child1.getLayoutY(), 0.0f); - assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); - assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); - } - - @Test - public void test_align_content_stretch_row_with_fixed_height() { - final YogaNode root = new YogaNode(); - root.setFlexDirection(YogaFlexDirection.ROW); - root.setAlignContent(YogaAlign.STRETCH); - root.setWrap(YogaWrap.WRAP); - root.setWidth(150f); - root.setHeight(100f); - - final YogaNode root_child0 = new YogaNode(); - root_child0.setWidth(50f); - root.addChildAt(root_child0, 0); - - final YogaNode root_child1 = new YogaNode(); - root_child1.setWidth(50f); - root_child1.setHeight(60f); - root.addChildAt(root_child1, 1); - - final YogaNode root_child2 = new YogaNode(); - root_child2.setWidth(50f); - root.addChildAt(root_child2, 2); - - final YogaNode root_child3 = new YogaNode(); - root_child3.setWidth(50f); - root.addChildAt(root_child3, 3); - - final YogaNode root_child4 = new YogaNode(); - root_child4.setWidth(50f); - root.addChildAt(root_child4, 4); - root.setDirection(YogaDirection.LTR); - root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); - - assertEquals(0f, root.getLayoutX(), 0.0f); - assertEquals(0f, root.getLayoutY(), 0.0f); - assertEquals(150f, root.getLayoutWidth(), 0.0f); - assertEquals(100f, root.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(80f, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child1.getLayoutX(), 0.0f); - assertEquals(0f, root_child1.getLayoutY(), 0.0f); - assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); - assertEquals(60f, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child2.getLayoutX(), 0.0f); - assertEquals(0f, root_child2.getLayoutY(), 0.0f); - assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); - assertEquals(80f, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child3.getLayoutX(), 0.0f); - assertEquals(80f, root_child3.getLayoutY(), 0.0f); - assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); - assertEquals(20f, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child4.getLayoutX(), 0.0f); - assertEquals(80f, root_child4.getLayoutY(), 0.0f); - assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); - assertEquals(20f, root_child4.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(150f, root.getLayoutWidth(), 0.0f); - assertEquals(100f, root.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(80f, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child1.getLayoutX(), 0.0f); - assertEquals(0f, root_child1.getLayoutY(), 0.0f); - assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); - assertEquals(60f, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child2.getLayoutX(), 0.0f); - assertEquals(0f, root_child2.getLayoutY(), 0.0f); - assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); - assertEquals(80f, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child3.getLayoutX(), 0.0f); - assertEquals(80f, root_child3.getLayoutY(), 0.0f); - assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); - assertEquals(20f, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child4.getLayoutX(), 0.0f); - assertEquals(80f, root_child4.getLayoutY(), 0.0f); - assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); - assertEquals(20f, root_child4.getLayoutHeight(), 0.0f); - } - - @Test - public void test_align_content_stretch_row_with_max_height() { - final YogaNode root = new YogaNode(); - root.setFlexDirection(YogaFlexDirection.ROW); - root.setAlignContent(YogaAlign.STRETCH); - root.setWrap(YogaWrap.WRAP); - root.setWidth(150f); - root.setHeight(100f); - - final YogaNode root_child0 = new YogaNode(); - root_child0.setWidth(50f); - root.addChildAt(root_child0, 0); - - final YogaNode root_child1 = new YogaNode(); - root_child1.setWidth(50f); - root_child1.setMaxHeight(20f); - root.addChildAt(root_child1, 1); - - final YogaNode root_child2 = new YogaNode(); - root_child2.setWidth(50f); - root.addChildAt(root_child2, 2); - - final YogaNode root_child3 = new YogaNode(); - root_child3.setWidth(50f); - root.addChildAt(root_child3, 3); - - final YogaNode root_child4 = new YogaNode(); - root_child4.setWidth(50f); - root.addChildAt(root_child4, 4); - root.setDirection(YogaDirection.LTR); - root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); - - assertEquals(0f, root.getLayoutX(), 0.0f); - assertEquals(0f, root.getLayoutY(), 0.0f); - assertEquals(150f, root.getLayoutWidth(), 0.0f); - assertEquals(100f, root.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child1.getLayoutX(), 0.0f); - assertEquals(0f, root_child1.getLayoutY(), 0.0f); - assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); - assertEquals(20f, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child2.getLayoutX(), 0.0f); - assertEquals(0f, root_child2.getLayoutY(), 0.0f); - assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child3.getLayoutX(), 0.0f); - assertEquals(50f, root_child3.getLayoutY(), 0.0f); - assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child4.getLayoutX(), 0.0f); - assertEquals(50f, root_child4.getLayoutY(), 0.0f); - assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child4.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(150f, root.getLayoutWidth(), 0.0f); - assertEquals(100f, root.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child1.getLayoutX(), 0.0f); - assertEquals(0f, root_child1.getLayoutY(), 0.0f); - assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); - assertEquals(20f, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child2.getLayoutX(), 0.0f); - assertEquals(0f, root_child2.getLayoutY(), 0.0f); - assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child3.getLayoutX(), 0.0f); - assertEquals(50f, root_child3.getLayoutY(), 0.0f); - assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child4.getLayoutX(), 0.0f); - assertEquals(50f, root_child4.getLayoutY(), 0.0f); - assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child4.getLayoutHeight(), 0.0f); - } - - @Test - public void test_align_content_stretch_row_with_min_height() { - final YogaNode root = new YogaNode(); - root.setFlexDirection(YogaFlexDirection.ROW); - root.setAlignContent(YogaAlign.STRETCH); - root.setWrap(YogaWrap.WRAP); - root.setWidth(150f); - root.setHeight(100f); - - final YogaNode root_child0 = new YogaNode(); - root_child0.setWidth(50f); - root.addChildAt(root_child0, 0); - - final YogaNode root_child1 = new YogaNode(); - root_child1.setWidth(50f); - root_child1.setMinHeight(80f); - root.addChildAt(root_child1, 1); - - final YogaNode root_child2 = new YogaNode(); - root_child2.setWidth(50f); - root.addChildAt(root_child2, 2); - - final YogaNode root_child3 = new YogaNode(); - root_child3.setWidth(50f); - root.addChildAt(root_child3, 3); - - final YogaNode root_child4 = new YogaNode(); - root_child4.setWidth(50f); - root.addChildAt(root_child4, 4); - root.setDirection(YogaDirection.LTR); - root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); - - assertEquals(0f, root.getLayoutX(), 0.0f); - assertEquals(0f, root.getLayoutY(), 0.0f); - assertEquals(150f, root.getLayoutWidth(), 0.0f); - assertEquals(100f, root.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(90f, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child1.getLayoutX(), 0.0f); - assertEquals(0f, root_child1.getLayoutY(), 0.0f); - assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); - assertEquals(90f, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child2.getLayoutX(), 0.0f); - assertEquals(0f, root_child2.getLayoutY(), 0.0f); - assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); - assertEquals(90f, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child3.getLayoutX(), 0.0f); - assertEquals(90f, root_child3.getLayoutY(), 0.0f); - assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); - assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child4.getLayoutX(), 0.0f); - assertEquals(90f, root_child4.getLayoutY(), 0.0f); - assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); - assertEquals(10f, root_child4.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(150f, root.getLayoutWidth(), 0.0f); - assertEquals(100f, root.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(90f, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child1.getLayoutX(), 0.0f); - assertEquals(0f, root_child1.getLayoutY(), 0.0f); - assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); - assertEquals(90f, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child2.getLayoutX(), 0.0f); - assertEquals(0f, root_child2.getLayoutY(), 0.0f); - assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); - assertEquals(90f, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(100f, root_child3.getLayoutX(), 0.0f); - assertEquals(90f, root_child3.getLayoutY(), 0.0f); - assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); - assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child4.getLayoutX(), 0.0f); - assertEquals(90f, root_child4.getLayoutY(), 0.0f); - assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); - assertEquals(10f, root_child4.getLayoutHeight(), 0.0f); - } - - @Test - public void test_align_content_stretch_column() { - final YogaNode root = new YogaNode(); - root.setAlignContent(YogaAlign.STRETCH); - root.setWrap(YogaWrap.WRAP); - root.setWidth(100f); - root.setHeight(150f); - - final YogaNode root_child0 = new YogaNode(); - root_child0.setHeight(50f); - root.addChildAt(root_child0, 0); - - final YogaNode root_child0_child0 = new YogaNode(); - root_child0_child0.setFlexGrow(1f); - root_child0_child0.setFlexShrink(1f); - root_child0_child0.setFlexBasisPercent(0f); - root_child0.addChildAt(root_child0_child0, 0); - - final YogaNode root_child1 = new YogaNode(); - root_child1.setFlexGrow(1f); - root_child1.setFlexShrink(1f); - root_child1.setFlexBasisPercent(0f); - root_child1.setHeight(50f); - root.addChildAt(root_child1, 1); - - final YogaNode root_child2 = new YogaNode(); - root_child2.setHeight(50f); - root.addChildAt(root_child2, 2); - - final YogaNode root_child3 = new YogaNode(); - root_child3.setHeight(50f); - root.addChildAt(root_child3, 3); - - final YogaNode root_child4 = new YogaNode(); - root_child4.setHeight(50f); - root.addChildAt(root_child4, 4); - root.setDirection(YogaDirection.LTR); - root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); - - assertEquals(0f, root.getLayoutX(), 0.0f); - assertEquals(0f, root.getLayoutY(), 0.0f); - assertEquals(100f, root.getLayoutWidth(), 0.0f); - assertEquals(150f, root.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child0_child0.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child1.getLayoutX(), 0.0f); - assertEquals(50f, root_child1.getLayoutY(), 0.0f); - assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); - assertEquals(0f, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child2.getLayoutX(), 0.0f); - assertEquals(50f, root_child2.getLayoutY(), 0.0f); - assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child3.getLayoutX(), 0.0f); - assertEquals(100f, root_child3.getLayoutY(), 0.0f); - assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child4.getLayoutX(), 0.0f); - assertEquals(0f, root_child4.getLayoutY(), 0.0f); - assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child4.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(100f, root.getLayoutWidth(), 0.0f); - assertEquals(150f, root.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); - assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child0_child0.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child1.getLayoutX(), 0.0f); - assertEquals(50f, root_child1.getLayoutY(), 0.0f); - assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); - assertEquals(0f, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child2.getLayoutX(), 0.0f); - assertEquals(50f, root_child2.getLayoutY(), 0.0f); - assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(50f, root_child3.getLayoutX(), 0.0f); - assertEquals(100f, root_child3.getLayoutY(), 0.0f); - assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child4.getLayoutX(), 0.0f); - assertEquals(0f, root_child4.getLayoutY(), 0.0f); - assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); - assertEquals(50f, root_child4.getLayoutHeight(), 0.0f); - } - } diff --git a/javascript/tests/Facebook.Yoga/YGAlignContentTest.js b/javascript/tests/Facebook.Yoga/YGAlignContentTest.js index d18fce9a..14cf9820 100644 --- a/javascript/tests/Facebook.Yoga/YGAlignContentTest.js +++ b/javascript/tests/Facebook.Yoga/YGAlignContentTest.js @@ -112,211 +112,12 @@ it("align_content_flex_start", function () { (typeof gc !== "undefined") && gc(); console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); }); -it("align_content_flex_start_without_height_on_children", function () { - var root = Yoga.Node.create(); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(100); - root.setHeight(100); - - var root_child0 = Yoga.Node.create(); - root_child0.setWidth(50); - root.insertChild(root_child0, 0); - - var root_child1 = Yoga.Node.create(); - root_child1.setWidth(50); - root_child1.setHeight(10); - root.insertChild(root_child1, 1); - - var root_child2 = Yoga.Node.create(); - root_child2.setWidth(50); - root.insertChild(root_child2, 2); - - var root_child3 = Yoga.Node.create(); - root_child3.setWidth(50); - root_child3.setHeight(10); - root.insertChild(root_child3, 3); - - var root_child4 = Yoga.Node.create(); - root_child4.setWidth(50); - root.insertChild(root_child4, 4); - 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(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); - console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - - console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); - console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(0 === root_child0.getComputedHeight(), "0 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - - console.assert(0 === root_child1.getComputedLeft(), "0 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); - console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); - console.assert(10 === root_child1.getComputedHeight(), "10 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - - console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(10 === root_child2.getComputedTop(), "10 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); - console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); - console.assert(0 === root_child2.getComputedHeight(), "0 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - - console.assert(0 === root_child3.getComputedLeft(), "0 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(10 === root_child3.getComputedTop(), "10 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); - console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); - console.assert(10 === root_child3.getComputedHeight(), "10 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - - console.assert(0 === root_child4.getComputedLeft(), "0 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(20 === root_child4.getComputedTop(), "20 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); - console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); - console.assert(0 === root_child4.getComputedHeight(), "0 === root_child4.getComputedHeight() (" + root_child4.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(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); - console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - - console.assert(50 === root_child0.getComputedLeft(), "50 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); - console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(0 === root_child0.getComputedHeight(), "0 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - - console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); - console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); - console.assert(10 === root_child1.getComputedHeight(), "10 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - - console.assert(50 === root_child2.getComputedLeft(), "50 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(10 === root_child2.getComputedTop(), "10 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); - console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); - console.assert(0 === root_child2.getComputedHeight(), "0 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - - console.assert(50 === root_child3.getComputedLeft(), "50 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(10 === root_child3.getComputedTop(), "10 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); - console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); - console.assert(10 === root_child3.getComputedHeight(), "10 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - - console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(20 === root_child4.getComputedTop(), "20 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); - console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); - console.assert(0 === root_child4.getComputedHeight(), "0 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); - - if (typeof root !== "undefined") - root.freeRecursive(); - - (typeof gc !== "undefined") && gc(); - console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); -}); -it("align_content_flex_start_with_flex", function () { - var root = Yoga.Node.create(); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(100); - root.setHeight(120); - - var root_child0 = Yoga.Node.create(); - root_child0.setFlexGrow(1); - root_child0.setFlexBasis("0%"); - root_child0.setWidth(50); - root.insertChild(root_child0, 0); - - var root_child1 = Yoga.Node.create(); - root_child1.setFlexGrow(1); - root_child1.setFlexBasis("0%"); - root_child1.setWidth(50); - root_child1.setHeight(10); - root.insertChild(root_child1, 1); - - var root_child2 = Yoga.Node.create(); - root_child2.setWidth(50); - root.insertChild(root_child2, 2); - - var root_child3 = Yoga.Node.create(); - root_child3.setFlexGrow(1); - root_child3.setFlexShrink(1); - root_child3.setFlexBasis("0%"); - root_child3.setWidth(50); - root.insertChild(root_child3, 3); - - var root_child4 = Yoga.Node.create(); - root_child4.setWidth(50); - root.insertChild(root_child4, 4); - 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(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); - console.assert(120 === root.getComputedHeight(), "120 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - - console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); - console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(40 === root_child0.getComputedHeight(), "40 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - - console.assert(0 === root_child1.getComputedLeft(), "0 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(40 === root_child1.getComputedTop(), "40 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); - console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); - console.assert(40 === root_child1.getComputedHeight(), "40 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - - console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(80 === root_child2.getComputedTop(), "80 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); - console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); - console.assert(0 === root_child2.getComputedHeight(), "0 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - - console.assert(0 === root_child3.getComputedLeft(), "0 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(80 === root_child3.getComputedTop(), "80 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); - console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); - console.assert(40 === root_child3.getComputedHeight(), "40 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - - console.assert(0 === root_child4.getComputedLeft(), "0 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(120 === root_child4.getComputedTop(), "120 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); - console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); - console.assert(0 === root_child4.getComputedHeight(), "0 === root_child4.getComputedHeight() (" + root_child4.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(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); - console.assert(120 === root.getComputedHeight(), "120 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - - console.assert(50 === root_child0.getComputedLeft(), "50 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); - console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(40 === root_child0.getComputedHeight(), "40 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - - console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(40 === root_child1.getComputedTop(), "40 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); - console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); - console.assert(40 === root_child1.getComputedHeight(), "40 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - - console.assert(50 === root_child2.getComputedLeft(), "50 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(80 === root_child2.getComputedTop(), "80 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); - console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); - console.assert(0 === root_child2.getComputedHeight(), "0 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - - console.assert(50 === root_child3.getComputedLeft(), "50 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(80 === root_child3.getComputedTop(), "80 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); - console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); - console.assert(40 === root_child3.getComputedHeight(), "40 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - - console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(120 === root_child4.getComputedTop(), "120 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); - console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); - console.assert(0 === root_child4.getComputedHeight(), "0 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); - - if (typeof root !== "undefined") - root.freeRecursive(); - - (typeof gc !== "undefined") && gc(); - console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); -}); it("align_content_flex_end", function () { var root = Yoga.Node.create(); + root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); root.setAlignContent(Yoga.ALIGN_FLEX_END); root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(100); + root.setWidth(130); root.setHeight(100); var root_child0 = Yoga.Node.create(); @@ -347,31 +148,31 @@ it("align_content_flex_end", function () { console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); - console.assert(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(130 === root.getComputedWidth(), "130 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(70 === root_child0.getComputedTop(), "70 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); console.assert(10 === root_child0.getComputedHeight(), "10 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - console.assert(0 === root_child1.getComputedLeft(), "0 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(10 === root_child1.getComputedTop(), "10 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(70 === root_child1.getComputedTop(), "70 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); console.assert(10 === root_child1.getComputedHeight(), "10 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(20 === root_child2.getComputedTop(), "20 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(80 === root_child2.getComputedTop(), "80 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); console.assert(10 === root_child2.getComputedHeight(), "10 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - console.assert(0 === root_child3.getComputedLeft(), "0 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(30 === root_child3.getComputedTop(), "30 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedLeft(), "50 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(80 === root_child3.getComputedTop(), "80 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); console.assert(10 === root_child3.getComputedHeight(), "10 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); console.assert(0 === root_child4.getComputedLeft(), "0 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(40 === root_child4.getComputedTop(), "40 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(90 === root_child4.getComputedTop(), "90 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); console.assert(10 === root_child4.getComputedHeight(), "10 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); @@ -379,31 +180,133 @@ it("align_content_flex_end", function () { console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); - console.assert(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(130 === root.getComputedWidth(), "130 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - console.assert(50 === root_child0.getComputedLeft(), "50 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(80 === root_child0.getComputedLeft(), "80 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(70 === root_child0.getComputedTop(), "70 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(10 === root_child0.getComputedHeight(), "10 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(30 === root_child1.getComputedLeft(), "30 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(70 === root_child1.getComputedTop(), "70 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(10 === root_child1.getComputedHeight(), "10 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + console.assert(80 === root_child2.getComputedLeft(), "80 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(80 === root_child2.getComputedTop(), "80 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); + console.assert(10 === root_child2.getComputedHeight(), "10 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + + console.assert(30 === root_child3.getComputedLeft(), "30 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(80 === root_child3.getComputedTop(), "80 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); + console.assert(10 === root_child3.getComputedHeight(), "10 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); + + console.assert(80 === root_child4.getComputedLeft(), "80 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(90 === root_child4.getComputedTop(), "90 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); + console.assert(10 === root_child4.getComputedHeight(), "10 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); + + if (typeof root !== "undefined") + root.freeRecursive(); + + (typeof gc !== "undefined") && gc(); + console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); +}); +it("align_content_center", function () { + var root = Yoga.Node.create(); + root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); + root.setAlignContent(Yoga.ALIGN_CENTER); + root.setFlexWrap(Yoga.WRAP_WRAP); + root.setWidth(130); + root.setHeight(100); + + var root_child0 = Yoga.Node.create(); + root_child0.setWidth(50); + root_child0.setHeight(10); + root.insertChild(root_child0, 0); + + var root_child1 = Yoga.Node.create(); + root_child1.setWidth(50); + root_child1.setHeight(10); + root.insertChild(root_child1, 1); + + var root_child2 = Yoga.Node.create(); + root_child2.setWidth(50); + root_child2.setHeight(10); + root.insertChild(root_child2, 2); + + var root_child3 = Yoga.Node.create(); + root_child3.setWidth(50); + root_child3.setHeight(10); + root.insertChild(root_child3, 3); + + var root_child4 = Yoga.Node.create(); + root_child4.setWidth(50); + root_child4.setHeight(10); + root.insertChild(root_child4, 4); + 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(130 === root.getComputedWidth(), "130 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(35 === root_child0.getComputedTop(), "35 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); console.assert(10 === root_child0.getComputedHeight(), "10 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(10 === root_child1.getComputedTop(), "10 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(35 === root_child1.getComputedTop(), "35 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); console.assert(10 === root_child1.getComputedHeight(), "10 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - console.assert(50 === root_child2.getComputedLeft(), "50 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(20 === root_child2.getComputedTop(), "20 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(45 === root_child2.getComputedTop(), "45 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); console.assert(10 === root_child2.getComputedHeight(), "10 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); console.assert(50 === root_child3.getComputedLeft(), "50 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(30 === root_child3.getComputedTop(), "30 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(45 === root_child3.getComputedTop(), "45 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); console.assert(10 === root_child3.getComputedHeight(), "10 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(40 === root_child4.getComputedTop(), "40 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(0 === root_child4.getComputedLeft(), "0 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(55 === root_child4.getComputedTop(), "55 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); + console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); + console.assert(10 === root_child4.getComputedHeight(), "10 === root_child4.getComputedHeight() (" + root_child4.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(130 === root.getComputedWidth(), "130 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(80 === root_child0.getComputedLeft(), "80 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(35 === root_child0.getComputedTop(), "35 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(10 === root_child0.getComputedHeight(), "10 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(30 === root_child1.getComputedLeft(), "30 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); + console.assert(35 === root_child1.getComputedTop(), "35 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); + console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); + console.assert(10 === root_child1.getComputedHeight(), "10 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); + + console.assert(80 === root_child2.getComputedLeft(), "80 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); + console.assert(45 === root_child2.getComputedTop(), "45 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); + console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); + console.assert(10 === root_child2.getComputedHeight(), "10 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); + + console.assert(30 === root_child3.getComputedLeft(), "30 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); + console.assert(45 === root_child3.getComputedTop(), "45 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); + console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); + console.assert(10 === root_child3.getComputedHeight(), "10 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); + + console.assert(80 === root_child4.getComputedLeft(), "80 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); + console.assert(55 === root_child4.getComputedTop(), "55 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); console.assert(10 === root_child4.getComputedHeight(), "10 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); @@ -713,1092 +616,3 @@ it("align_content_spacearound", function () { (typeof gc !== "undefined") && gc(); console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); }); -it("align_content_stretch_row", function () { - var root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignContent(Yoga.ALIGN_STRETCH); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(150); - root.setHeight(100); - - var root_child0 = Yoga.Node.create(); - root_child0.setWidth(50); - root.insertChild(root_child0, 0); - - var root_child1 = Yoga.Node.create(); - root_child1.setWidth(50); - root.insertChild(root_child1, 1); - - var root_child2 = Yoga.Node.create(); - root_child2.setWidth(50); - root.insertChild(root_child2, 2); - - var root_child3 = Yoga.Node.create(); - root_child3.setWidth(50); - root.insertChild(root_child3, 3); - - var root_child4 = Yoga.Node.create(); - root_child4.setWidth(50); - root.insertChild(root_child4, 4); - 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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); - console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - - console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); - console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(50 === root_child0.getComputedHeight(), "50 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - - console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); - console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); - console.assert(50 === root_child1.getComputedHeight(), "50 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - - console.assert(100 === root_child2.getComputedLeft(), "100 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); - console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); - console.assert(50 === root_child2.getComputedHeight(), "50 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - - console.assert(0 === root_child3.getComputedLeft(), "0 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(50 === root_child3.getComputedTop(), "50 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); - console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); - console.assert(50 === root_child3.getComputedHeight(), "50 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - - console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(50 === root_child4.getComputedTop(), "50 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); - console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); - console.assert(50 === root_child4.getComputedHeight(), "50 === root_child4.getComputedHeight() (" + root_child4.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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); - console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - - console.assert(100 === root_child0.getComputedLeft(), "100 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); - console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(50 === root_child0.getComputedHeight(), "50 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - - console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); - console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); - console.assert(50 === root_child1.getComputedHeight(), "50 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - - console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); - console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); - console.assert(50 === root_child2.getComputedHeight(), "50 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - - console.assert(100 === root_child3.getComputedLeft(), "100 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(50 === root_child3.getComputedTop(), "50 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); - console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); - console.assert(50 === root_child3.getComputedHeight(), "50 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - - console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(50 === root_child4.getComputedTop(), "50 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); - console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); - console.assert(50 === root_child4.getComputedHeight(), "50 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); - - if (typeof root !== "undefined") - root.freeRecursive(); - - (typeof gc !== "undefined") && gc(); - console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); -}); -it("align_content_stretch_row_with_children", function () { - var root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignContent(Yoga.ALIGN_STRETCH); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(150); - root.setHeight(100); - - var root_child0 = Yoga.Node.create(); - root_child0.setWidth(50); - root.insertChild(root_child0, 0); - - var root_child0_child0 = Yoga.Node.create(); - root_child0_child0.setFlexGrow(1); - root_child0_child0.setFlexShrink(1); - root_child0_child0.setFlexBasis("0%"); - root_child0.insertChild(root_child0_child0, 0); - - var root_child1 = Yoga.Node.create(); - root_child1.setWidth(50); - root.insertChild(root_child1, 1); - - var root_child2 = Yoga.Node.create(); - root_child2.setWidth(50); - root.insertChild(root_child2, 2); - - var root_child3 = Yoga.Node.create(); - root_child3.setWidth(50); - root.insertChild(root_child3, 3); - - var root_child4 = Yoga.Node.create(); - root_child4.setWidth(50); - root.insertChild(root_child4, 4); - 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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); - console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - - console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); - console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(50 === root_child0.getComputedHeight(), "50 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - - console.assert(0 === root_child0_child0.getComputedLeft(), "0 === 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(50 === root_child0_child0.getComputedWidth(), "50 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")"); - console.assert(50 === root_child0_child0.getComputedHeight(), "50 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")"); - - console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); - console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); - console.assert(50 === root_child1.getComputedHeight(), "50 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - - console.assert(100 === root_child2.getComputedLeft(), "100 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); - console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); - console.assert(50 === root_child2.getComputedHeight(), "50 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - - console.assert(0 === root_child3.getComputedLeft(), "0 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(50 === root_child3.getComputedTop(), "50 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); - console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); - console.assert(50 === root_child3.getComputedHeight(), "50 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - - console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(50 === root_child4.getComputedTop(), "50 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); - console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); - console.assert(50 === root_child4.getComputedHeight(), "50 === root_child4.getComputedHeight() (" + root_child4.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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); - console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - - console.assert(100 === root_child0.getComputedLeft(), "100 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); - console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(50 === root_child0.getComputedHeight(), "50 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - - console.assert(0 === root_child0_child0.getComputedLeft(), "0 === 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(50 === root_child0_child0.getComputedWidth(), "50 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")"); - console.assert(50 === root_child0_child0.getComputedHeight(), "50 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")"); - - console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); - console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); - console.assert(50 === root_child1.getComputedHeight(), "50 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - - console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); - console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); - console.assert(50 === root_child2.getComputedHeight(), "50 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - - console.assert(100 === root_child3.getComputedLeft(), "100 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(50 === root_child3.getComputedTop(), "50 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); - console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); - console.assert(50 === root_child3.getComputedHeight(), "50 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - - console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(50 === root_child4.getComputedTop(), "50 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); - console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); - console.assert(50 === root_child4.getComputedHeight(), "50 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); - - if (typeof root !== "undefined") - root.freeRecursive(); - - (typeof gc !== "undefined") && gc(); - console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); -}); -it("align_content_stretch_row_with_flex", function () { - var root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignContent(Yoga.ALIGN_STRETCH); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(150); - root.setHeight(100); - - var root_child0 = Yoga.Node.create(); - root_child0.setWidth(50); - root.insertChild(root_child0, 0); - - var root_child1 = Yoga.Node.create(); - root_child1.setFlexGrow(1); - root_child1.setFlexShrink(1); - root_child1.setFlexBasis("0%"); - root_child1.setWidth(50); - root.insertChild(root_child1, 1); - - var root_child2 = Yoga.Node.create(); - root_child2.setWidth(50); - root.insertChild(root_child2, 2); - - var root_child3 = Yoga.Node.create(); - root_child3.setFlexGrow(1); - root_child3.setFlexShrink(1); - root_child3.setFlexBasis("0%"); - root_child3.setWidth(50); - root.insertChild(root_child3, 3); - - var root_child4 = Yoga.Node.create(); - root_child4.setWidth(50); - root.insertChild(root_child4, 4); - 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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); - console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - - console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); - console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(100 === root_child0.getComputedHeight(), "100 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - - console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); - console.assert(0 === root_child1.getComputedWidth(), "0 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); - console.assert(100 === root_child1.getComputedHeight(), "100 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - - console.assert(50 === root_child2.getComputedLeft(), "50 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); - console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); - console.assert(100 === root_child2.getComputedHeight(), "100 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - - console.assert(100 === root_child3.getComputedLeft(), "100 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(0 === root_child3.getComputedTop(), "0 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); - console.assert(0 === root_child3.getComputedWidth(), "0 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); - console.assert(100 === root_child3.getComputedHeight(), "100 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - - console.assert(100 === root_child4.getComputedLeft(), "100 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(0 === root_child4.getComputedTop(), "0 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); - console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); - console.assert(100 === root_child4.getComputedHeight(), "100 === root_child4.getComputedHeight() (" + root_child4.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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); - console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - - console.assert(100 === root_child0.getComputedLeft(), "100 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); - console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(100 === root_child0.getComputedHeight(), "100 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - - console.assert(100 === root_child1.getComputedLeft(), "100 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); - console.assert(0 === root_child1.getComputedWidth(), "0 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); - console.assert(100 === root_child1.getComputedHeight(), "100 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - - console.assert(50 === root_child2.getComputedLeft(), "50 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); - console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); - console.assert(100 === root_child2.getComputedHeight(), "100 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - - console.assert(50 === root_child3.getComputedLeft(), "50 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(0 === root_child3.getComputedTop(), "0 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); - console.assert(0 === root_child3.getComputedWidth(), "0 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); - console.assert(100 === root_child3.getComputedHeight(), "100 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - - console.assert(0 === root_child4.getComputedLeft(), "0 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(0 === root_child4.getComputedTop(), "0 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); - console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); - console.assert(100 === root_child4.getComputedHeight(), "100 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); - - if (typeof root !== "undefined") - root.freeRecursive(); - - (typeof gc !== "undefined") && gc(); - console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); -}); -it("align_content_stretch_row_with_flex_no_shrink", function () { - var root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignContent(Yoga.ALIGN_STRETCH); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(150); - root.setHeight(100); - - var root_child0 = Yoga.Node.create(); - root_child0.setWidth(50); - root.insertChild(root_child0, 0); - - var root_child1 = Yoga.Node.create(); - root_child1.setFlexGrow(1); - root_child1.setFlexShrink(1); - root_child1.setFlexBasis("0%"); - root_child1.setWidth(50); - root.insertChild(root_child1, 1); - - var root_child2 = Yoga.Node.create(); - root_child2.setWidth(50); - root.insertChild(root_child2, 2); - - var root_child3 = Yoga.Node.create(); - root_child3.setFlexGrow(1); - root_child3.setFlexBasis("0%"); - root_child3.setWidth(50); - root.insertChild(root_child3, 3); - - var root_child4 = Yoga.Node.create(); - root_child4.setWidth(50); - root.insertChild(root_child4, 4); - 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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); - console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - - console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); - console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(100 === root_child0.getComputedHeight(), "100 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - - console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); - console.assert(0 === root_child1.getComputedWidth(), "0 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); - console.assert(100 === root_child1.getComputedHeight(), "100 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - - console.assert(50 === root_child2.getComputedLeft(), "50 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); - console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); - console.assert(100 === root_child2.getComputedHeight(), "100 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - - console.assert(100 === root_child3.getComputedLeft(), "100 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(0 === root_child3.getComputedTop(), "0 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); - console.assert(0 === root_child3.getComputedWidth(), "0 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); - console.assert(100 === root_child3.getComputedHeight(), "100 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - - console.assert(100 === root_child4.getComputedLeft(), "100 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(0 === root_child4.getComputedTop(), "0 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); - console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); - console.assert(100 === root_child4.getComputedHeight(), "100 === root_child4.getComputedHeight() (" + root_child4.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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); - console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - - console.assert(100 === root_child0.getComputedLeft(), "100 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); - console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(100 === root_child0.getComputedHeight(), "100 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - - console.assert(100 === root_child1.getComputedLeft(), "100 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); - console.assert(0 === root_child1.getComputedWidth(), "0 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); - console.assert(100 === root_child1.getComputedHeight(), "100 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - - console.assert(50 === root_child2.getComputedLeft(), "50 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); - console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); - console.assert(100 === root_child2.getComputedHeight(), "100 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - - console.assert(50 === root_child3.getComputedLeft(), "50 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(0 === root_child3.getComputedTop(), "0 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); - console.assert(0 === root_child3.getComputedWidth(), "0 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); - console.assert(100 === root_child3.getComputedHeight(), "100 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - - console.assert(0 === root_child4.getComputedLeft(), "0 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(0 === root_child4.getComputedTop(), "0 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); - console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); - console.assert(100 === root_child4.getComputedHeight(), "100 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); - - if (typeof root !== "undefined") - root.freeRecursive(); - - (typeof gc !== "undefined") && gc(); - console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); -}); -it("align_content_stretch_row_with_margin", function () { - var root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignContent(Yoga.ALIGN_STRETCH); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(150); - root.setHeight(100); - - var root_child0 = Yoga.Node.create(); - root_child0.setWidth(50); - root.insertChild(root_child0, 0); - - var root_child1 = Yoga.Node.create(); - root_child1.setMargin(Yoga.EDGE_LEFT, 10); - root_child1.setMargin(Yoga.EDGE_TOP, 10); - root_child1.setMargin(Yoga.EDGE_RIGHT, 10); - root_child1.setMargin(Yoga.EDGE_BOTTOM, 10); - root_child1.setWidth(50); - root.insertChild(root_child1, 1); - - var root_child2 = Yoga.Node.create(); - root_child2.setWidth(50); - root.insertChild(root_child2, 2); - - var root_child3 = Yoga.Node.create(); - root_child3.setMargin(Yoga.EDGE_LEFT, 10); - root_child3.setMargin(Yoga.EDGE_TOP, 10); - root_child3.setMargin(Yoga.EDGE_RIGHT, 10); - root_child3.setMargin(Yoga.EDGE_BOTTOM, 10); - root_child3.setWidth(50); - root.insertChild(root_child3, 3); - - var root_child4 = Yoga.Node.create(); - root_child4.setWidth(50); - root.insertChild(root_child4, 4); - 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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); - console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - - console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); - console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(40 === root_child0.getComputedHeight(), "40 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - - console.assert(60 === root_child1.getComputedLeft(), "60 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(10 === root_child1.getComputedTop(), "10 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); - console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); - console.assert(20 === root_child1.getComputedHeight(), "20 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - - console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(40 === root_child2.getComputedTop(), "40 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); - console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); - console.assert(40 === root_child2.getComputedHeight(), "40 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - - console.assert(60 === root_child3.getComputedLeft(), "60 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(50 === root_child3.getComputedTop(), "50 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); - console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); - console.assert(20 === root_child3.getComputedHeight(), "20 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - - console.assert(0 === root_child4.getComputedLeft(), "0 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(80 === root_child4.getComputedTop(), "80 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); - console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); - console.assert(20 === root_child4.getComputedHeight(), "20 === root_child4.getComputedHeight() (" + root_child4.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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); - console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - - console.assert(100 === root_child0.getComputedLeft(), "100 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); - console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(40 === root_child0.getComputedHeight(), "40 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - - console.assert(40 === root_child1.getComputedLeft(), "40 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(10 === root_child1.getComputedTop(), "10 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); - console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); - console.assert(20 === root_child1.getComputedHeight(), "20 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - - console.assert(100 === root_child2.getComputedLeft(), "100 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(40 === root_child2.getComputedTop(), "40 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); - console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); - console.assert(40 === root_child2.getComputedHeight(), "40 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - - console.assert(40 === root_child3.getComputedLeft(), "40 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(50 === root_child3.getComputedTop(), "50 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); - console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); - console.assert(20 === root_child3.getComputedHeight(), "20 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - - console.assert(100 === root_child4.getComputedLeft(), "100 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(80 === root_child4.getComputedTop(), "80 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); - console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); - console.assert(20 === root_child4.getComputedHeight(), "20 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); - - if (typeof root !== "undefined") - root.freeRecursive(); - - (typeof gc !== "undefined") && gc(); - console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); -}); -it("align_content_stretch_row_with_padding", function () { - var root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignContent(Yoga.ALIGN_STRETCH); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(150); - root.setHeight(100); - - var root_child0 = Yoga.Node.create(); - root_child0.setWidth(50); - root.insertChild(root_child0, 0); - - var root_child1 = Yoga.Node.create(); - root_child1.setPadding(Yoga.EDGE_LEFT, 10); - root_child1.setPadding(Yoga.EDGE_TOP, 10); - root_child1.setPadding(Yoga.EDGE_RIGHT, 10); - root_child1.setPadding(Yoga.EDGE_BOTTOM, 10); - root_child1.setWidth(50); - root.insertChild(root_child1, 1); - - var root_child2 = Yoga.Node.create(); - root_child2.setWidth(50); - root.insertChild(root_child2, 2); - - var root_child3 = Yoga.Node.create(); - root_child3.setPadding(Yoga.EDGE_LEFT, 10); - root_child3.setPadding(Yoga.EDGE_TOP, 10); - root_child3.setPadding(Yoga.EDGE_RIGHT, 10); - root_child3.setPadding(Yoga.EDGE_BOTTOM, 10); - root_child3.setWidth(50); - root.insertChild(root_child3, 3); - - var root_child4 = Yoga.Node.create(); - root_child4.setWidth(50); - root.insertChild(root_child4, 4); - 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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); - console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - - console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); - console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(50 === root_child0.getComputedHeight(), "50 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - - console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); - console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); - console.assert(50 === root_child1.getComputedHeight(), "50 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - - console.assert(100 === root_child2.getComputedLeft(), "100 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); - console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); - console.assert(50 === root_child2.getComputedHeight(), "50 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - - console.assert(0 === root_child3.getComputedLeft(), "0 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(50 === root_child3.getComputedTop(), "50 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); - console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); - console.assert(50 === root_child3.getComputedHeight(), "50 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - - console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(50 === root_child4.getComputedTop(), "50 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); - console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); - console.assert(50 === root_child4.getComputedHeight(), "50 === root_child4.getComputedHeight() (" + root_child4.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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); - console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - - console.assert(100 === root_child0.getComputedLeft(), "100 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); - console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(50 === root_child0.getComputedHeight(), "50 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - - console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); - console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); - console.assert(50 === root_child1.getComputedHeight(), "50 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - - console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); - console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); - console.assert(50 === root_child2.getComputedHeight(), "50 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - - console.assert(100 === root_child3.getComputedLeft(), "100 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(50 === root_child3.getComputedTop(), "50 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); - console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); - console.assert(50 === root_child3.getComputedHeight(), "50 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - - console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(50 === root_child4.getComputedTop(), "50 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); - console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); - console.assert(50 === root_child4.getComputedHeight(), "50 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); - - if (typeof root !== "undefined") - root.freeRecursive(); - - (typeof gc !== "undefined") && gc(); - console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); -}); -it("align_content_stretch_row_with_single_row", function () { - var root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignContent(Yoga.ALIGN_STRETCH); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(150); - root.setHeight(100); - - var root_child0 = Yoga.Node.create(); - root_child0.setWidth(50); - root.insertChild(root_child0, 0); - - var root_child1 = Yoga.Node.create(); - root_child1.setWidth(50); - root.insertChild(root_child1, 1); - 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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); - console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - - console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); - console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(100 === root_child0.getComputedHeight(), "100 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - - console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); - console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); - console.assert(100 === root_child1.getComputedHeight(), "100 === root_child1.getComputedHeight() (" + root_child1.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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); - console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - - console.assert(100 === root_child0.getComputedLeft(), "100 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); - console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(100 === root_child0.getComputedHeight(), "100 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - - console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); - console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); - console.assert(100 === root_child1.getComputedHeight(), "100 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - - if (typeof root !== "undefined") - root.freeRecursive(); - - (typeof gc !== "undefined") && gc(); - console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); -}); -it("align_content_stretch_row_with_fixed_height", function () { - var root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignContent(Yoga.ALIGN_STRETCH); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(150); - root.setHeight(100); - - var root_child0 = Yoga.Node.create(); - root_child0.setWidth(50); - root.insertChild(root_child0, 0); - - var root_child1 = Yoga.Node.create(); - root_child1.setWidth(50); - root_child1.setHeight(60); - root.insertChild(root_child1, 1); - - var root_child2 = Yoga.Node.create(); - root_child2.setWidth(50); - root.insertChild(root_child2, 2); - - var root_child3 = Yoga.Node.create(); - root_child3.setWidth(50); - root.insertChild(root_child3, 3); - - var root_child4 = Yoga.Node.create(); - root_child4.setWidth(50); - root.insertChild(root_child4, 4); - 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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); - console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - - console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); - console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(80 === root_child0.getComputedHeight(), "80 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - - console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); - console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); - console.assert(60 === root_child1.getComputedHeight(), "60 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - - console.assert(100 === root_child2.getComputedLeft(), "100 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); - console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); - console.assert(80 === root_child2.getComputedHeight(), "80 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - - console.assert(0 === root_child3.getComputedLeft(), "0 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(80 === root_child3.getComputedTop(), "80 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); - console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); - console.assert(20 === root_child3.getComputedHeight(), "20 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - - console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(80 === root_child4.getComputedTop(), "80 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); - console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); - console.assert(20 === root_child4.getComputedHeight(), "20 === root_child4.getComputedHeight() (" + root_child4.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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); - console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - - console.assert(100 === root_child0.getComputedLeft(), "100 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); - console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(80 === root_child0.getComputedHeight(), "80 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - - console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); - console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); - console.assert(60 === root_child1.getComputedHeight(), "60 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - - console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); - console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); - console.assert(80 === root_child2.getComputedHeight(), "80 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - - console.assert(100 === root_child3.getComputedLeft(), "100 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(80 === root_child3.getComputedTop(), "80 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); - console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); - console.assert(20 === root_child3.getComputedHeight(), "20 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - - console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(80 === root_child4.getComputedTop(), "80 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); - console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); - console.assert(20 === root_child4.getComputedHeight(), "20 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); - - if (typeof root !== "undefined") - root.freeRecursive(); - - (typeof gc !== "undefined") && gc(); - console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); -}); -it("align_content_stretch_row_with_max_height", function () { - var root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignContent(Yoga.ALIGN_STRETCH); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(150); - root.setHeight(100); - - var root_child0 = Yoga.Node.create(); - root_child0.setWidth(50); - root.insertChild(root_child0, 0); - - var root_child1 = Yoga.Node.create(); - root_child1.setWidth(50); - root_child1.setMaxHeight(20); - root.insertChild(root_child1, 1); - - var root_child2 = Yoga.Node.create(); - root_child2.setWidth(50); - root.insertChild(root_child2, 2); - - var root_child3 = Yoga.Node.create(); - root_child3.setWidth(50); - root.insertChild(root_child3, 3); - - var root_child4 = Yoga.Node.create(); - root_child4.setWidth(50); - root.insertChild(root_child4, 4); - 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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); - console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - - console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); - console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(50 === root_child0.getComputedHeight(), "50 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - - console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); - console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); - console.assert(20 === root_child1.getComputedHeight(), "20 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - - console.assert(100 === root_child2.getComputedLeft(), "100 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); - console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); - console.assert(50 === root_child2.getComputedHeight(), "50 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - - console.assert(0 === root_child3.getComputedLeft(), "0 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(50 === root_child3.getComputedTop(), "50 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); - console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); - console.assert(50 === root_child3.getComputedHeight(), "50 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - - console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(50 === root_child4.getComputedTop(), "50 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); - console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); - console.assert(50 === root_child4.getComputedHeight(), "50 === root_child4.getComputedHeight() (" + root_child4.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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); - console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - - console.assert(100 === root_child0.getComputedLeft(), "100 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); - console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(50 === root_child0.getComputedHeight(), "50 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - - console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); - console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); - console.assert(20 === root_child1.getComputedHeight(), "20 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - - console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); - console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); - console.assert(50 === root_child2.getComputedHeight(), "50 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - - console.assert(100 === root_child3.getComputedLeft(), "100 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(50 === root_child3.getComputedTop(), "50 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); - console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); - console.assert(50 === root_child3.getComputedHeight(), "50 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - - console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(50 === root_child4.getComputedTop(), "50 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); - console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); - console.assert(50 === root_child4.getComputedHeight(), "50 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); - - if (typeof root !== "undefined") - root.freeRecursive(); - - (typeof gc !== "undefined") && gc(); - console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); -}); -it("align_content_stretch_row_with_min_height", function () { - var root = Yoga.Node.create(); - root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); - root.setAlignContent(Yoga.ALIGN_STRETCH); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(150); - root.setHeight(100); - - var root_child0 = Yoga.Node.create(); - root_child0.setWidth(50); - root.insertChild(root_child0, 0); - - var root_child1 = Yoga.Node.create(); - root_child1.setWidth(50); - root_child1.setMinHeight(80); - root.insertChild(root_child1, 1); - - var root_child2 = Yoga.Node.create(); - root_child2.setWidth(50); - root.insertChild(root_child2, 2); - - var root_child3 = Yoga.Node.create(); - root_child3.setWidth(50); - root.insertChild(root_child3, 3); - - var root_child4 = Yoga.Node.create(); - root_child4.setWidth(50); - root.insertChild(root_child4, 4); - 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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); - console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - - console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); - console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(90 === root_child0.getComputedHeight(), "90 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - - console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); - console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); - console.assert(90 === root_child1.getComputedHeight(), "90 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - - console.assert(100 === root_child2.getComputedLeft(), "100 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); - console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); - console.assert(90 === root_child2.getComputedHeight(), "90 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - - console.assert(0 === root_child3.getComputedLeft(), "0 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(90 === root_child3.getComputedTop(), "90 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); - console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); - console.assert(10 === root_child3.getComputedHeight(), "10 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - - console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(90 === root_child4.getComputedTop(), "90 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); - console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); - console.assert(10 === root_child4.getComputedHeight(), "10 === root_child4.getComputedHeight() (" + root_child4.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(150 === root.getComputedWidth(), "150 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); - console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - - console.assert(100 === root_child0.getComputedLeft(), "100 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); - console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(90 === root_child0.getComputedHeight(), "90 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - - console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); - console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); - console.assert(90 === root_child1.getComputedHeight(), "90 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - - console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); - console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); - console.assert(90 === root_child2.getComputedHeight(), "90 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - - console.assert(100 === root_child3.getComputedLeft(), "100 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(90 === root_child3.getComputedTop(), "90 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); - console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); - console.assert(10 === root_child3.getComputedHeight(), "10 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - - console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(90 === root_child4.getComputedTop(), "90 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); - console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); - console.assert(10 === root_child4.getComputedHeight(), "10 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); - - if (typeof root !== "undefined") - root.freeRecursive(); - - (typeof gc !== "undefined") && gc(); - console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); -}); -it("align_content_stretch_column", function () { - var root = Yoga.Node.create(); - root.setAlignContent(Yoga.ALIGN_STRETCH); - root.setFlexWrap(Yoga.WRAP_WRAP); - root.setWidth(100); - root.setHeight(150); - - var root_child0 = Yoga.Node.create(); - root_child0.setHeight(50); - root.insertChild(root_child0, 0); - - var root_child0_child0 = Yoga.Node.create(); - root_child0_child0.setFlexGrow(1); - root_child0_child0.setFlexShrink(1); - root_child0_child0.setFlexBasis("0%"); - root_child0.insertChild(root_child0_child0, 0); - - var root_child1 = Yoga.Node.create(); - root_child1.setFlexGrow(1); - root_child1.setFlexShrink(1); - root_child1.setFlexBasis("0%"); - root_child1.setHeight(50); - root.insertChild(root_child1, 1); - - var root_child2 = Yoga.Node.create(); - root_child2.setHeight(50); - root.insertChild(root_child2, 2); - - var root_child3 = Yoga.Node.create(); - root_child3.setHeight(50); - root.insertChild(root_child3, 3); - - var root_child4 = Yoga.Node.create(); - root_child4.setHeight(50); - root.insertChild(root_child4, 4); - 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(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); - console.assert(150 === root.getComputedHeight(), "150 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - - console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); - console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(50 === root_child0.getComputedHeight(), "50 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - - console.assert(0 === root_child0_child0.getComputedLeft(), "0 === 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(50 === root_child0_child0.getComputedWidth(), "50 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")"); - console.assert(50 === root_child0_child0.getComputedHeight(), "50 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")"); - - console.assert(0 === root_child1.getComputedLeft(), "0 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(50 === root_child1.getComputedTop(), "50 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); - console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); - console.assert(0 === root_child1.getComputedHeight(), "0 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - - console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(50 === root_child2.getComputedTop(), "50 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); - console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); - console.assert(50 === root_child2.getComputedHeight(), "50 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - - console.assert(0 === root_child3.getComputedLeft(), "0 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(100 === root_child3.getComputedTop(), "100 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); - console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); - console.assert(50 === root_child3.getComputedHeight(), "50 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - - console.assert(50 === root_child4.getComputedLeft(), "50 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(0 === root_child4.getComputedTop(), "0 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); - console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); - console.assert(50 === root_child4.getComputedHeight(), "50 === root_child4.getComputedHeight() (" + root_child4.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(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); - console.assert(150 === root.getComputedHeight(), "150 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - - console.assert(50 === root_child0.getComputedLeft(), "50 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); - console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(50 === root_child0.getComputedHeight(), "50 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - - console.assert(0 === root_child0_child0.getComputedLeft(), "0 === 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(50 === root_child0_child0.getComputedWidth(), "50 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")"); - console.assert(50 === root_child0_child0.getComputedHeight(), "50 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")"); - - console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")"); - console.assert(50 === root_child1.getComputedTop(), "50 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")"); - console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")"); - console.assert(0 === root_child1.getComputedHeight(), "0 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")"); - - console.assert(50 === root_child2.getComputedLeft(), "50 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")"); - console.assert(50 === root_child2.getComputedTop(), "50 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")"); - console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")"); - console.assert(50 === root_child2.getComputedHeight(), "50 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")"); - - console.assert(50 === root_child3.getComputedLeft(), "50 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")"); - console.assert(100 === root_child3.getComputedTop(), "100 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")"); - console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")"); - console.assert(50 === root_child3.getComputedHeight(), "50 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")"); - - console.assert(0 === root_child4.getComputedLeft(), "0 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")"); - console.assert(0 === root_child4.getComputedTop(), "0 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")"); - console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")"); - console.assert(50 === root_child4.getComputedHeight(), "50 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")"); - - if (typeof root !== "undefined") - root.freeRecursive(); - - (typeof gc !== "undefined") && gc(); - console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")"); -}); diff --git a/tests/YGAlignContentTest.cpp b/tests/YGAlignContentTest.cpp index d6dac67a..2061af12 100644 --- a/tests/YGAlignContentTest.cpp +++ b/tests/YGAlignContentTest.cpp @@ -110,205 +110,12 @@ TEST(YogaTest, align_content_flex_start) { YGNodeFreeRecursive(root); } -TEST(YogaTest, align_content_flex_start_without_height_on_children) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNew(); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNew(); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNew(); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeStyleSetHeight(root_child3, 10); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNew(); - YGNodeStyleSetWidth(root_child4, 50); - YGNodeInsertChild(root, root_child4, 4); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child4)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, align_content_flex_start_with_flex) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 120); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexBasisPercent(root_child0, 0); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNew(); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeStyleSetFlexBasisPercent(root_child1, 0); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNew(); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNew(); - YGNodeStyleSetFlexGrow(root_child3, 1); - YGNodeStyleSetFlexShrink(root_child3, 1); - YGNodeStyleSetFlexBasisPercent(root_child3, 0); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNew(); - YGNodeStyleSetWidth(root_child4, 50); - YGNodeInsertChild(root, root_child4, 4); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(120, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(120, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child4)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(120, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(120, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); -} - TEST(YogaTest, align_content_flex_end) { const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); YGNodeStyleSetAlignContent(root, YGAlignFlexEnd); YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetWidth(root, 130); YGNodeStyleSetHeight(root, 100); const YGNodeRef root_child0 = YGNodeNew(); @@ -339,31 +146,31 @@ TEST(YogaTest, align_content_flex_end) { ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(130, YGNodeLayoutGetWidth(root)); ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(70, YGNodeLayoutGetTop(root_child0)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(70, YGNodeLayoutGetTop(root_child1)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child2)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child3)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetTop(root_child4)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); @@ -371,31 +178,130 @@ TEST(YogaTest, align_content_flex_end) { ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(130, YGNodeLayoutGetWidth(root)); ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(70, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(70, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, align_content_center) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetAlignContent(root, YGAlignCenter); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + YGNodeStyleSetWidth(root, 130); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetWidth(root_child1, 50); + YGNodeStyleSetHeight(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 50); + YGNodeStyleSetHeight(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + + const YGNodeRef root_child3 = YGNodeNew(); + YGNodeStyleSetWidth(root_child3, 50); + YGNodeStyleSetHeight(root_child3, 10); + YGNodeInsertChild(root, root_child3, 3); + + const YGNodeRef root_child4 = YGNodeNew(); + YGNodeStyleSetWidth(root_child4, 50); + YGNodeStyleSetHeight(root_child4, 10); + YGNodeInsertChild(root, root_child4, 4); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(130, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(35, YGNodeLayoutGetTop(root_child0)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(35, YGNodeLayoutGetTop(root_child1)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(45, YGNodeLayoutGetTop(root_child2)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(45, YGNodeLayoutGetTop(root_child3)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(55, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(130, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(35, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(35, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(45, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(45, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(55, YGNodeLayoutGetTop(root_child4)); ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); @@ -692,1059 +598,3 @@ TEST(YogaTest, align_content_spacearound) { YGNodeFreeRecursive(root); } - -TEST(YogaTest, align_content_stretch_row) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root, YGAlignStretch); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 150); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNew(); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNew(); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNew(); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNew(); - YGNodeStyleSetWidth(root_child4, 50); - YGNodeInsertChild(root, root_child4, 4); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, align_content_stretch_row_with_children) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root, YGAlignStretch); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 150); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNew(); - YGNodeStyleSetFlexGrow(root_child0_child0, 1); - YGNodeStyleSetFlexShrink(root_child0_child0, 1); - YGNodeStyleSetFlexBasisPercent(root_child0_child0, 0); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - const YGNodeRef root_child1 = YGNodeNew(); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNew(); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNew(); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNew(); - YGNodeStyleSetWidth(root_child4, 50); - YGNodeInsertChild(root, root_child4, 4); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, align_content_stretch_row_with_flex) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root, YGAlignStretch); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 150); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNew(); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeStyleSetFlexShrink(root_child1, 1); - YGNodeStyleSetFlexBasisPercent(root_child1, 0); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNew(); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNew(); - YGNodeStyleSetFlexGrow(root_child3, 1); - YGNodeStyleSetFlexShrink(root_child3, 1); - YGNodeStyleSetFlexBasisPercent(root_child3, 0); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNew(); - YGNodeStyleSetWidth(root_child4, 50); - YGNodeInsertChild(root, root_child4, 4); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child4)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, align_content_stretch_row_with_flex_no_shrink) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root, YGAlignStretch); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 150); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNew(); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeStyleSetFlexShrink(root_child1, 1); - YGNodeStyleSetFlexBasisPercent(root_child1, 0); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNew(); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNew(); - YGNodeStyleSetFlexGrow(root_child3, 1); - YGNodeStyleSetFlexBasisPercent(root_child3, 0); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNew(); - YGNodeStyleSetWidth(root_child4, 50); - YGNodeInsertChild(root, root_child4, 4); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child4)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, align_content_stretch_row_with_margin) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root, YGAlignStretch); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 150); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNew(); - YGNodeStyleSetMargin(root_child1, YGEdgeLeft, 10); - YGNodeStyleSetMargin(root_child1, YGEdgeTop, 10); - YGNodeStyleSetMargin(root_child1, YGEdgeRight, 10); - YGNodeStyleSetMargin(root_child1, YGEdgeBottom, 10); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNew(); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNew(); - YGNodeStyleSetMargin(root_child3, YGEdgeLeft, 10); - YGNodeStyleSetMargin(root_child3, YGEdgeTop, 10); - YGNodeStyleSetMargin(root_child3, YGEdgeRight, 10); - YGNodeStyleSetMargin(root_child3, YGEdgeBottom, 10); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNew(); - YGNodeStyleSetWidth(root_child4, 50); - YGNodeInsertChild(root, root_child4, 4); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child4)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, align_content_stretch_row_with_padding) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root, YGAlignStretch); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 150); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNew(); - YGNodeStyleSetPadding(root_child1, YGEdgeLeft, 10); - YGNodeStyleSetPadding(root_child1, YGEdgeTop, 10); - YGNodeStyleSetPadding(root_child1, YGEdgeRight, 10); - YGNodeStyleSetPadding(root_child1, YGEdgeBottom, 10); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNew(); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNew(); - YGNodeStyleSetPadding(root_child3, YGEdgeLeft, 10); - YGNodeStyleSetPadding(root_child3, YGEdgeTop, 10); - YGNodeStyleSetPadding(root_child3, YGEdgeRight, 10); - YGNodeStyleSetPadding(root_child3, YGEdgeBottom, 10); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNew(); - YGNodeStyleSetWidth(root_child4, 50); - YGNodeInsertChild(root, root_child4, 4); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, align_content_stretch_row_with_single_row) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root, YGAlignStretch); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 150); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNew(); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeInsertChild(root, root_child1, 1); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, align_content_stretch_row_with_fixed_height) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root, YGAlignStretch); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 150); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNew(); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(root_child1, 60); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNew(); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNew(); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNew(); - YGNodeStyleSetWidth(root_child4, 50); - YGNodeInsertChild(root, root_child4, 4); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child4)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, align_content_stretch_row_with_max_height) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root, YGAlignStretch); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 150); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNew(); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetMaxHeight(root_child1, 20); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNew(); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNew(); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNew(); - YGNodeStyleSetWidth(root_child4, 50); - YGNodeInsertChild(root, root_child4, 4); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, align_content_stretch_row_with_min_height) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root, YGAlignStretch); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 150); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNew(); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetMinHeight(root_child1, 80); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNew(); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNew(); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNew(); - YGNodeStyleSetWidth(root_child4, 50); - YGNodeInsertChild(root, root_child4, 4); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, align_content_stretch_column) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetAlignContent(root, YGAlignStretch); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 150); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNew(); - YGNodeStyleSetFlexGrow(root_child0_child0, 1); - YGNodeStyleSetFlexShrink(root_child0_child0, 1); - YGNodeStyleSetFlexBasisPercent(root_child0_child0, 0); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - const YGNodeRef root_child1 = YGNodeNew(); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeStyleSetFlexShrink(root_child1, 1); - YGNodeStyleSetFlexBasisPercent(root_child1, 0); - YGNodeStyleSetHeight(root_child1, 50); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNew(); - YGNodeStyleSetHeight(root_child2, 50); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNew(); - YGNodeStyleSetHeight(root_child3, 50); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNew(); - YGNodeStyleSetHeight(root_child4, 50); - YGNodeInsertChild(root, root_child4, 4); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); -} diff --git a/yoga/Yoga.c b/yoga/Yoga.c index 771a8a17..e8d5c31e 100644 --- a/yoga/Yoga.c +++ b/yoga/Yoga.c @@ -2485,23 +2485,10 @@ static void YGNodelayoutImpl(const YGNodeRef node, // the spacing. mainDim += betweenMainDim + YGNodeDimWithMargin(child, mainAxis, availableInnerWidth); - if (YGNodeIsStyleDimDefined(child, crossAxis, availableInnerCrossDim) || - child->measure != NULL || - !isNodeFlexWrap) { - // The cross dimension is the max of the elements dimension since - // there - // can only be one element in that cross dimension. - crossDim = - fmaxf(crossDim, YGNodeDimWithMargin(child, crossAxis, availableInnerWidth)); - } else { - // If we wrap the lines we only take the space we need at least. - crossDim = fmaxf( - crossDim, - YGNodeMarginForAxis(child, crossAxis, availableInnerWidth) + - fmaxf(YGValueResolve(&child->style.minDimensions[dim[crossAxis]], - availableInnerWidth), - YGNodePaddingAndBorderForAxis(child, crossAxis, availableInnerWidth))); - } + // The cross dimension is the max of the elements dimension since + // there + // can only be one element in that cross dimension. + crossDim = fmaxf(crossDim, YGNodeDimWithMargin(child, crossAxis, availableInnerWidth)); } } else if (performLayout) { child->layout.position[pos[mainAxis]] += @@ -2665,8 +2652,7 @@ static void YGNodelayoutImpl(const YGNodeRef node, } // STEP 8: MULTI-LINE CONTENT ALIGNMENT - if (performLayout && - (lineCount > 1 || node->style.alignContent == YGAlignStretch || YGIsBaselineLayout(node)) && + if (performLayout && (lineCount > 1 || YGIsBaselineLayout(node)) && !YGFloatIsUndefined(availableInnerCrossDim)) { const float remainingAlignContentDim = availableInnerCrossDim - totalLineCrossDim; @@ -2774,36 +2760,8 @@ static void YGNodelayoutImpl(const YGNodeRef node, case YGAlignStretch: { child->layout.position[pos[crossAxis]] = currentLead + YGNodeLeadingMargin(child, crossAxis, availableInnerWidth); - - // Remeasure child with the line height as it as been only measured with the - // parents height yet. - if (!YGNodeIsStyleDimDefined(child, crossAxis, availableInnerCrossDim)) { - const float childWidth = - isMainAxisRow ? (child->layout.measuredDimensions[YGDimensionWidth] + - YGNodeMarginForAxis(child, crossAxis, availableInnerWidth)) - : lineHeight; - - const float childHeight = - !isMainAxisRow ? (child->layout.measuredDimensions[YGDimensionHeight] + - YGNodeMarginForAxis(child, crossAxis, availableInnerWidth)) - : lineHeight; - - if (!(YGFloatsEqual(childWidth, - child->layout.measuredDimensions[YGDimensionWidth]) && - YGFloatsEqual(childHeight, - child->layout.measuredDimensions[YGDimensionHeight]))) { - YGLayoutNodeInternal(child, - childWidth, - childHeight, - direction, - YGMeasureModeExactly, - YGMeasureModeExactly, - availableInnerWidth, - availableInnerHeight, - true, - "stretch"); - } - } + // TODO(prenaux): Correctly set the height of items with indefinite + // (auto) crossAxis dimension. break; } case YGAlignBaseline: { From e7021715b8b67c7b9770c17ba0a61420b4d9e108 Mon Sep 17 00:00:00 2001 From: Emil Sjolander Date: Mon, 13 Feb 2017 05:17:34 -0800 Subject: [PATCH 14/20] Split travis builds into multiple runs Summary: Split travis into one run per language. This should improve build speed as well as improve signal as to what is failing. Reviewed By: dshahidehpour Differential Revision: D4551194 fbshipit-source-id: 36bc60193b4b287352073ab62a7bd053b15eaedf --- .travis.yml | 58 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/.travis.yml b/.travis.yml index a477b641..9cd07f99 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,33 +10,49 @@ osx_image: xcode8.2 language: cpp compiler: clang +env: + - LANG=c + - LANG=java + - LANG=net + - LANG=ios + - LANG=js + before_install: - brew update - brew tap facebook/fb - brew install buck - - brew cask install java - - brew outdated xctool || brew upgrade xctool - - brew install mono - - export JAVA_HOME=$(/usr/libexec/java_home -v 1.8) - - export PATH=$JAVA_HOME/bin:$PATH + # Java + - [[ $LANG = "java" ]] && brew cask install java + - [[ $LANG = "java" ]] && export JAVA_HOME=$(/usr/libexec/java_home -v 1.8) + - [[ $LANG = "java" ]] && export PATH=$JAVA_HOME/bin:$PATH -install: - - cd javascript - - npm install - - cd $TRAVIS_BUILD_DIR + # .NET + - [[ $LANG = "net" ]] && brew install mono -script: - - buck test //:yoga - - buck test //java:java - - buck test //YogaKit:YogaKitTests --config cxx.default_platform=iphonesimulator-x86_64 - - sh csharp/tests/Facebook.Yoga/test_macos.sh + # iOS + - [[ $LANG = "ios" ]] && brew outdated xctool || brew upgrade xctool - - cd javascript - - npm run test:all - - npm run bench - - cd $TRAVIS_BUILD_DIR + # JavaScript + - [[ $LANG = "js" ]] && cd javascript + - [[ $LANG = "js" ]] && npm install - - buck run //benchmark:benchmark - - git checkout HEAD^ - - buck run //benchmark:benchmark +- script: + # C + - [[ $LANG = "c" ]] && buck test //:yoga + - [[ $LANG = "c" ]] && buck run //benchmark:benchmark + - [[ $LANG = "c" ]] && git checkout HEAD^ + - [[ $LANG = "c" ]] && buck run //benchmark:benchmark + + # Java + - [[ $LANG = "java" ]] && buck test //java:java + + # .NET + - [[ $LANG = "net" ]] && sh csharp/tests/Facebook.Yoga/test_macos.sh + + # iOS + - [[ $LANG = "ios" ]] && buck test //YogaKit:YogaKitTests --config cxx.default_platform=iphonesimulator-x86_64 + + # JavaScript + - [[ $LANG = "js" ]] && npm run test:all + - [[ $LANG = "js" ]] && npm run bench From 1cbadf5f542013b5a5183d2d6f9a2be6ac9c2696 Mon Sep 17 00:00:00 2001 From: Emil Sjolander Date: Mon, 13 Feb 2017 06:49:38 -0800 Subject: [PATCH 15/20] Fix mistakes in travis file Summary: Fix yaml errors Reviewed By: passy Differential Revision: D4551330 fbshipit-source-id: d17087cf51f9556c7015ea0fc4ab11fec44917f2 --- .travis.yml | 52 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9cd07f99..7ca69fd2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,36 +23,54 @@ before_install: - brew install buck # Java - - [[ $LANG = "java" ]] && brew cask install java - - [[ $LANG = "java" ]] && export JAVA_HOME=$(/usr/libexec/java_home -v 1.8) - - [[ $LANG = "java" ]] && export PATH=$JAVA_HOME/bin:$PATH + - | + [[ $LANG = "java" ]] && + brew cask install java && + export JAVA_HOME=$(/usr/libexec/java_home -v 1.8) && + export PATH=$JAVA_HOME/bin:$PATH # .NET - - [[ $LANG = "net" ]] && brew install mono + - | + [[ $LANG = "net" ]] && + brew install mono # iOS - - [[ $LANG = "ios" ]] && brew outdated xctool || brew upgrade xctool + - | + [[ $LANG = "ios" ]] && + brew upgrade xctool # JavaScript - - [[ $LANG = "js" ]] && cd javascript - - [[ $LANG = "js" ]] && npm install + - | + [[ $LANG = "js" ]] && + cd javascript && + npm install -- script: +script: # C - - [[ $LANG = "c" ]] && buck test //:yoga - - [[ $LANG = "c" ]] && buck run //benchmark:benchmark - - [[ $LANG = "c" ]] && git checkout HEAD^ - - [[ $LANG = "c" ]] && buck run //benchmark:benchmark + - | + [[ $LANG = "c" ]] && + buck test //:yoga && + buck run //benchmark:benchmark && + git checkout HEAD^ && + buck run //benchmark:benchmark # Java - - [[ $LANG = "java" ]] && buck test //java:java + - | + [[ $LANG = "java" ]] && + buck test //java:java # .NET - - [[ $LANG = "net" ]] && sh csharp/tests/Facebook.Yoga/test_macos.sh + - | + [[ $LANG = "net" ]] && + sh csharp/tests/Facebook.Yoga/test_macos.sh # iOS - - [[ $LANG = "ios" ]] && buck test //YogaKit:YogaKitTests --config cxx.default_platform=iphonesimulator-x86_64 + - | + [[ $LANG = "ios" ]] && + buck test //YogaKit:YogaKitTests --config cxx.default_platform=iphonesimulator-x86_64 # JavaScript - - [[ $LANG = "js" ]] && npm run test:all - - [[ $LANG = "js" ]] && npm run bench + - | + [[ $LANG = "js" ]] && + npm run test:all && + npm run bench From ad8c6225fdfb8c42aed22341bdf20f6ef38f7ea3 Mon Sep 17 00:00:00 2001 From: Kazuki Sakamoto Date: Mon, 13 Feb 2017 08:15:21 -0800 Subject: [PATCH 16/20] Build i386 for iOS and macOS Summary: Closes https://github.com/facebook/yoga/pull/391 Reviewed By: emilsjolander Differential Revision: D4549469 Pulled By: splhack fbshipit-source-id: 7500b7235218f9a4f564adb36044303dff520fd6 --- csharp/BUCK | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/csharp/BUCK b/csharp/BUCK index 8fc408eb..29e2e6d2 100644 --- a/csharp/BUCK +++ b/csharp/BUCK @@ -39,7 +39,9 @@ with allow_unsafe_import(): if os.path.isdir('/Applications/Xcode.app'): yoganet_ios_srcs = [] - for arch in ['iphonesimulator-x86_64', 'iphoneos-arm64', 'iphoneos-armv7']: + for arch in [ + 'iphonesimulator-x86_64', 'iphonesimulator-i386', 'iphoneos-arm64', 'iphoneos-armv7' + ]: name = 'yoganet-' + arch yoganet_ios_srcs.append(':' + name) genrule( @@ -61,3 +63,15 @@ if os.path.isdir('/Applications/Xcode.app'): cmd = 'lipo $SRCS -create -output $OUT', visibility = ['PUBLIC'], ) + + yoganet_macosx_target = 'csharp:yoganet#macosx-%s,dynamic' + genrule( + name = 'yoganet-macosx', + srcs = [ + yoga_dep(yoganet_macosx_target % 'x86_64'), + yoga_dep(yoganet_macosx_target % 'i386'), + ], + out = 'libyoga.dylib', + cmd = 'lipo $SRCS -create -output $OUT', + visibility = ['PUBLIC'], + ) From 058761e16e2a986bbc943e3e8dcbd025ef7d5169 Mon Sep 17 00:00:00 2001 From: Dustin Shahidehpour Date: Mon, 13 Feb 2017 09:05:22 -0800 Subject: [PATCH 17/20] Give YogaKitSample some love, Convert it to a Swift Project Summary: To date, our sample project was lacking. There is still a lot of work that can be done to improve, but, this is a step in the right direction. Here are the changes in this commit: 1. The project is written in Swift. 2. Created new CollectionView (via [IGListKit](https://github.com/instagram/iglistkit)), making it very easy to add new examples. 3. New examples for basic layouts, and including/excluding layouts on the fly. Here's a video! ![](https://media.giphy.com/media/l0ExcvTLa0ADdawRa/giphy.gif) Closes https://github.com/facebook/yoga/pull/392 Reviewed By: emilsjolander Differential Revision: D4550379 Pulled By: dshahidehpour fbshipit-source-id: 64a07acf96c1887f1d2ad0c54971fcedb64334a0 --- YogaKit/YogaKitSample/Podfile | 1 + YogaKit/YogaKitSample/Podfile.lock | 11 +- .../YogaKitSample.xcodeproj/project.pbxproj | 64 ++++++----- .../YogaKitSample/YogaKitSample/AppDelegate.h | 15 --- .../YogaKitSample/YogaKitSample/AppDelegate.m | 27 ----- .../YogaKitSample/AppDelegate.swift | 27 +++++ .../ExamplesViewController.swift | 100 ++++++++++++++++++ .../YogaKitSample/SwiftViewController.swift | 83 ++++++++++----- .../YogaKitSample/ViewController.h | 13 --- .../ViewControllers/BasicViewController.swift | 48 +++++++++ .../LayoutInclusionViewController.swift | 70 ++++++++++++ .../Views/SingleLabelCollectionCell.swift | 45 ++++++++ YogaKit/YogaKitSample/YogaKitSample/main.m | 16 --- 13 files changed, 390 insertions(+), 130 deletions(-) delete mode 100644 YogaKit/YogaKitSample/YogaKitSample/AppDelegate.h delete mode 100644 YogaKit/YogaKitSample/YogaKitSample/AppDelegate.m create mode 100644 YogaKit/YogaKitSample/YogaKitSample/AppDelegate.swift create mode 100644 YogaKit/YogaKitSample/YogaKitSample/ExamplesViewController.swift delete mode 100644 YogaKit/YogaKitSample/YogaKitSample/ViewController.h create mode 100644 YogaKit/YogaKitSample/YogaKitSample/ViewControllers/BasicViewController.swift create mode 100644 YogaKit/YogaKitSample/YogaKitSample/ViewControllers/LayoutInclusionViewController.swift create mode 100644 YogaKit/YogaKitSample/YogaKitSample/Views/SingleLabelCollectionCell.swift delete mode 100644 YogaKit/YogaKitSample/YogaKitSample/main.m diff --git a/YogaKit/YogaKitSample/Podfile b/YogaKit/YogaKitSample/Podfile index 87279a14..ab7eca4d 100644 --- a/YogaKit/YogaKitSample/Podfile +++ b/YogaKit/YogaKitSample/Podfile @@ -2,4 +2,5 @@ use_frameworks! target 'YogaKitSample' do pod 'YogaKit', :path => '../../YogaKit.podspec' + pod 'IGListKit', '~> 2.1.0' end diff --git a/YogaKit/YogaKitSample/Podfile.lock b/YogaKit/YogaKitSample/Podfile.lock index 031125d4..6b5c5658 100644 --- a/YogaKit/YogaKitSample/Podfile.lock +++ b/YogaKit/YogaKitSample/Podfile.lock @@ -1,19 +1,26 @@ PODS: + - IGListKit (2.1.0): + - IGListKit/Default (= 2.1.0) + - IGListKit/Default (2.1.0): + - IGListKit/Diffing + - IGListKit/Diffing (2.1.0) - Yoga (1.1.0) - YogaKit (1.1.0): - Yoga (~> 1.1) DEPENDENCIES: + - IGListKit (~> 2.1.0) - YogaKit (from `../../YogaKit.podspec`) EXTERNAL SOURCES: YogaKit: - :path: "../../YogaKit.podspec" + :path: ../../YogaKit.podspec SPEC CHECKSUMS: + IGListKit: b826c68ef7a4ae1626c09d4d3e1ea7a169e6c36e Yoga: 0bf083b7c485b20598020dbedcea869cbe53071e YogaKit: 80df90de9ef2900baa111f2c93476a6f9e921385 -PODFILE CHECKSUM: 9db3bdea7f1b4b715ad859a449b2dc87fb6226cc +PODFILE CHECKSUM: 216f8e7127767709e0e43f3711208d238fa5c404 COCOAPODS: 1.2.0 diff --git a/YogaKit/YogaKitSample/YogaKitSample.xcodeproj/project.pbxproj b/YogaKit/YogaKitSample/YogaKitSample.xcodeproj/project.pbxproj index 4999ad9d..654f9ebb 100644 --- a/YogaKit/YogaKitSample/YogaKitSample.xcodeproj/project.pbxproj +++ b/YogaKit/YogaKitSample/YogaKitSample.xcodeproj/project.pbxproj @@ -7,14 +7,15 @@ objects = { /* Begin PBXBuildFile section */ - 13687D481DF8748400E7C260 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13687D471DF8748400E7C260 /* main.m */; }; - 13687D4B1DF8748400E7C260 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13687D4A1DF8748400E7C260 /* AppDelegate.m */; }; - 13687D4E1DF8748400E7C260 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 13687D4D1DF8748400E7C260 /* ViewController.m */; }; 13687D531DF8748400E7C260 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13687D521DF8748400E7C260 /* Assets.xcassets */; }; 13687D851DF87D1E00E7C260 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 13687D841DF87D1E00E7C260 /* UIKit.framework */; }; 13687D871DF87D2400E7C260 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 13687D861DF87D2400E7C260 /* Foundation.framework */; }; 15A7CB5995C9DAB1C8803834 /* Pods_YogaKitSample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C80A931E90C7F3088CB86822 /* Pods_YogaKitSample.framework */; }; - 638A94481E1F06D100A726AD /* SwiftViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 638A94471E1F06D100A726AD /* SwiftViewController.swift */; }; + 40BD9F461E477A09002790A9 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40BD9F451E477A09002790A9 /* AppDelegate.swift */; }; + 40BD9F4B1E47850C002790A9 /* BasicViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40BD9F4A1E47850C002790A9 /* BasicViewController.swift */; }; + 40BD9F501E479079002790A9 /* SingleLabelCollectionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40BD9F4F1E479079002790A9 /* SingleLabelCollectionCell.swift */; }; + 40BD9F521E479173002790A9 /* LayoutInclusionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40BD9F511E479173002790A9 /* LayoutInclusionViewController.swift */; }; + 638A94481E1F06D100A726AD /* ExamplesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 638A94471E1F06D100A726AD /* ExamplesViewController.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -52,17 +53,16 @@ /* Begin PBXFileReference section */ 13687D431DF8748400E7C260 /* YogaKitSample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = YogaKitSample.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 13687D471DF8748400E7C260 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; - 13687D491DF8748400E7C260 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; - 13687D4A1DF8748400E7C260 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; - 13687D4C1DF8748400E7C260 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; - 13687D4D1DF8748400E7C260 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 13687D521DF8748400E7C260 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 13687D571DF8748400E7C260 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 13687D841DF87D1E00E7C260 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 13687D861DF87D2400E7C260 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 1D2FF4D5FCA6A8C54A4074A3 /* Pods-YogaKitSample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-YogaKitSample.debug.xcconfig"; path = "Pods/Target Support Files/Pods-YogaKitSample/Pods-YogaKitSample.debug.xcconfig"; sourceTree = ""; }; - 638A94471E1F06D100A726AD /* SwiftViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftViewController.swift; sourceTree = ""; }; + 40BD9F451E477A09002790A9 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 40BD9F4A1E47850C002790A9 /* BasicViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BasicViewController.swift; path = ViewControllers/BasicViewController.swift; sourceTree = ""; }; + 40BD9F4F1E479079002790A9 /* SingleLabelCollectionCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SingleLabelCollectionCell.swift; path = Views/SingleLabelCollectionCell.swift; sourceTree = ""; }; + 40BD9F511E479173002790A9 /* LayoutInclusionViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LayoutInclusionViewController.swift; path = ViewControllers/LayoutInclusionViewController.swift; sourceTree = ""; }; + 638A94471E1F06D100A726AD /* ExamplesViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExamplesViewController.swift; sourceTree = ""; }; 638A944F1E215CC800A726AD /* YogaKitSampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = YogaKitSampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 82F0896A88112E957EF37C7F /* Pods-YogaKitSample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-YogaKitSample.release.xcconfig"; path = "Pods/Target Support Files/Pods-YogaKitSample/Pods-YogaKitSample.release.xcconfig"; sourceTree = ""; }; C80A931E90C7F3088CB86822 /* Pods_YogaKitSample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_YogaKitSample.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -111,26 +111,16 @@ 13687D451DF8748400E7C260 /* YogaKitSample */ = { isa = PBXGroup; children = ( - 13687D491DF8748400E7C260 /* AppDelegate.h */, - 13687D4A1DF8748400E7C260 /* AppDelegate.m */, - 13687D4C1DF8748400E7C260 /* ViewController.h */, - 13687D4D1DF8748400E7C260 /* ViewController.m */, - 638A94471E1F06D100A726AD /* SwiftViewController.swift */, + 40BD9F4E1E47902F002790A9 /* Views */, + 40BD9F481E4784B3002790A9 /* ViewControllers */, + 638A94471E1F06D100A726AD /* ExamplesViewController.swift */, 13687D521DF8748400E7C260 /* Assets.xcassets */, 13687D571DF8748400E7C260 /* Info.plist */, - 13687D461DF8748400E7C260 /* Supporting Files */, + 40BD9F451E477A09002790A9 /* AppDelegate.swift */, ); path = YogaKitSample; sourceTree = ""; }; - 13687D461DF8748400E7C260 /* Supporting Files */ = { - isa = PBXGroup; - children = ( - 13687D471DF8748400E7C260 /* main.m */, - ); - name = "Supporting Files"; - sourceTree = ""; - }; 13687D831DF87D1E00E7C260 /* Frameworks */ = { isa = PBXGroup; children = ( @@ -141,6 +131,23 @@ name = Frameworks; sourceTree = ""; }; + 40BD9F481E4784B3002790A9 /* ViewControllers */ = { + isa = PBXGroup; + children = ( + 40BD9F4A1E47850C002790A9 /* BasicViewController.swift */, + 40BD9F511E479173002790A9 /* LayoutInclusionViewController.swift */, + ); + name = ViewControllers; + sourceTree = ""; + }; + 40BD9F4E1E47902F002790A9 /* Views */ = { + isa = PBXGroup; + children = ( + 40BD9F4F1E479079002790A9 /* SingleLabelCollectionCell.swift */, + ); + name = Views; + sourceTree = ""; + }; E1C759E3C8E84821213ECE8D /* Pods */ = { isa = PBXGroup; children = ( @@ -304,10 +311,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 638A94481E1F06D100A726AD /* SwiftViewController.swift in Sources */, - 13687D4E1DF8748400E7C260 /* ViewController.m in Sources */, - 13687D4B1DF8748400E7C260 /* AppDelegate.m in Sources */, - 13687D481DF8748400E7C260 /* main.m in Sources */, + 40BD9F501E479079002790A9 /* SingleLabelCollectionCell.swift in Sources */, + 40BD9F521E479173002790A9 /* LayoutInclusionViewController.swift in Sources */, + 638A94481E1F06D100A726AD /* ExamplesViewController.swift in Sources */, + 40BD9F4B1E47850C002790A9 /* BasicViewController.swift in Sources */, + 40BD9F461E477A09002790A9 /* AppDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/YogaKit/YogaKitSample/YogaKitSample/AppDelegate.h b/YogaKit/YogaKitSample/YogaKitSample/AppDelegate.h deleted file mode 100644 index 39858917..00000000 --- a/YogaKit/YogaKitSample/YogaKitSample/AppDelegate.h +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Copyright 2014-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the license found in the - * LICENSE-examples file in the root directory of this source tree. - */ - -#import - -@interface AppDelegate : UIResponder - -@property (strong, nonatomic) UIWindow *window; - -@end diff --git a/YogaKit/YogaKitSample/YogaKitSample/AppDelegate.m b/YogaKit/YogaKitSample/YogaKitSample/AppDelegate.m deleted file mode 100644 index d1840bc7..00000000 --- a/YogaKit/YogaKitSample/YogaKitSample/AppDelegate.m +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright 2014-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the license found in the - * LICENSE-examples file in the root directory of this source tree. - */ - -#import "AppDelegate.h" -#import "ViewController.h" - -@interface AppDelegate () - -@end - -@implementation AppDelegate - - -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; - self.window.rootViewController = [ViewController new]; - self.window.backgroundColor = [UIColor whiteColor]; - [self.window makeKeyAndVisible]; - return YES; -} - -@end diff --git a/YogaKit/YogaKitSample/YogaKitSample/AppDelegate.swift b/YogaKit/YogaKitSample/YogaKitSample/AppDelegate.swift new file mode 100644 index 00000000..861adeca --- /dev/null +++ b/YogaKit/YogaKitSample/YogaKitSample/AppDelegate.swift @@ -0,0 +1,27 @@ +/** + * Copyright 2014-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the license found in the + * LICENSE-examples file in the root directory of this source tree. + */ + +import Foundation +import UIKit + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + var window: UIWindow? + + func applicationDidFinishLaunching(_ application: UIApplication) { + self.window = UIWindow(frame: UIScreen.main.bounds) + if let window = self.window { + let navigationController = UINavigationController(rootViewController: ExamplesViewController()) + navigationController.navigationBar.isTranslucent = false + + window.rootViewController = navigationController + window.backgroundColor = .white + window.makeKeyAndVisible() + } + } +} diff --git a/YogaKit/YogaKitSample/YogaKitSample/ExamplesViewController.swift b/YogaKit/YogaKitSample/YogaKitSample/ExamplesViewController.swift new file mode 100644 index 00000000..38ee2618 --- /dev/null +++ b/YogaKit/YogaKitSample/YogaKitSample/ExamplesViewController.swift @@ -0,0 +1,100 @@ +/** + * Copyright 2014-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the license found in the + * LICENSE-examples file in the root directory of this source tree. + */ + +import UIKit +import IGListKit + +private final class ExampleModel { + let title: String + let controllerClass: UIViewController.Type + + init(title: String, controllerClass: UIViewController.Type) { + self.title = title + self.controllerClass = controllerClass + } +} + +extension ExampleModel: IGListDiffable { + fileprivate func diffIdentifier() -> NSObjectProtocol { + return title as NSString + } + + fileprivate func isEqual(toDiffableObject object: IGListDiffable?) -> Bool { + guard let otherObj = object as? ExampleModel else { return false } + + return (title == otherObj.title) && + (controllerClass == otherObj.controllerClass) + } +} + +final class ExamplesViewController: UIViewController, IGListAdapterDataSource, IGListSingleSectionControllerDelegate { + private lazy var adapter: IGListAdapter = { + return IGListAdapter(updater: IGListAdapterUpdater(), viewController: self, workingRangeSize: 0) + }() + private let collectionView = IGListCollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout()) + + + // Update this to array to create more examples. + private let models: [ExampleModel] = [ExampleModel(title: "Basic Layout", controllerClass: BasicViewController.self), + ExampleModel(title: "Exclude Views in Layout", controllerClass: LayoutInclusionViewController.self)] + + //MARK: UIViewController + + override func viewDidLoad() { + super.viewDidLoad() + title = "Examples" + view.addSubview(collectionView) + adapter.collectionView = collectionView + adapter.dataSource = self + } + + override func viewDidLayoutSubviews() { + super.viewDidLayoutSubviews() + collectionView.frame = view.bounds + } + + //MARK: IGListAdapterDataSource + + func objects(for listAdapter: IGListAdapter) -> [IGListDiffable] { + return models as [IGListDiffable] + } + + func listAdapter(_ listAdapter: IGListAdapter, sectionControllerFor object: Any) -> IGListSectionController { + let sizeBlock: IGListSingleSectionCellSizeBlock = { (model, context) in + return CGSize(width: (context?.containerSize.width)!, height: 75.0) + } + + let configureBlock: IGListSingleSectionCellConfigureBlock = { (model, cell) in + guard let m = model as? ExampleModel, let c = cell as? SingleLabelCollectionCell else { + return + } + + c.label.text = m.title + } + + let sectionController = IGListSingleSectionController(cellClass: SingleLabelCollectionCell.self, + configureBlock: configureBlock, + sizeBlock: sizeBlock) + sectionController.selectionDelegate = self + return sectionController + } + + func emptyView(for listAdapter: IGListAdapter) -> UIView? { return nil } + + //MARK: IGListSingleSectionControllerDelegate + + func didSelect(_ sectionController: IGListSingleSectionController) { + let section = adapter.section(for: sectionController) + let model = models[section] + + let controller = model.controllerClass.init() + controller.title = model.title + + self.navigationController?.pushViewController(controller, animated: true) + } +} diff --git a/YogaKit/YogaKitSample/YogaKitSample/SwiftViewController.swift b/YogaKit/YogaKitSample/YogaKitSample/SwiftViewController.swift index 66a90199..c0723d41 100644 --- a/YogaKit/YogaKitSample/YogaKitSample/SwiftViewController.swift +++ b/YogaKit/YogaKitSample/YogaKitSample/SwiftViewController.swift @@ -7,35 +7,60 @@ */ import UIKit +import IGListKit import YogaKit -class SwiftViewController: UIViewController { - override func viewDidLoad() { - let root = self.view! - root.backgroundColor = .red - root.yoga.isEnabled = true - root.yoga.width = self.view.bounds.size.width - root.yoga.height = self.view.bounds.size.height - root.yoga.alignItems = .center - root.yoga.justifyContent = .center - - let child1 = UIView() - child1.backgroundColor = .blue - child1.yoga.isEnabled = true - child1.yoga.width = 100 - child1.yoga.height = 10 - - let child2 = UIView() - child2.backgroundColor = .green - child2.frame = CGRect(x: 0, y: 0, width: 200, height: 100) - - let child3 = UIView() - child3.backgroundColor = .yellow - child3.frame = CGRect(x: 0, y: 0, width: 100, height: 100) - - child2.addSubview(child3) - root.addSubview(child1) - root.addSubview(child2) - root.yoga.applyLayout(preservingOrigin: false) - } +struct DemoItem { + let name: String +} + +final class SwiftViewController: UIViewController, IGListAdapterDataSource { + + lazy var adapter: IGListAdapter = { + return IGListAdapter(updater: IGListAdapterUpdater(), viewController: self, workingRangeSize: 0) + }() + let collectionView = IGListCollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout()) + + //MARK: UIViewController + + override func viewDidLoad() { + super.viewDidLoad() + title = "YogaKit Examples" + view.addSubview(collectionView) + adapter.collectionView = collectionView + adapter.dataSource = self + } + + override func viewDidLayoutSubviews() { + super.viewDidLayoutSubviews() + collectionView.frame = view.bounds + } + + + //MARK: IGListAdapterDataSource + + func objects(for listAdapter: IGListAdapter) -> [IGListDiffable] { + return ["Dustin" as IGListDiffable, "Ryan" as IGListDiffable] + } + + func listAdapter(_ listAdapter: IGListAdapter, sectionControllerFor object: Any) -> IGListSectionController { + let sizeBlock: IGListSingleSectionCellSizeBlock = { (model, context) in + return CGSize(width: (context?.containerSize.width)!, height: 100.0) + } + let configureBlock: IGListSingleSectionCellConfigureBlock = { (model, cell) in + guard let m = model as? String else { + return + } + + cell.backgroundColor = (m == "Dustin") ? .blue : .red + } + + return IGListSingleSectionController(cellClass: UICollectionViewCell.self, + configureBlock: configureBlock, + sizeBlock: sizeBlock) + } + + func emptyView(for listAdapter: IGListAdapter) -> UIView? { + return nil + } } diff --git a/YogaKit/YogaKitSample/YogaKitSample/ViewController.h b/YogaKit/YogaKitSample/YogaKitSample/ViewController.h deleted file mode 100644 index dbea50e0..00000000 --- a/YogaKit/YogaKitSample/YogaKitSample/ViewController.h +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Copyright 2014-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the license found in the - * LICENSE-examples file in the root directory of this source tree. - */ - -#import - -@interface ViewController : UIViewController - -@end diff --git a/YogaKit/YogaKitSample/YogaKitSample/ViewControllers/BasicViewController.swift b/YogaKit/YogaKitSample/YogaKitSample/ViewControllers/BasicViewController.swift new file mode 100644 index 00000000..56e9c897 --- /dev/null +++ b/YogaKit/YogaKitSample/YogaKitSample/ViewControllers/BasicViewController.swift @@ -0,0 +1,48 @@ +/** + * Copyright 2014-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the license found in the + * LICENSE-examples file in the root directory of this source tree. + */ + +import UIKit +import YogaKit + +final class BasicViewController: UIViewController { + override func viewDidLoad() { + let containerSize = self.view.bounds.size + + let root = self.view! + root.backgroundColor = .white + root.yoga.isEnabled = true + root.yoga.width = containerSize.width + root.yoga.height = containerSize.height + root.yoga.alignItems = .center + root.yoga.justifyContent = .center + + let child1 = UIView() + child1.backgroundColor = .blue + child1.yoga.isEnabled = true + child1.yoga.width = 100 + child1.yoga.height = 10 + child1.yoga.marginBottom = 25 + root.addSubview(child1) + + let child2 = UIView() + child2.yoga.isEnabled = true + child2.yoga.alignSelf = .flexEnd + child2.backgroundColor = .green + child2.frame = CGRect(x: 0, y: 0, width: 200, height: 100) + root.addSubview(child2) + + let child3 = UIView() + child3.yoga.isEnabled = true + child3.yoga.alignSelf = .flexStart + child3.backgroundColor = .yellow + child3.frame = CGRect(x: 0, y: 0, width: 100, height: 100) + root.addSubview(child3) + + root.yoga.applyLayout(preservingOrigin: true) + } +} diff --git a/YogaKit/YogaKitSample/YogaKitSample/ViewControllers/LayoutInclusionViewController.swift b/YogaKit/YogaKitSample/YogaKitSample/ViewControllers/LayoutInclusionViewController.swift new file mode 100644 index 00000000..dad97ee9 --- /dev/null +++ b/YogaKit/YogaKitSample/YogaKitSample/ViewControllers/LayoutInclusionViewController.swift @@ -0,0 +1,70 @@ +/** + * Copyright 2014-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the license found in the + * LICENSE-examples file in the root directory of this source tree. + */ + +import UIKit +import YogaKit + +final class LayoutInclusionViewController: UIViewController { + private let button: UIButton = UIButton(type: .system) + private let disappearingView: UIView = UIView(frame: .zero) + private let contentView: UIView = UIView(frame: .zero) + + override func viewDidLoad() { + let root = self.view! + root.backgroundColor = .white + root.yoga.isEnabled = true + root.yoga.flexDirection = .column + root.yoga.justifyContent = .spaceAround + + contentView.backgroundColor = .clear + contentView.layer.borderColor = UIColor.lightGray.cgColor + contentView.layer.borderWidth = 1.0 + contentView.yoga.isEnabled = true + contentView.yoga.height = 300 + contentView.yoga.width = self.view.bounds.size.width + contentView.yoga.flexDirection = .row + contentView.yoga.justifyContent = .center + contentView.yoga.paddingHorizontal = 25 + self.view.addSubview(contentView) + + let redView = UIView(frame: .zero) + redView.backgroundColor = .red + redView.yoga.isEnabled = true + redView.yoga.flexGrow = 1 + redView.yoga.flexShrink = 1 + contentView.addSubview(redView) + + disappearingView.backgroundColor = .blue + disappearingView.yoga.isEnabled = true + disappearingView.yoga.flexGrow = 1 + contentView.addSubview(disappearingView) + + button.setTitle("Add Blue View", for: UIControlState.selected) + button.setTitle("Remove Blue View", for: UIControlState.normal) + button.addTarget(self, action: #selector(buttonWasTapped), for: UIControlEvents.touchUpInside) + button.yoga.isEnabled = true + button.yoga.height = 300 + button.yoga.width = 300 + button.yoga.alignSelf = .center + root.addSubview(button) + + root.yoga.applyLayout(preservingOrigin: false) + } + + // MARK - UIButton Action + func buttonWasTapped() { + button.isSelected = !button.isSelected + + button.isUserInteractionEnabled = false + disappearingView.yoga.isIncludedInLayout = !disappearingView.yoga.isIncludedInLayout + disappearingView.isHidden = !disappearingView.isHidden + + contentView.yoga.applyLayout(preservingOrigin: true) + button.isUserInteractionEnabled = true + } +} diff --git a/YogaKit/YogaKitSample/YogaKitSample/Views/SingleLabelCollectionCell.swift b/YogaKit/YogaKitSample/YogaKitSample/Views/SingleLabelCollectionCell.swift new file mode 100644 index 00000000..5fff40cb --- /dev/null +++ b/YogaKit/YogaKitSample/YogaKitSample/Views/SingleLabelCollectionCell.swift @@ -0,0 +1,45 @@ +/** + * Copyright 2014-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the license found in the + * LICENSE-examples file in the root directory of this source tree. + */ + +import UIKit +import YogaKit + +final class SingleLabelCollectionCell: UICollectionViewCell { + let label: UILabel = UILabel(frame: .zero) + + override init(frame: CGRect) { + super.init(frame: frame) + + contentView.yoga.isEnabled = true + contentView.yoga.flexDirection = .column + contentView.yoga.justifyContent = .flexEnd + + label.textAlignment = .center + label.numberOfLines = 1 + label.yoga.isIncludedInLayout = false + contentView.addSubview(label) + + let border = UIView(frame: .zero) + border.backgroundColor = .lightGray + border.yoga.isEnabled = true + border.yoga.height = 0.5 + border.yoga.marginHorizontal = 25 + contentView.addSubview(border) + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func layoutSubviews() { + super.layoutSubviews() + + contentView.yoga.applyLayout(preservingOrigin: false) + label.frame = contentView.bounds + } +} diff --git a/YogaKit/YogaKitSample/YogaKitSample/main.m b/YogaKit/YogaKitSample/YogaKitSample/main.m deleted file mode 100644 index bbef0040..00000000 --- a/YogaKit/YogaKitSample/YogaKitSample/main.m +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Copyright 2014-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the license found in the - * LICENSE-examples file in the root directory of this source tree. - */ - -#import -#import "AppDelegate.h" - -int main(int argc, char * argv[]) { - @autoreleasepool { - return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); - } -} From ae9f89b5d16dd28c225158ba0d7d119be2d0a8f1 Mon Sep 17 00:00:00 2001 From: Dustin Shahidehpour Date: Mon, 13 Feb 2017 09:16:22 -0800 Subject: [PATCH 18/20] Add helper function for bulk updates. Summary: Currently, our configuration of Views looks like this: ```objc UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; view.yoga.isEnabled = YES; view.yoga.height = 50; view.yoga.width = 50; ``` Every time that we access `view.yoga` we have to access the associated object on `UIView` to get the `YGLayout`. This adds an extra `objc_msgSend` which increases binary size, and is slight perf impact. This diff creates a way to modify the `YGLayout` with only a single `objc_msgSend`. Here's the new syntax: ```objc UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; [view configureLayoutWithBlock:^void(YGLayout *layout){ layout.isEnabled = YES layout.height = 50; layout.width = 50; }]; ``` Here's the Swift version: ```swift let view = UIView(frame: .zero) view.configureLayout { (layout) in layout.isEnabled = true layout.height = 50 layout.width = 50 } ``` Closes https://github.com/facebook/yoga/pull/393 Reviewed By: emilsjolander Differential Revision: D4550382 Pulled By: dshahidehpour fbshipit-source-id: 76d797d1e0de8e5dc767e02180a7fc440a70212e --- YogaKit/CHANGELOG.md | 17 +++++++++++++++++ YogaKit/Source/UIView+Yoga.h | 16 ++++++++++++++++ YogaKit/Source/UIView+Yoga.m | 6 ++++++ YogaKit/Tests/YogaKitTests.m | 19 +++++++++++++++++++ 4 files changed, 58 insertions(+) diff --git a/YogaKit/CHANGELOG.md b/YogaKit/CHANGELOG.md index 49c46f2f..58f41d9b 100644 --- a/YogaKit/CHANGELOG.md +++ b/YogaKit/CHANGELOG.md @@ -25,3 +25,20 @@ view.yoga.marginLeft // 0 ### Enhancements - Pixel Rounding now uses `roundf()` instead of `round()`. + +- There is now a method that allows "bulk" updates to YGLayout. +```objc +[view configureLayoutWithBlock:^(YGLayout *layout) { + layout.isEnabled = YES; + layout.width = 50; + layout.height = 50; +}]; +``` + +```swift +view.configureLayout { (layout) in + layout.isEnabled = true + layout.width = 50 + layout.height = 50 +} +``` diff --git a/YogaKit/Source/UIView+Yoga.h b/YogaKit/Source/UIView+Yoga.h index 1af3581b..e75119c0 100644 --- a/YogaKit/Source/UIView+Yoga.h +++ b/YogaKit/Source/UIView+Yoga.h @@ -10,8 +10,24 @@ #import "YGLayout.h" #import +NS_ASSUME_NONNULL_BEGIN + +typedef void (^YGLayoutConfigurationBlock)(YGLayout *); + @interface UIView (Yoga) +/** + The YGLayout that is attached to this view. It is lazily created. + */ @property (nonatomic, readonly, strong) YGLayout *yoga; +/** + In ObjC land, every time you access `view.yoga.*` you are adding another `objc_msgSend` + to your code. If you plan on making multiple changes to YGLayout, it's more performant + to use this method, which uses a single objc_msgSend call. + */ +- (void)configureLayoutWithBlock:(YGLayoutConfigurationBlock)block NS_SWIFT_NAME(configureLayout(block:)); + @end + +NS_ASSUME_NONNULL_END diff --git a/YogaKit/Source/UIView+Yoga.m b/YogaKit/Source/UIView+Yoga.m index 66b7eed0..4448b377 100644 --- a/YogaKit/Source/UIView+Yoga.m +++ b/YogaKit/Source/UIView+Yoga.m @@ -26,5 +26,11 @@ static const void *kYGYogaAssociatedKey = &kYGYogaAssociatedKey; return yoga; } +- (void)configureLayoutWithBlock:(YGLayoutConfigurationBlock)block +{ + if (block != nil) { + block(self.yoga); + } +} @end diff --git a/YogaKit/Tests/YogaKitTests.m b/YogaKit/Tests/YogaKitTests.m index dcb089e8..5a1d56f1 100644 --- a/YogaKit/Tests/YogaKitTests.m +++ b/YogaKit/Tests/YogaKitTests.m @@ -18,6 +18,25 @@ @implementation YogaKitTests +- (void)testConfigureLayoutIsNoOpWithNilBlock +{ + UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; + XCTAssertNoThrow([view configureLayoutWithBlock:nil]); +} + +- (void)testConfigureLayoutBlockWorksWithValidBlock +{ + UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; + [view configureLayoutWithBlock:^(YGLayout *layout){ + XCTAssertNotNil(layout); + layout.isEnabled = YES; + layout.width = 25; + }]; + + XCTAssertTrue(view.yoga.isEnabled); + XCTAssertEqual(view.yoga.width, 25); +} + - (void)testNodesAreDeallocedWithSingleView { __weak YGLayout *layoutRef = nil; From abf142ea3f0fc988d6932141ec2aa161ff9fb1a9 Mon Sep 17 00:00:00 2001 From: Emil Sjolander Date: Mon, 13 Feb 2017 09:27:44 -0800 Subject: [PATCH 19/20] Fix more travis file errors Summary: and add badges to readme Reviewed By: passy Differential Revision: D4551571 fbshipit-source-id: c6eafe480e3667252eadc96c548c3b3c85046389 --- .travis.yml | 69 ++++++++++++++++++++++++++++++----------------------- README.md | 8 ++++++- 2 files changed, 46 insertions(+), 31 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7ca69fd2..c91c67e5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,11 +11,11 @@ language: cpp compiler: clang env: - - LANG=c - - LANG=java - - LANG=net - - LANG=ios - - LANG=js + - TARGET=c + - TARGET=java + - TARGET=net + - TARGET=ios + - TARGET=js before_install: - brew update @@ -24,53 +24,62 @@ before_install: # Java - | - [[ $LANG = "java" ]] && - brew cask install java && - export JAVA_HOME=$(/usr/libexec/java_home -v 1.8) && - export PATH=$JAVA_HOME/bin:$PATH + if [[ $TARGET = "java" ]]; then + brew cask install java; + export JAVA_HOME=$(/usr/libexec/java_home -v 1.8); + export PATH=$JAVA_HOME/bin:$PATH; + fi # .NET - | - [[ $LANG = "net" ]] && - brew install mono + if [[ $TARGET = "net" ]]; then + brew install mono; + fi # iOS - | - [[ $LANG = "ios" ]] && - brew upgrade xctool + if [[ $TARGET = "ios" ]]; then + brew upgrade xctool; + fi # JavaScript - | - [[ $LANG = "js" ]] && - cd javascript && - npm install + if [[ $TARGET = "js" ]]; then + cd javascript; + npm install; + fi script: # C - | - [[ $LANG = "c" ]] && - buck test //:yoga && - buck run //benchmark:benchmark && - git checkout HEAD^ && - buck run //benchmark:benchmark + if [[ $TARGET = "c" ]]; then + buck test --verbose 0 //:yoga; + buck run --verbose 0 //benchmark:benchmark; + git checkout HEAD^; + buck run --verbose 0 //benchmark:benchmark; + fi # Java - | - [[ $LANG = "java" ]] && - buck test //java:java + if [[ $TARGET = "java" ]]; then + buck test --verbose 0 //java:java; + fi # .NET - | - [[ $LANG = "net" ]] && - sh csharp/tests/Facebook.Yoga/test_macos.sh + if [[ $TARGET = "net" ]]; then + sh csharp/tests/Facebook.Yoga/test_macos.sh; + fi # iOS - | - [[ $LANG = "ios" ]] && - buck test //YogaKit:YogaKitTests --config cxx.default_platform=iphonesimulator-x86_64 + if [[ $TARGET = "ios" ]]; then + buck test --verbose 0 //YogaKit:YogaKitTests --config cxx.default_platform=iphonesimulator-x86_64; + fi # JavaScript - | - [[ $LANG = "js" ]] && - npm run test:all && - npm run bench + if [[ $TARGET = "js" ]]; then + npm run test:all; + npm run bench; + fi diff --git a/README.md b/README.md index a7e03de2..9c4ff28a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,10 @@ -# Yoga [![Build Status](https://travis-ci.org/facebook/yoga.svg?branch=master)](https://travis-ci.org/facebook/yoga) [![CocoaPods](https://img.shields.io/cocoapods/v/YogaKit.svg)](http://cocoapods.org/pods/YogaKit) [![npm](https://img.shields.io/npm/v/yoga-layout.svg)](https://www.npmjs.com/package/yoga-layout) +# Yoga [![CocoaPods](https://img.shields.io/cocoapods/v/YogaKit.svg)](http://cocoapods.org/pods/YogaKit) [![npm](https://img.shields.io/npm/v/yoga-layout.svg)](https://www.npmjs.com/package/yoga-layout) + +[![C Status](https://badges.herokuapp.com/travis/facebook/yoga?env=TARGET=c&label=C)](https://travis-ci.org/facebook/yoga) +[![Java Status](https://badges.herokuapp.com/travis/facebook/yoga?env=TARGET=java&label=Java)](https://travis-ci.org/facebook/yoga) +[![iOS Status](https://badges.herokuapp.com/travis/facebook/yoga?env=TARGET=ios&label=iOS)](https://travis-ci.org/facebook/yoga) +[![.NET Status](https://badges.herokuapp.com/travis/facebook/yoga?env=TARGET=net&label=.NET)](https://travis-ci.org/facebook/yoga) +[![JavaScript Status](https://badges.herokuapp.com/travis/facebook/yoga?env=TARGET=js&label=JavaScript)](https://travis-ci.org/facebook/yoga) ## Building Yoga builds with [buck](https://buckbuild.com). Make sure you install buck before contributing to Yoga. Yoga's main implementation is in C, with bindings to supported languages and frameworks. When making changes to Yoga please ensure the changes are also propagated to these bindings when applicable. From 55fe6f0bc9d7d4194e41813fe36810355c69a648 Mon Sep 17 00:00:00 2001 From: Dustin Shahidehpour Date: Mon, 13 Feb 2017 10:15:43 -0800 Subject: [PATCH 20/20] Add isDirty property and make markDirty less crashy/more performant. Summary: For some internal Instagram diffs, and some external ones (auto-detection of dirty nodes). We need to give the dirty properties a little love. This adds a getter to find out if your node is dirty, and makes sure that the leaf node is properly setup before it is marked dirty to prevent a crash. Reviewed By: emilsjolander Differential Revision: D4549241 fbshipit-source-id: 36eda6fdb4ea7f968d126aab6da67896f4a01d40 --- YogaKit/CHANGELOG.md | 2 ++ YogaKit/Source/YGLayout.h | 6 ++++++ YogaKit/Source/YGLayout.m | 19 +++++++++++++++++-- YogaKit/Tests/YogaKitTests.m | 18 ++++++++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/YogaKit/CHANGELOG.md b/YogaKit/CHANGELOG.md index 58f41d9b..c6b42a3a 100644 --- a/YogaKit/CHANGELOG.md +++ b/YogaKit/CHANGELOG.md @@ -42,3 +42,5 @@ view.configureLayout { (layout) in layout.height = 50 } ``` + +- Added new `isDirty` property, and make `markDirty` a little more performant. diff --git a/YogaKit/Source/YGLayout.h b/YogaKit/Source/YGLayout.h index e9f49b12..70a4b015 100644 --- a/YogaKit/Source/YGLayout.h +++ b/YogaKit/Source/YGLayout.h @@ -111,6 +111,12 @@ */ @property (nonatomic, readonly, assign) BOOL isLeaf; +/** + Return's a BOOL indicating if a view is dirty. When a node is dirty + it usually indicates that it will be remeasured on the next layout pass. + */ +@property (nonatomic, readonly, assign) BOOL isDirty; + /** Mark that a view's layout needs to be recalculated. Only works for leaf views. */ diff --git a/YogaKit/Source/YGLayout.m b/YogaKit/Source/YGLayout.m index d7240a8b..cd62f51a 100644 --- a/YogaKit/Source/YGLayout.m +++ b/YogaKit/Source/YGLayout.m @@ -120,11 +120,26 @@ YG_VALUE_EDGE_PROPERTY(lowercased_name, capitalized_name, capitalized_name, YGEd YGNodeFree(self.node); } +- (BOOL)isDirty +{ + return YGNodeIsDirty(self.node); +} + - (void)markDirty { - if (self.isLeaf) { - YGNodeMarkDirty(self.node); + if (self.isDirty || !self.isLeaf) { + return; } + + // Yoga is not happy if we try to mark a node as "dirty" before we have set + // the measure function. Since we already know that this is a leaf, + // this *should* be fine. Forgive me Hack Gods. + const YGNodeRef node = self.node; + if (YGNodeGetMeasureFunc(node) == NULL) { + YGNodeSetMeasureFunc(node, YGMeasureView); + } + + YGNodeMarkDirty(node); } - (NSUInteger)numberOfChildren diff --git a/YogaKit/Tests/YogaKitTests.m b/YogaKit/Tests/YogaKitTests.m index 5a1d56f1..dca193c4 100644 --- a/YogaKit/Tests/YogaKitTests.m +++ b/YogaKit/Tests/YogaKitTests.m @@ -153,6 +153,24 @@ XCTAssertEqual(25, view2.frame.origin.y); } +- (void)testMarkingDirtyOnlyWorksOnLeafNodes +{ + UIView *container = [[UIView alloc] initWithFrame:CGRectZero]; + container.yoga.isEnabled = YES; + + UIView *subview = [[UIView alloc] initWithFrame:CGRectZero]; + subview.yoga.isEnabled = YES; + [container addSubview:subview]; + + XCTAssertFalse(container.yoga.isDirty); + [container.yoga markDirty]; + XCTAssertFalse(container.yoga.isDirty); + + XCTAssertFalse(subview.yoga.isDirty); + [subview.yoga markDirty]; + XCTAssertTrue(subview.yoga.isDirty); +} + - (void)testThatMarkingLeafsAsDirtyWillTriggerASizeRecalculation { UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 50)];