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; }