diff --git a/csharp/Facebook.Yoga/YogaExperimentalFeature.cs b/csharp/Facebook.Yoga/YogaExperimentalFeature.cs index d6210367..8a353cae 100644 --- a/csharp/Facebook.Yoga/YogaExperimentalFeature.cs +++ b/csharp/Facebook.Yoga/YogaExperimentalFeature.cs @@ -12,6 +12,5 @@ namespace Facebook.Yoga public enum YogaExperimentalFeature { WebFlexBasis, - MinFlexFix, } } diff --git a/csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs b/csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs index 7b150568..cc3a74ab 100644 --- a/csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs +++ b/csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs @@ -1815,5 +1815,148 @@ namespace Facebook.Yoga Assert.AreEqual(72f, root_child0_child0.LayoutHeight); } + [Test] + public void Test_align_center_should_size_based_on_content() + { + YogaConfig config = new YogaConfig(); + + YogaNode root = new YogaNode(config); + root.AlignItems = YogaAlign.Center; + root.MarginTop = 20; + root.Width = 100; + root.Height = 100; + + YogaNode root_child0 = new YogaNode(config); + root_child0.JustifyContent = YogaJustify.Center; + root_child0.FlexShrink = 1; + root.Insert(0, root_child0); + + YogaNode root_child0_child0 = new YogaNode(config); + root_child0_child0.FlexGrow = 1; + root_child0_child0.FlexShrink = 1; + root_child0.Insert(0, root_child0_child0); + + YogaNode root_child0_child0_child0 = new YogaNode(config); + root_child0_child0_child0.Width = 20; + root_child0_child0_child0.Height = 20; + root_child0_child0.Insert(0, root_child0_child0_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(20f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(40f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(20f, root_child0.LayoutWidth); + Assert.AreEqual(20f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0.LayoutY); + Assert.AreEqual(20f, root_child0_child0.LayoutWidth); + Assert.AreEqual(20f, root_child0_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child0_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0_child0.LayoutY); + Assert.AreEqual(20f, root_child0_child0_child0.LayoutWidth); + Assert.AreEqual(20f, root_child0_child0_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(20f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(40f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(20f, root_child0.LayoutWidth); + Assert.AreEqual(20f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0.LayoutY); + Assert.AreEqual(20f, root_child0_child0.LayoutWidth); + Assert.AreEqual(20f, root_child0_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child0_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0_child0.LayoutY); + Assert.AreEqual(20f, root_child0_child0_child0.LayoutWidth); + Assert.AreEqual(20f, root_child0_child0_child0.LayoutHeight); + } + + [Test] + public void Test_align_strech_should_size_based_on_parent() + { + YogaConfig config = new YogaConfig(); + + YogaNode root = new YogaNode(config); + root.MarginTop = 20; + root.Width = 100; + root.Height = 100; + + YogaNode root_child0 = new YogaNode(config); + root_child0.JustifyContent = YogaJustify.Center; + root_child0.FlexShrink = 1; + root.Insert(0, root_child0); + + YogaNode root_child0_child0 = new YogaNode(config); + root_child0_child0.FlexGrow = 1; + root_child0_child0.FlexShrink = 1; + root_child0.Insert(0, root_child0_child0); + + YogaNode root_child0_child0_child0 = new YogaNode(config); + root_child0_child0_child0.Width = 20; + root_child0_child0_child0.Height = 20; + root_child0_child0.Insert(0, root_child0_child0_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(20f, 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(100f, root_child0.LayoutWidth); + Assert.AreEqual(20f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0.LayoutY); + Assert.AreEqual(100f, root_child0_child0.LayoutWidth); + Assert.AreEqual(20f, root_child0_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child0_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0_child0.LayoutY); + Assert.AreEqual(20f, root_child0_child0_child0.LayoutWidth); + Assert.AreEqual(20f, root_child0_child0_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(20f, 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(100f, root_child0.LayoutWidth); + Assert.AreEqual(20f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0.LayoutY); + Assert.AreEqual(100f, root_child0_child0.LayoutWidth); + Assert.AreEqual(20f, root_child0_child0.LayoutHeight); + + Assert.AreEqual(80f, root_child0_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0_child0.LayoutY); + Assert.AreEqual(20f, root_child0_child0_child0.LayoutWidth); + Assert.AreEqual(20f, root_child0_child0_child0.LayoutHeight); + } + } } diff --git a/csharp/tests/Facebook.Yoga/YGMinMaxDimensionTest.cs b/csharp/tests/Facebook.Yoga/YGMinMaxDimensionTest.cs index 1ff29a8a..a2843232 100644 --- a/csharp/tests/Facebook.Yoga/YGMinMaxDimensionTest.cs +++ b/csharp/tests/Facebook.Yoga/YGMinMaxDimensionTest.cs @@ -366,7 +366,6 @@ namespace Facebook.Yoga public void Test_flex_grow_to_min() { YogaConfig config = new YogaConfig(); - config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.MinFlexFix, true); YogaNode root = new YogaNode(config); root.Width = 100; @@ -422,7 +421,6 @@ namespace Facebook.Yoga public void Test_flex_grow_in_at_most_container() { YogaConfig config = new YogaConfig(); - config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.MinFlexFix, true); YogaNode root = new YogaNode(config); root.FlexDirection = YogaFlexDirection.Row; diff --git a/csharp/tests/Facebook.Yoga/YGPercentageTest.cs b/csharp/tests/Facebook.Yoga/YGPercentageTest.cs index fdf4d28e..f6b73e7f 100644 --- a/csharp/tests/Facebook.Yoga/YGPercentageTest.cs +++ b/csharp/tests/Facebook.Yoga/YGPercentageTest.cs @@ -1047,7 +1047,6 @@ namespace Facebook.Yoga public void Test_percentage_container_in_wrapping_container() { YogaConfig config = new YogaConfig(); - config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.MinFlexFix, true); YogaNode root = new YogaNode(config); root.JustifyContent = YogaJustify.Center; diff --git a/enums.py b/enums.py index 122df36b..731121c5 100644 --- a/enums.py +++ b/enums.py @@ -94,7 +94,6 @@ ENUMS = { 'ExperimentalFeature': [ # Mimic web flex-basis behavior. 'WebFlexBasis', - 'MinFlexFix' ], 'PrintOptions': [ ('Layout', 1), diff --git a/gentest/fixtures/YGAlignItemsTest.html b/gentest/fixtures/YGAlignItemsTest.html index 2c88c306..c7b3df1a 100644 --- a/gentest/fixtures/YGAlignItemsTest.html +++ b/gentest/fixtures/YGAlignItemsTest.html @@ -167,3 +167,20 @@
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+ diff --git a/gentest/fixtures/YGMinMaxDimensionTest.html b/gentest/fixtures/YGMinMaxDimensionTest.html index 264cf4f1..33745cd1 100644 --- a/gentest/fixtures/YGMinMaxDimensionTest.html +++ b/gentest/fixtures/YGMinMaxDimensionTest.html @@ -30,12 +30,12 @@
-
+
-
+
diff --git a/gentest/fixtures/YGPercentageTest.html b/gentest/fixtures/YGPercentageTest.html index 66b062c5..fa722198 100644 --- a/gentest/fixtures/YGPercentageTest.html +++ b/gentest/fixtures/YGPercentageTest.html @@ -92,7 +92,7 @@
-
+
diff --git a/java/com/facebook/yoga/YogaConfig.java b/java/com/facebook/yoga/YogaConfig.java index 8f86b0ad..6cad34ba 100644 --- a/java/com/facebook/yoga/YogaConfig.java +++ b/java/com/facebook/yoga/YogaConfig.java @@ -56,4 +56,15 @@ public class YogaConfig { public void setPointScaleFactor(float pixelsInPoint) { jni_YGConfigSetPointScaleFactor(mNativePointer, pixelsInPoint); } + + private native void jni_YGConfigSetUseLegacyStretchBehaviour(long nativePointer, boolean useLegacyStretchBehaviour); + + /** + * Yoga previously had an error where containers would take the maximum space possible instead of the minimum + * like they are supposed to. In practice this resulted in implicit behaviour similar to align-self: stretch; + * Because this was such a long-standing bug we must allow legacy users to switch back to this behaviour. + */ + public void setUseLegacyStretchBehaviour(boolean useLegacyStretchBehaviour) { + jni_YGConfigSetUseLegacyStretchBehaviour(mNativePointer, useLegacyStretchBehaviour); + } } diff --git a/java/com/facebook/yoga/YogaExperimentalFeature.java b/java/com/facebook/yoga/YogaExperimentalFeature.java index 178ece40..3d388515 100644 --- a/java/com/facebook/yoga/YogaExperimentalFeature.java +++ b/java/com/facebook/yoga/YogaExperimentalFeature.java @@ -13,8 +13,7 @@ import com.facebook.proguard.annotations.DoNotStrip; @DoNotStrip public enum YogaExperimentalFeature { - WEB_FLEX_BASIS(0), - MIN_FLEX_FIX(1); + WEB_FLEX_BASIS(0); private int mIntValue; @@ -29,7 +28,6 @@ public enum YogaExperimentalFeature { public static YogaExperimentalFeature fromInt(int value) { switch (value) { case 0: return WEB_FLEX_BASIS; - case 1: return MIN_FLEX_FIX; default: throw new IllegalArgumentException("Unknown enum value: " + value); } } diff --git a/java/jni/YGJNI.cpp b/java/jni/YGJNI.cpp index fd9e6081..ca0af8c0 100644 --- a/java/jni/YGJNI.cpp +++ b/java/jni/YGJNI.cpp @@ -408,6 +408,11 @@ void jni_YGConfigSetPointScaleFactor(alias_ref, jlong nativePointer, jf YGConfigSetPointScaleFactor(config, pixelsInPoint); } +void jni_YGConfigSetUseLegacyStretchBehaviour(alias_ref, jlong nativePointer, jboolean useLegacyStretchBehaviour) { + const YGConfigRef config = _jlong2YGConfigRef(nativePointer); + YGConfigSetUseLegacyStretchBehaviour(config, useLegacyStretchBehaviour); +} + jint jni_YGNodeGetInstanceCount(alias_ref clazz) { return YGNodeGetInstanceCount(); } @@ -504,6 +509,7 @@ jint JNI_OnLoad(JavaVM *vm, void *) { YGMakeNativeMethod(jni_YGConfigSetExperimentalFeatureEnabled), YGMakeNativeMethod(jni_YGConfigSetUseWebDefaults), YGMakeNativeMethod(jni_YGConfigSetPointScaleFactor), + YGMakeNativeMethod(jni_YGConfigSetUseLegacyStretchBehaviour), }); }); } diff --git a/java/tests/com/facebook/yoga/YGAlignItemsTest.java b/java/tests/com/facebook/yoga/YGAlignItemsTest.java index cea82fb5..15d7d842 100644 --- a/java/tests/com/facebook/yoga/YGAlignItemsTest.java +++ b/java/tests/com/facebook/yoga/YGAlignItemsTest.java @@ -1791,4 +1791,145 @@ public class YGAlignItemsTest { assertEquals(72f, root_child0_child0.getLayoutHeight(), 0.0f); } + @Test + public void test_align_center_should_size_based_on_content() { + YogaConfig config = new YogaConfig(); + + final YogaNode root = new YogaNode(config); + root.setAlignItems(YogaAlign.CENTER); + root.setMargin(YogaEdge.TOP, 20f); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(config); + root_child0.setJustifyContent(YogaJustify.CENTER); + root_child0.setFlexShrink(1f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child0_child0 = new YogaNode(config); + root_child0_child0.setFlexGrow(1f); + root_child0_child0.setFlexShrink(1f); + root_child0.addChildAt(root_child0_child0, 0); + + final YogaNode root_child0_child0_child0 = new YogaNode(config); + root_child0_child0_child0.setWidth(20f); + root_child0_child0_child0.setHeight(20f); + root_child0_child0.addChildAt(root_child0_child0_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(20f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(40f, 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); + + assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(20f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0_child0.getLayoutY(), 0.0f); + assertEquals(20f, root_child0_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0_child0_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(20f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(40f, 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); + + assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(20f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0_child0.getLayoutY(), 0.0f); + assertEquals(20f, root_child0_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0_child0_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_strech_should_size_based_on_parent() { + YogaConfig config = new YogaConfig(); + + final YogaNode root = new YogaNode(config); + root.setMargin(YogaEdge.TOP, 20f); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(config); + root_child0.setJustifyContent(YogaJustify.CENTER); + root_child0.setFlexShrink(1f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child0_child0 = new YogaNode(config); + root_child0_child0.setFlexGrow(1f); + root_child0_child0.setFlexShrink(1f); + root_child0.addChildAt(root_child0_child0, 0); + + final YogaNode root_child0_child0_child0 = new YogaNode(config); + root_child0_child0_child0.setWidth(20f); + root_child0_child0_child0.setHeight(20f); + root_child0_child0.addChildAt(root_child0_child0_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(20f, 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(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0_child0.getLayoutY(), 0.0f); + assertEquals(20f, root_child0_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0_child0_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(20f, 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(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0_child0.getLayoutHeight(), 0.0f); + + assertEquals(80f, root_child0_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0_child0.getLayoutY(), 0.0f); + assertEquals(20f, root_child0_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0_child0_child0.getLayoutHeight(), 0.0f); + } + } diff --git a/java/tests/com/facebook/yoga/YGMinMaxDimensionTest.java b/java/tests/com/facebook/yoga/YGMinMaxDimensionTest.java index 3c7064d7..fa285420 100644 --- a/java/tests/com/facebook/yoga/YGMinMaxDimensionTest.java +++ b/java/tests/com/facebook/yoga/YGMinMaxDimensionTest.java @@ -357,7 +357,6 @@ public class YGMinMaxDimensionTest { @Test public void test_flex_grow_to_min() { YogaConfig config = new YogaConfig(); - config.setExperimentalFeatureEnabled(YogaExperimentalFeature.MIN_FLEX_FIX, true); final YogaNode root = new YogaNode(config); root.setWidth(100f); @@ -412,7 +411,6 @@ public class YGMinMaxDimensionTest { @Test public void test_flex_grow_in_at_most_container() { YogaConfig config = new YogaConfig(); - config.setExperimentalFeatureEnabled(YogaExperimentalFeature.MIN_FLEX_FIX, true); final YogaNode root = new YogaNode(config); root.setFlexDirection(YogaFlexDirection.ROW); diff --git a/java/tests/com/facebook/yoga/YGPercentageTest.java b/java/tests/com/facebook/yoga/YGPercentageTest.java index c75356de..77e9c1d0 100644 --- a/java/tests/com/facebook/yoga/YGPercentageTest.java +++ b/java/tests/com/facebook/yoga/YGPercentageTest.java @@ -1027,7 +1027,6 @@ public class YGPercentageTest { @Test public void test_percentage_container_in_wrapping_container() { YogaConfig config = new YogaConfig(); - config.setExperimentalFeatureEnabled(YogaExperimentalFeature.MIN_FLEX_FIX, true); final YogaNode root = new YogaNode(config); root.setJustifyContent(YogaJustify.CENTER); diff --git a/javascript/sources/YGEnums.js b/javascript/sources/YGEnums.js index d4596827..e19aeb9a 100644 --- a/javascript/sources/YGEnums.js +++ b/javascript/sources/YGEnums.js @@ -43,9 +43,8 @@ module.exports = { EDGE_VERTICAL: 7, EDGE_ALL: 8, - EXPERIMENTAL_FEATURE_COUNT: 2, + EXPERIMENTAL_FEATURE_COUNT: 1, EXPERIMENTAL_FEATURE_WEB_FLEX_BASIS: 0, - EXPERIMENTAL_FEATURE_MIN_FLEX_FIX: 1, FLEX_DIRECTION_COUNT: 4, FLEX_DIRECTION_COLUMN: 0, diff --git a/javascript/tests/Facebook.Yoga/YGAlignItemsTest.js b/javascript/tests/Facebook.Yoga/YGAlignItemsTest.js index 3a95b980..28a9a980 100644 --- a/javascript/tests/Facebook.Yoga/YGAlignItemsTest.js +++ b/javascript/tests/Facebook.Yoga/YGAlignItemsTest.js @@ -1878,3 +1878,152 @@ it("align_items_flex_end_child_without_margin_bigger_than_parent", function () { config.free(); } }); +it("align_center_should_size_based_on_content", function () { + var config = Yoga.Config.create(); + + try { + var root = Yoga.Node.create(config); + root.setAlignItems(Yoga.ALIGN_CENTER); + root.setMargin(Yoga.EDGE_TOP, 20); + root.setWidth(100); + root.setHeight(100); + + var root_child0 = Yoga.Node.create(config); + root_child0.setJustifyContent(Yoga.JUSTIFY_CENTER); + root_child0.setFlexShrink(1); + root.insertChild(root_child0, 0); + + var root_child0_child0 = Yoga.Node.create(config); + root_child0_child0.setFlexGrow(1); + root_child0_child0.setFlexShrink(1); + root_child0.insertChild(root_child0_child0, 0); + + var root_child0_child0_child0 = Yoga.Node.create(config); + root_child0_child0_child0.setWidth(20); + root_child0_child0_child0.setHeight(20); + root_child0_child0.insertChild(root_child0_child0_child0, 0); + root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR); + + console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); + console.assert(20 === root.getComputedTop(), "20 === 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(40 === root_child0.getComputedLeft(), "40 === 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() + ")"); + + 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(20 === root_child0_child0.getComputedWidth(), "20 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")"); + console.assert(20 === root_child0_child0.getComputedHeight(), "20 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")"); + + console.assert(0 === root_child0_child0_child0.getComputedLeft(), "0 === root_child0_child0_child0.getComputedLeft() (" + root_child0_child0_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0_child0_child0.getComputedTop(), "0 === root_child0_child0_child0.getComputedTop() (" + root_child0_child0_child0.getComputedTop() + ")"); + console.assert(20 === root_child0_child0_child0.getComputedWidth(), "20 === root_child0_child0_child0.getComputedWidth() (" + root_child0_child0_child0.getComputedWidth() + ")"); + console.assert(20 === root_child0_child0_child0.getComputedHeight(), "20 === root_child0_child0_child0.getComputedHeight() (" + root_child0_child0_child0.getComputedHeight() + ")"); + + root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL); + + console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); + console.assert(20 === root.getComputedTop(), "20 === 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(40 === root_child0.getComputedLeft(), "40 === 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() + ")"); + + 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(20 === root_child0_child0.getComputedWidth(), "20 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")"); + console.assert(20 === root_child0_child0.getComputedHeight(), "20 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")"); + + console.assert(0 === root_child0_child0_child0.getComputedLeft(), "0 === root_child0_child0_child0.getComputedLeft() (" + root_child0_child0_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0_child0_child0.getComputedTop(), "0 === root_child0_child0_child0.getComputedTop() (" + root_child0_child0_child0.getComputedTop() + ")"); + console.assert(20 === root_child0_child0_child0.getComputedWidth(), "20 === root_child0_child0_child0.getComputedWidth() (" + root_child0_child0_child0.getComputedWidth() + ")"); + console.assert(20 === root_child0_child0_child0.getComputedHeight(), "20 === root_child0_child0_child0.getComputedHeight() (" + root_child0_child0_child0.getComputedHeight() + ")"); + } finally { + if (typeof root !== "undefined") { + root.freeRecursive(); + } + + config.free(); + } +}); +it("align_strech_should_size_based_on_parent", function () { + var config = Yoga.Config.create(); + + try { + var root = Yoga.Node.create(config); + root.setMargin(Yoga.EDGE_TOP, 20); + root.setWidth(100); + root.setHeight(100); + + var root_child0 = Yoga.Node.create(config); + root_child0.setJustifyContent(Yoga.JUSTIFY_CENTER); + root_child0.setFlexShrink(1); + root.insertChild(root_child0, 0); + + var root_child0_child0 = Yoga.Node.create(config); + root_child0_child0.setFlexGrow(1); + root_child0_child0.setFlexShrink(1); + root_child0.insertChild(root_child0_child0, 0); + + var root_child0_child0_child0 = Yoga.Node.create(config); + root_child0_child0_child0.setWidth(20); + root_child0_child0_child0.setHeight(20); + root_child0_child0.insertChild(root_child0_child0_child0, 0); + root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR); + + console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); + console.assert(20 === root.getComputedTop(), "20 === 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(100 === root_child0.getComputedWidth(), "100 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(20 === root_child0.getComputedHeight(), "20 === 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(100 === root_child0_child0.getComputedWidth(), "100 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")"); + console.assert(20 === root_child0_child0.getComputedHeight(), "20 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")"); + + console.assert(0 === root_child0_child0_child0.getComputedLeft(), "0 === root_child0_child0_child0.getComputedLeft() (" + root_child0_child0_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0_child0_child0.getComputedTop(), "0 === root_child0_child0_child0.getComputedTop() (" + root_child0_child0_child0.getComputedTop() + ")"); + console.assert(20 === root_child0_child0_child0.getComputedWidth(), "20 === root_child0_child0_child0.getComputedWidth() (" + root_child0_child0_child0.getComputedWidth() + ")"); + console.assert(20 === root_child0_child0_child0.getComputedHeight(), "20 === root_child0_child0_child0.getComputedHeight() (" + root_child0_child0_child0.getComputedHeight() + ")"); + + root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL); + + console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); + console.assert(20 === root.getComputedTop(), "20 === 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(100 === root_child0.getComputedWidth(), "100 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(20 === root_child0.getComputedHeight(), "20 === 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(100 === root_child0_child0.getComputedWidth(), "100 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")"); + console.assert(20 === root_child0_child0.getComputedHeight(), "20 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")"); + + console.assert(80 === root_child0_child0_child0.getComputedLeft(), "80 === root_child0_child0_child0.getComputedLeft() (" + root_child0_child0_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0_child0_child0.getComputedTop(), "0 === root_child0_child0_child0.getComputedTop() (" + root_child0_child0_child0.getComputedTop() + ")"); + console.assert(20 === root_child0_child0_child0.getComputedWidth(), "20 === root_child0_child0_child0.getComputedWidth() (" + root_child0_child0_child0.getComputedWidth() + ")"); + console.assert(20 === root_child0_child0_child0.getComputedHeight(), "20 === root_child0_child0_child0.getComputedHeight() (" + root_child0_child0_child0.getComputedHeight() + ")"); + } finally { + if (typeof root !== "undefined") { + root.freeRecursive(); + } + + config.free(); + } +}); diff --git a/javascript/tests/Facebook.Yoga/YGMinMaxDimensionTest.js b/javascript/tests/Facebook.Yoga/YGMinMaxDimensionTest.js index c404235f..4dfc511f 100644 --- a/javascript/tests/Facebook.Yoga/YGMinMaxDimensionTest.js +++ b/javascript/tests/Facebook.Yoga/YGMinMaxDimensionTest.js @@ -380,8 +380,6 @@ it("justify_content_overflow_min_max", function () { it("flex_grow_to_min", function () { var config = Yoga.Config.create(); - config.setExperimentalFeatureEnabled(Yoga.EXPERIMENTAL_FEATURE_MIN_FLEX_FIX, true); - try { var root = Yoga.Node.create(config); root.setWidth(100); @@ -440,8 +438,6 @@ it("flex_grow_to_min", function () { it("flex_grow_in_at_most_container", function () { var config = Yoga.Config.create(); - config.setExperimentalFeatureEnabled(Yoga.EXPERIMENTAL_FEATURE_MIN_FLEX_FIX, true); - try { var root = Yoga.Node.create(config); root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); diff --git a/javascript/tests/Facebook.Yoga/YGPercentageTest.js b/javascript/tests/Facebook.Yoga/YGPercentageTest.js index 350bb48b..1c9351c7 100644 --- a/javascript/tests/Facebook.Yoga/YGPercentageTest.js +++ b/javascript/tests/Facebook.Yoga/YGPercentageTest.js @@ -1094,8 +1094,6 @@ it("percent_within_flex_grow", function () { it("percentage_container_in_wrapping_container", function () { var config = Yoga.Config.create(); - config.setExperimentalFeatureEnabled(Yoga.EXPERIMENTAL_FEATURE_MIN_FLEX_FIX, true); - try { var root = Yoga.Node.create(config); root.setJustifyContent(Yoga.JUSTIFY_CENTER); diff --git a/tests/YGAlignItemsTest.cpp b/tests/YGAlignItemsTest.cpp index 8fe2deff..33eaab9c 100644 --- a/tests/YGAlignItemsTest.cpp +++ b/tests/YGAlignItemsTest.cpp @@ -1809,3 +1809,146 @@ TEST(YogaTest, align_items_flex_end_child_without_margin_bigger_than_parent) { YGConfigFree(config); } + +TEST(YogaTest, align_center_should_size_based_on_content) { + const YGConfigRef config = YGConfigNew(); + + const YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetAlignItems(root, YGAlignCenter); + YGNodeStyleSetMargin(root, YGEdgeTop, 20); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetJustifyContent(root_child0, YGJustifyCenter); + YGNodeStyleSetFlexShrink(root_child0, 1); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetFlexGrow(root_child0_child0, 1); + YGNodeStyleSetFlexShrink(root_child0_child0, 1); + YGNodeInsertChild(root_child0, root_child0_child0, 0); + + const YGNodeRef root_child0_child0_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetWidth(root_child0_child0_child0, 20); + YGNodeStyleSetHeight(root_child0_child0_child0, 20); + YGNodeInsertChild(root_child0_child0, root_child0_child0_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0_child0_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0_child0_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0_child0_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0_child0_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + +TEST(YogaTest, align_strech_should_size_based_on_parent) { + const YGConfigRef config = YGConfigNew(); + + const YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetMargin(root, YGEdgeTop, 20); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetJustifyContent(root_child0, YGJustifyCenter); + YGNodeStyleSetFlexShrink(root_child0, 1); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetFlexGrow(root_child0_child0, 1); + YGNodeStyleSetFlexShrink(root_child0_child0, 1); + YGNodeInsertChild(root_child0, root_child0_child0, 0); + + const YGNodeRef root_child0_child0_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetWidth(root_child0_child0_child0, 20); + YGNodeStyleSetHeight(root_child0_child0_child0, 20); + YGNodeInsertChild(root_child0_child0, root_child0_child0_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(20, 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(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0_child0_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0_child0_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(20, 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(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0_child0)); + + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child0_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0_child0_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0_child0_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} diff --git a/tests/YGMinMaxDimensionTest.cpp b/tests/YGMinMaxDimensionTest.cpp index 40306404..610429e0 100644 --- a/tests/YGMinMaxDimensionTest.cpp +++ b/tests/YGMinMaxDimensionTest.cpp @@ -359,7 +359,6 @@ TEST(YogaTest, justify_content_overflow_min_max) { TEST(YogaTest, flex_grow_to_min) { const YGConfigRef config = YGConfigNew(); - YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureMinFlexFix, true); const YGNodeRef root = YGNodeNewWithConfig(config); YGNodeStyleSetWidth(root, 100); @@ -415,7 +414,6 @@ TEST(YogaTest, flex_grow_to_min) { TEST(YogaTest, flex_grow_in_at_most_container) { const YGConfigRef config = YGConfigNew(); - YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureMinFlexFix, true); const YGNodeRef root = YGNodeNewWithConfig(config); YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); diff --git a/tests/YGPercentageTest.cpp b/tests/YGPercentageTest.cpp index 3dbe951d..4825b3a3 100644 --- a/tests/YGPercentageTest.cpp +++ b/tests/YGPercentageTest.cpp @@ -1040,7 +1040,6 @@ TEST(YogaTest, percent_within_flex_grow) { TEST(YogaTest, percentage_container_in_wrapping_container) { const YGConfigRef config = YGConfigNew(); - YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureMinFlexFix, true); const YGNodeRef root = YGNodeNewWithConfig(config); YGNodeStyleSetJustifyContent(root, YGJustifyCenter); diff --git a/yoga/YGEnums.c b/yoga/YGEnums.c index c3e4521c..85e8fcf0 100644 --- a/yoga/YGEnums.c +++ b/yoga/YGEnums.c @@ -91,8 +91,6 @@ const char *YGExperimentalFeatureToString(const YGExperimentalFeature value){ switch(value){ case YGExperimentalFeatureWebFlexBasis: return "web-flex-basis"; - case YGExperimentalFeatureMinFlexFix: - return "min-flex-fix"; } return "unknown"; } diff --git a/yoga/YGEnums.h b/yoga/YGEnums.h index 972c5210..db64e3d7 100644 --- a/yoga/YGEnums.h +++ b/yoga/YGEnums.h @@ -62,10 +62,9 @@ typedef YG_ENUM_BEGIN(YGEdge) { } YG_ENUM_END(YGEdge); WIN_EXPORT const char *YGEdgeToString(const YGEdge value); -#define YGExperimentalFeatureCount 2 +#define YGExperimentalFeatureCount 1 typedef YG_ENUM_BEGIN(YGExperimentalFeature) { YGExperimentalFeatureWebFlexBasis, - YGExperimentalFeatureMinFlexFix, } YG_ENUM_END(YGExperimentalFeature); WIN_EXPORT const char *YGExperimentalFeatureToString(const YGExperimentalFeature value); diff --git a/yoga/Yoga.c b/yoga/Yoga.c index 2ec84287..06bbc952 100644 --- a/yoga/Yoga.c +++ b/yoga/Yoga.c @@ -97,6 +97,7 @@ typedef struct YGStyle { typedef struct YGConfig { bool experimentalFeatures[YGExperimentalFeatureCount + 1]; bool useWebDefaults; + bool useLegacyStretchBehaviour; float pointScaleFactor; } YGConfig; @@ -202,7 +203,6 @@ static YGNode gYGNodeDefaults = { static YGConfig gYGConfigDefaults = { .experimentalFeatures = { - [YGExperimentalFeatureMinFlexFix] = false, [YGExperimentalFeatureWebFlexBasis] = false, }, .useWebDefaults = false, @@ -2199,23 +2199,25 @@ static void YGNodelayoutImpl(const YGNodeRef node, // If the main dimension size isn't known, it is computed based on // the line length, so there's no more space left to distribute. + bool sizeBasedOnContent = false; // If we don't measure with exact main dimension we want to ensure we don't violate min and max if (measureModeMainDim != YGMeasureModeExactly) { if (!YGFloatIsUndefined(minInnerMainDim) && sizeConsumedOnCurrentLine < minInnerMainDim) { availableInnerMainDim = minInnerMainDim; } else if (!YGFloatIsUndefined(maxInnerMainDim) && sizeConsumedOnCurrentLine > maxInnerMainDim) { availableInnerMainDim = maxInnerMainDim; - } else if (YGConfigIsExperimentalFeatureEnabled(node->config, YGExperimentalFeatureMinFlexFix) && - (totalFlexGrowFactors == 0 || YGResolveFlexGrow(node) == 0)) { - // TODO: this needs to be moved out of experimental feature, as this is legitimate fix - // If we don't have any children to flex or we can't flex the node itself, - // space we've used is all space we need - availableInnerMainDim = sizeConsumedOnCurrentLine; + } else { + if (!node->config->useLegacyStretchBehaviour && (totalFlexGrowFactors == 0 || YGResolveFlexGrow(node) == 0)) { + // If we don't have any children to flex or we can't flex the node itself, + // space we've used is all space we need + availableInnerMainDim = sizeConsumedOnCurrentLine; + } + sizeBasedOnContent = true; } } float remainingFreeSpace = 0; - if (!YGFloatIsUndefined(availableInnerMainDim)) { + if ((!sizeBasedOnContent || node->config->useLegacyStretchBehaviour) && !YGFloatIsUndefined(availableInnerMainDim)) { remainingFreeSpace = availableInnerMainDim - sizeConsumedOnCurrentLine; } else if (sizeConsumedOnCurrentLine < 0) { // availableInnerMainDim is indefinite which means the node is being sized @@ -3427,6 +3429,10 @@ void YGConfigSetUseWebDefaults(const YGConfigRef config, const bool enabled) { config->useWebDefaults = enabled; } +void YGConfigSetUseLegacyStretchBehaviour(const YGConfigRef config, const bool useLegacyStretchBehaviour) { + config->useLegacyStretchBehaviour = useLegacyStretchBehaviour; +} + bool YGConfigGetUseWebDefaults(const YGConfigRef config) { return config->useWebDefaults; } diff --git a/yoga/Yoga.h b/yoga/Yoga.h index 4a6de72b..a26a1e9a 100644 --- a/yoga/Yoga.h +++ b/yoga/Yoga.h @@ -225,6 +225,11 @@ WIN_EXPORT void YGLog(YGLogLevel level, const char *message, ...); // If you want to avoid rounding - set PointScaleFactor to 0 WIN_EXPORT void YGConfigSetPointScaleFactor(const YGConfigRef config, const float pixelsInPoint); +// Yoga previously had an error where containers would take the maximum space possible instead of the minimum +// like they are supposed to. In practice this resulted in implicit behaviour similar to align-self: stretch; +// Because this was such a long-standing bug we must allow legacy users to switch back to this behaviour. +WIN_EXPORT void YGConfigSetUseLegacyStretchBehaviour(const YGConfigRef config, const bool useLegacyStretchBehaviour); + // YGConfig WIN_EXPORT YGConfigRef YGConfigNew(void); WIN_EXPORT void YGConfigFree(const YGConfigRef config);