From a69545a6ae5896b080c5b489f6be963bb8e7da32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20W=C3=B6hrl?= Date: Fri, 24 Nov 2017 07:06:16 -0800 Subject: [PATCH] Fix justify content with min/max constraint parent Summary: The min/max inner width shouldn't take the margins into account. Adds a test for both cases. Fixes #664 Closes https://github.com/facebook/yoga/pull/665 Differential Revision: D6407982 Pulled By: emilsjolander fbshipit-source-id: ffa549a06f802263e3b8488e90756aa3f722d52d --- .../Facebook.Yoga/YGJustifyContentTest.cs | 168 ++++++++++++++++ gentest/fixtures/YGJustifyContentTest.html | 16 ++ .../facebook/yoga/YGJustifyContentTest.java | 164 ++++++++++++++++ .../Facebook.Yoga/YGJustifyContentTest.js | 180 ++++++++++++++++++ tests/YGJustifyContentTest.cpp | 168 ++++++++++++++++ yoga/Yoga.cpp | 8 +- 6 files changed, 700 insertions(+), 4 deletions(-) diff --git a/csharp/tests/Facebook.Yoga/YGJustifyContentTest.cs b/csharp/tests/Facebook.Yoga/YGJustifyContentTest.cs index 7073164a..2fd58f5a 100644 --- a/csharp/tests/Facebook.Yoga/YGJustifyContentTest.cs +++ b/csharp/tests/Facebook.Yoga/YGJustifyContentTest.cs @@ -699,5 +699,173 @@ namespace Facebook.Yoga Assert.AreEqual(10f, root_child2.LayoutHeight); } + [Test] + public void Test_justify_content_row_min_width_and_margin() + { + YogaConfig config = new YogaConfig(); + + YogaNode root = new YogaNode(config); + root.FlexDirection = YogaFlexDirection.Row; + root.JustifyContent = YogaJustify.Center; + root.MarginLeft = 100; + root.MinWidth = 50; + + YogaNode root_child0 = new YogaNode(config); + root_child0.Width = 20; + root_child0.Height = 20; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(100f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(50f, root.LayoutWidth); + Assert.AreEqual(20f, root.LayoutHeight); + + Assert.AreEqual(15f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(20f, root_child0.LayoutWidth); + Assert.AreEqual(20f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(100f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(50f, root.LayoutWidth); + Assert.AreEqual(20f, root.LayoutHeight); + + Assert.AreEqual(15f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(20f, root_child0.LayoutWidth); + Assert.AreEqual(20f, root_child0.LayoutHeight); + } + + [Test] + public void Test_justify_content_row_max_width_and_margin() + { + YogaConfig config = new YogaConfig(); + + YogaNode root = new YogaNode(config); + root.FlexDirection = YogaFlexDirection.Row; + root.JustifyContent = YogaJustify.Center; + root.MarginLeft = 100; + root.Width = 100; + root.MaxWidth = 80; + + YogaNode root_child0 = new YogaNode(config); + root_child0.Width = 20; + root_child0.Height = 20; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(100f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(80f, root.LayoutWidth); + Assert.AreEqual(20f, root.LayoutHeight); + + Assert.AreEqual(30f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(20f, root_child0.LayoutWidth); + Assert.AreEqual(20f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(100f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(80f, root.LayoutWidth); + Assert.AreEqual(20f, root.LayoutHeight); + + Assert.AreEqual(30f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(20f, root_child0.LayoutWidth); + Assert.AreEqual(20f, root_child0.LayoutHeight); + } + + [Test] + public void Test_justify_content_column_min_height_and_margin() + { + YogaConfig config = new YogaConfig(); + + YogaNode root = new YogaNode(config); + root.JustifyContent = YogaJustify.Center; + root.MarginTop = 100; + root.MinHeight = 50; + + YogaNode root_child0 = new YogaNode(config); + root_child0.Width = 20; + root_child0.Height = 20; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(100f, root.LayoutY); + Assert.AreEqual(20f, root.LayoutWidth); + Assert.AreEqual(50f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(15f, root_child0.LayoutY); + Assert.AreEqual(20f, root_child0.LayoutWidth); + Assert.AreEqual(20f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(100f, root.LayoutY); + Assert.AreEqual(20f, root.LayoutWidth); + Assert.AreEqual(50f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(15f, root_child0.LayoutY); + Assert.AreEqual(20f, root_child0.LayoutWidth); + Assert.AreEqual(20f, root_child0.LayoutHeight); + } + + [Test] + public void Test_justify_content_colunn_max_height_and_margin() + { + YogaConfig config = new YogaConfig(); + + YogaNode root = new YogaNode(config); + root.JustifyContent = YogaJustify.Center; + root.MarginTop = 100; + root.Height = 100; + root.MaxHeight = 80; + + YogaNode root_child0 = new YogaNode(config); + root_child0.Width = 20; + root_child0.Height = 20; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(100f, root.LayoutY); + Assert.AreEqual(20f, root.LayoutWidth); + Assert.AreEqual(80f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(30f, root_child0.LayoutY); + Assert.AreEqual(20f, root_child0.LayoutWidth); + Assert.AreEqual(20f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(100f, root.LayoutY); + Assert.AreEqual(20f, root.LayoutWidth); + Assert.AreEqual(80f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(30f, root_child0.LayoutY); + Assert.AreEqual(20f, root_child0.LayoutWidth); + Assert.AreEqual(20f, root_child0.LayoutHeight); + } + } } diff --git a/gentest/fixtures/YGJustifyContentTest.html b/gentest/fixtures/YGJustifyContentTest.html index 16c0dcc6..a0808366 100644 --- a/gentest/fixtures/YGJustifyContentTest.html +++ b/gentest/fixtures/YGJustifyContentTest.html @@ -57,3 +57,19 @@
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
diff --git a/java/tests/com/facebook/yoga/YGJustifyContentTest.java b/java/tests/com/facebook/yoga/YGJustifyContentTest.java index 2728389b..d6566785 100644 --- a/java/tests/com/facebook/yoga/YGJustifyContentTest.java +++ b/java/tests/com/facebook/yoga/YGJustifyContentTest.java @@ -688,4 +688,168 @@ public class YGJustifyContentTest { assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); } + @Test + public void test_justify_content_row_min_width_and_margin() { + YogaConfig config = new YogaConfig(); + + final YogaNode root = new YogaNode(config); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setJustifyContent(YogaJustify.CENTER); + root.setMargin(YogaEdge.LEFT, 100f); + root.setMinWidth(50f); + + final YogaNode root_child0 = new YogaNode(config); + root_child0.setWidth(20f); + root_child0.setHeight(20f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(100f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(50f, root.getLayoutWidth(), 0.0f); + assertEquals(20f, root.getLayoutHeight(), 0.0f); + + assertEquals(15f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(20f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(100f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(50f, root.getLayoutWidth(), 0.0f); + assertEquals(20f, root.getLayoutHeight(), 0.0f); + + assertEquals(15f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(20f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_justify_content_row_max_width_and_margin() { + YogaConfig config = new YogaConfig(); + + final YogaNode root = new YogaNode(config); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setJustifyContent(YogaJustify.CENTER); + root.setMargin(YogaEdge.LEFT, 100f); + root.setWidth(100f); + root.setMaxWidth(80f); + + final YogaNode root_child0 = new YogaNode(config); + root_child0.setWidth(20f); + root_child0.setHeight(20f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(100f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(80f, root.getLayoutWidth(), 0.0f); + assertEquals(20f, root.getLayoutHeight(), 0.0f); + + assertEquals(30f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(20f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(100f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(80f, root.getLayoutWidth(), 0.0f); + assertEquals(20f, root.getLayoutHeight(), 0.0f); + + assertEquals(30f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(20f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_justify_content_column_min_height_and_margin() { + YogaConfig config = new YogaConfig(); + + final YogaNode root = new YogaNode(config); + root.setJustifyContent(YogaJustify.CENTER); + root.setMargin(YogaEdge.TOP, 100f); + root.setMinHeight(50f); + + final YogaNode root_child0 = new YogaNode(config); + root_child0.setWidth(20f); + root_child0.setHeight(20f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(100f, root.getLayoutY(), 0.0f); + assertEquals(20f, root.getLayoutWidth(), 0.0f); + assertEquals(50f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(15f, root_child0.getLayoutY(), 0.0f); + assertEquals(20f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(100f, root.getLayoutY(), 0.0f); + assertEquals(20f, root.getLayoutWidth(), 0.0f); + assertEquals(50f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(15f, root_child0.getLayoutY(), 0.0f); + assertEquals(20f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_justify_content_colunn_max_height_and_margin() { + YogaConfig config = new YogaConfig(); + + final YogaNode root = new YogaNode(config); + root.setJustifyContent(YogaJustify.CENTER); + root.setMargin(YogaEdge.TOP, 100f); + root.setHeight(100f); + root.setMaxHeight(80f); + + final YogaNode root_child0 = new YogaNode(config); + root_child0.setWidth(20f); + root_child0.setHeight(20f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(100f, root.getLayoutY(), 0.0f); + assertEquals(20f, root.getLayoutWidth(), 0.0f); + assertEquals(80f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(30f, root_child0.getLayoutY(), 0.0f); + assertEquals(20f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(100f, root.getLayoutY(), 0.0f); + assertEquals(20f, root.getLayoutWidth(), 0.0f); + assertEquals(80f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(30f, root_child0.getLayoutY(), 0.0f); + assertEquals(20f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0.getLayoutHeight(), 0.0f); + } + } diff --git a/javascript/tests/Facebook.Yoga/YGJustifyContentTest.js b/javascript/tests/Facebook.Yoga/YGJustifyContentTest.js index 20efc960..a1421e3f 100644 --- a/javascript/tests/Facebook.Yoga/YGJustifyContentTest.js +++ b/javascript/tests/Facebook.Yoga/YGJustifyContentTest.js @@ -723,3 +723,183 @@ it("justify_content_column_space_around", function () { config.free(); } }); +it("justify_content_row_min_width_and_margin", function () { + var config = Yoga.Config.create(); + + try { + var root = Yoga.Node.create(config); + root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); + root.setJustifyContent(Yoga.JUSTIFY_CENTER); + root.setMargin(Yoga.EDGE_LEFT, 100); + root.setMinWidth(50); + + var root_child0 = Yoga.Node.create(config); + root_child0.setWidth(20); + root_child0.setHeight(20); + root.insertChild(root_child0, 0); + root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR); + + console.assert(100 === root.getComputedLeft(), "100 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); + console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); + console.assert(50 === root.getComputedWidth(), "50 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(20 === root.getComputedHeight(), "20 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(15 === root_child0.getComputedLeft(), "15 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(20 === root_child0.getComputedWidth(), "20 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(20 === root_child0.getComputedHeight(), "20 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL); + + console.assert(100 === root.getComputedLeft(), "100 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); + console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); + console.assert(50 === root.getComputedWidth(), "50 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(20 === root.getComputedHeight(), "20 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(15 === root_child0.getComputedLeft(), "15 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(20 === root_child0.getComputedWidth(), "20 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(20 === root_child0.getComputedHeight(), "20 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + } finally { + if (typeof root !== "undefined") { + root.freeRecursive(); + } + + config.free(); + } +}); +it("justify_content_row_max_width_and_margin", function () { + var config = Yoga.Config.create(); + + try { + var root = Yoga.Node.create(config); + root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); + root.setJustifyContent(Yoga.JUSTIFY_CENTER); + root.setMargin(Yoga.EDGE_LEFT, 100); + root.setWidth(100); + root.setMaxWidth(80); + + var root_child0 = Yoga.Node.create(config); + root_child0.setWidth(20); + root_child0.setHeight(20); + root.insertChild(root_child0, 0); + root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR); + + console.assert(100 === root.getComputedLeft(), "100 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); + console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); + console.assert(80 === root.getComputedWidth(), "80 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(20 === root.getComputedHeight(), "20 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(30 === root_child0.getComputedLeft(), "30 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(20 === root_child0.getComputedWidth(), "20 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(20 === root_child0.getComputedHeight(), "20 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL); + + console.assert(100 === root.getComputedLeft(), "100 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); + console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); + console.assert(80 === root.getComputedWidth(), "80 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(20 === root.getComputedHeight(), "20 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(30 === root_child0.getComputedLeft(), "30 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(20 === root_child0.getComputedWidth(), "20 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(20 === root_child0.getComputedHeight(), "20 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + } finally { + if (typeof root !== "undefined") { + root.freeRecursive(); + } + + config.free(); + } +}); +it("justify_content_column_min_height_and_margin", function () { + var config = Yoga.Config.create(); + + try { + var root = Yoga.Node.create(config); + root.setJustifyContent(Yoga.JUSTIFY_CENTER); + root.setMargin(Yoga.EDGE_TOP, 100); + root.setMinHeight(50); + + var root_child0 = Yoga.Node.create(config); + root_child0.setWidth(20); + root_child0.setHeight(20); + 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(100 === root.getComputedTop(), "100 === root.getComputedTop() (" + root.getComputedTop() + ")"); + console.assert(20 === root.getComputedWidth(), "20 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(50 === root.getComputedHeight(), "50 === 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(20 === root_child0.getComputedWidth(), "20 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(20 === root_child0.getComputedHeight(), "20 === 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(100 === root.getComputedTop(), "100 === root.getComputedTop() (" + root.getComputedTop() + ")"); + console.assert(20 === root.getComputedWidth(), "20 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(50 === root.getComputedHeight(), "50 === 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(20 === root_child0.getComputedWidth(), "20 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(20 === root_child0.getComputedHeight(), "20 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + } finally { + if (typeof root !== "undefined") { + root.freeRecursive(); + } + + config.free(); + } +}); +it("justify_content_colunn_max_height_and_margin", function () { + var config = Yoga.Config.create(); + + try { + var root = Yoga.Node.create(config); + root.setJustifyContent(Yoga.JUSTIFY_CENTER); + root.setMargin(Yoga.EDGE_TOP, 100); + root.setHeight(100); + root.setMaxHeight(80); + + var root_child0 = Yoga.Node.create(config); + root_child0.setWidth(20); + root_child0.setHeight(20); + 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(100 === root.getComputedTop(), "100 === root.getComputedTop() (" + root.getComputedTop() + ")"); + console.assert(20 === root.getComputedWidth(), "20 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(80 === root.getComputedHeight(), "80 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(30 === root_child0.getComputedTop(), "30 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(20 === root_child0.getComputedWidth(), "20 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(20 === root_child0.getComputedHeight(), "20 === 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(100 === root.getComputedTop(), "100 === root.getComputedTop() (" + root.getComputedTop() + ")"); + console.assert(20 === root.getComputedWidth(), "20 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(80 === root.getComputedHeight(), "80 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(30 === root_child0.getComputedTop(), "30 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(20 === root_child0.getComputedWidth(), "20 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(20 === root_child0.getComputedHeight(), "20 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + } finally { + if (typeof root !== "undefined") { + root.freeRecursive(); + } + + config.free(); + } +}); diff --git a/tests/YGJustifyContentTest.cpp b/tests/YGJustifyContentTest.cpp index 98bf24a5..bb0861e9 100644 --- a/tests/YGJustifyContentTest.cpp +++ b/tests/YGJustifyContentTest.cpp @@ -693,3 +693,171 @@ TEST(YogaTest, justify_content_column_space_around) { YGConfigFree(config); } + +TEST(YogaTest, justify_content_row_min_width_and_margin) { + const YGConfigRef config = YGConfigNew(); + + const YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetJustifyContent(root, YGJustifyCenter); + YGNodeStyleSetMargin(root, YGEdgeLeft, 100); + YGNodeStyleSetMinWidth(root, 50); + + const YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetWidth(root_child0, 20); + YGNodeStyleSetHeight(root_child0, 20); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(15, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(15, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + +TEST(YogaTest, justify_content_row_max_width_and_margin) { + const YGConfigRef config = YGConfigNew(); + + const YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetJustifyContent(root, YGJustifyCenter); + YGNodeStyleSetMargin(root, YGEdgeLeft, 100); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetMaxWidth(root, 80); + + const YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetWidth(root_child0, 20); + YGNodeStyleSetHeight(root_child0, 20); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + +TEST(YogaTest, justify_content_column_min_height_and_margin) { + const YGConfigRef config = YGConfigNew(); + + const YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetJustifyContent(root, YGJustifyCenter); + YGNodeStyleSetMargin(root, YGEdgeTop, 100); + YGNodeStyleSetMinHeight(root, 50); + + const YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetWidth(root_child0, 20); + YGNodeStyleSetHeight(root_child0, 20); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(15, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(15, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + +TEST(YogaTest, justify_content_colunn_max_height_and_margin) { + const YGConfigRef config = YGConfigNew(); + + const YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetJustifyContent(root, YGJustifyCenter); + YGNodeStyleSetMargin(root, YGEdgeTop, 100); + YGNodeStyleSetHeight(root, 100); + YGNodeStyleSetMaxHeight(root, 80); + + const YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetWidth(root_child0, 20); + YGNodeStyleSetHeight(root_child0, 20); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 8ff8921a..cc685f4e 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -1862,17 +1862,17 @@ static void YGNodelayoutImpl(const YGNodeRef node, // STEP 2: DETERMINE AVAILABLE SIZE IN MAIN AND CROSS DIRECTIONS const float minInnerWidth = - YGResolveValue(&node->style.minDimensions[YGDimensionWidth], parentWidth) - marginAxisRow - + YGResolveValue(&node->style.minDimensions[YGDimensionWidth], parentWidth) - paddingAndBorderAxisRow; const float maxInnerWidth = - YGResolveValue(&node->style.maxDimensions[YGDimensionWidth], parentWidth) - marginAxisRow - + YGResolveValue(&node->style.maxDimensions[YGDimensionWidth], parentWidth) - paddingAndBorderAxisRow; const float minInnerHeight = YGResolveValue(&node->style.minDimensions[YGDimensionHeight], parentHeight) - - marginAxisColumn - paddingAndBorderAxisColumn; + paddingAndBorderAxisColumn; const float maxInnerHeight = YGResolveValue(&node->style.maxDimensions[YGDimensionHeight], parentHeight) - - marginAxisColumn - paddingAndBorderAxisColumn; + paddingAndBorderAxisColumn; const float minInnerMainDim = isMainAxisRow ? minInnerWidth : minInnerHeight; const float maxInnerMainDim = isMainAxisRow ? maxInnerWidth : maxInnerHeight;