diff --git a/enums.py b/enums.py
index 83bd85271c..22e9d56f02 100755
--- a/enums.py
+++ b/enums.py
@@ -69,6 +69,9 @@
# Fix flex basis computation to not apply FitContent constraint in the
# main axis for non-measure container nodes
"FixFlexBasisFitContent",
+ # Measure a leaf's min-content height at the width it is given instead
+ # of asking for a height of at most zero
+ "MinContentHeightAtGivenWidth",
],
"Gutter": ["Column", "Row", "All"],
"GridTrackType": ["Auto", "Points", "Percent", "Fr", "Minmax"],
diff --git a/gentest/fixtures/YGAutoMinSizeTest.html b/gentest/fixtures/YGAutoMinSizeTest.html
index f2becdd280..0bb7b7b0ab 100644
--- a/gentest/fixtures/YGAutoMinSizeTest.html
+++ b/gentest/fixtures/YGAutoMinSizeTest.html
@@ -237,3 +237,129 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/java/com/facebook/yoga/YogaExperimentalFeature.kt b/java/com/facebook/yoga/YogaExperimentalFeature.kt
index aec70ac246..bf122ae07f 100644
--- a/java/com/facebook/yoga/YogaExperimentalFeature.kt
+++ b/java/com/facebook/yoga/YogaExperimentalFeature.kt
@@ -11,7 +11,8 @@ package com.facebook.yoga
public enum class YogaExperimentalFeature(public val intValue: Int) {
WEB_FLEX_BASIS(0),
- FIX_FLEX_BASIS_FIT_CONTENT(1);
+ FIX_FLEX_BASIS_FIT_CONTENT(1),
+ MIN_CONTENT_HEIGHT_AT_GIVEN_WIDTH(2);
public fun intValue(): Int = intValue
@@ -21,6 +22,7 @@ public enum class YogaExperimentalFeature(public val intValue: Int) {
when (value) {
0 -> WEB_FLEX_BASIS
1 -> FIX_FLEX_BASIS_FIT_CONTENT
+ 2 -> MIN_CONTENT_HEIGHT_AT_GIVEN_WIDTH
else -> throw IllegalArgumentException("Unknown enum value: $value")
}
}
diff --git a/java/tests/generated/com/facebook/yoga/YGAutoMinSizeTest.java b/java/tests/generated/com/facebook/yoga/YGAutoMinSizeTest.java
index b2daebbb59..ae645ffa4a 100644
--- a/java/tests/generated/com/facebook/yoga/YGAutoMinSizeTest.java
+++ b/java/tests/generated/com/facebook/yoga/YGAutoMinSizeTest.java
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
- * @generated SignedSource<<3b2b3cdb3eb43c1b4acb8970fc876dba>>
+ * @generated SignedSource<<2a9aaf1d014eb3ce03c0ce72b5d1f4a6>>
* generated by gentest/src/GentestDriver.ts from gentest/fixtures/YGAutoMinSizeTest.html
*/
@@ -1995,6 +1995,927 @@ public void test_auto_min_size_wrapping_column_counts_all_children() {
assertEquals(180f, root_child1.getLayoutHeight(), 0.0f);
}
+ @Test
+ public void test_auto_min_size_text_keeps_wrapped_lines() {
+ YogaConfig config = YogaConfigFactory.create();
+ config.setExperimentalFeatureEnabled(YogaExperimentalFeature.MIN_CONTENT_HEIGHT_AT_GIVEN_WIDTH, true);
+ config.setErrata(YogaErrata.NONE);
+
+ final YogaNode root = createNode(config);
+ root.setPositionType(YogaPositionType.ABSOLUTE);
+ root.setWidth(50f);
+ root.setHeight(20f);
+
+ final YogaNode root_child0 = createNode(config);
+ root_child0.setFlexShrink(1f);
+ root.addChildAt(root_child0, 0);
+ root_child0.setData("aaaa aaaa aaaa");
+ root_child0.setMeasureFunction(new TestUtils.intrinsicMeasureFunction());
+
+ final YogaNode root_child1 = createNode(config);
+ root_child1.setHeight(10f);
+ root.addChildAt(root_child1, 1);
+ root.setDirection(YogaDirection.LTR);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(50f, root.getLayoutWidth(), 0.0f);
+ assertEquals(20f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(30f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(30f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutHeight(), 0.0f);
+
+ root.setDirection(YogaDirection.RTL);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(50f, root.getLayoutWidth(), 0.0f);
+ assertEquals(20f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(30f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(30f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutHeight(), 0.0f);
+ }
+
+ @Test
+ public void test_auto_min_size_nested_text_keeps_wrapped_lines() {
+ YogaConfig config = YogaConfigFactory.create();
+ config.setExperimentalFeatureEnabled(YogaExperimentalFeature.MIN_CONTENT_HEIGHT_AT_GIVEN_WIDTH, true);
+ config.setErrata(YogaErrata.NONE);
+
+ final YogaNode root = createNode(config);
+ root.setPositionType(YogaPositionType.ABSOLUTE);
+ root.setWidth(50f);
+ root.setHeight(20f);
+
+ final YogaNode root_child0 = createNode(config);
+ root_child0.setFlexShrink(1f);
+ root.addChildAt(root_child0, 0);
+
+ final YogaNode root_child0_child0 = createNode(config);
+ root_child0_child0.setMargin(YogaEdge.BOTTOM, 5f);
+ root_child0.addChildAt(root_child0_child0, 0);
+ root_child0_child0.setData("aaaa aaaa aaaa");
+ root_child0_child0.setMeasureFunction(new TestUtils.intrinsicMeasureFunction());
+
+ final YogaNode root_child1 = createNode(config);
+ root_child1.setHeight(10f);
+ root.addChildAt(root_child1, 1);
+ root.setDirection(YogaDirection.LTR);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(50f, root.getLayoutWidth(), 0.0f);
+ assertEquals(20f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(35f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f);
+ assertEquals(30f, root_child0_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(35f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutHeight(), 0.0f);
+
+ root.setDirection(YogaDirection.RTL);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(50f, root.getLayoutWidth(), 0.0f);
+ assertEquals(20f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(35f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f);
+ assertEquals(30f, root_child0_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(35f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutHeight(), 0.0f);
+ }
+
+ @Test
+ public void test_auto_min_size_text_wraps_inside_margin_and_padding() {
+ YogaConfig config = YogaConfigFactory.create();
+ config.setExperimentalFeatureEnabled(YogaExperimentalFeature.MIN_CONTENT_HEIGHT_AT_GIVEN_WIDTH, true);
+ config.setErrata(YogaErrata.NONE);
+
+ final YogaNode root = createNode(config);
+ root.setPositionType(YogaPositionType.ABSOLUTE);
+ root.setWidth(110f);
+ root.setHeight(20f);
+
+ final YogaNode root_child0 = createNode(config);
+ root_child0.setFlexShrink(1f);
+ root_child0.setMargin(YogaEdge.VERTICAL, 0f);
+ root_child0.setMargin(YogaEdge.HORIZONTAL, 10f);
+ root_child0.setPadding(YogaEdge.VERTICAL, 0);
+ root_child0.setPadding(YogaEdge.HORIZONTAL, 20);
+ root.addChildAt(root_child0, 0);
+ root_child0.setData("aaaa aaaa aaaa");
+ root_child0.setMeasureFunction(new TestUtils.intrinsicMeasureFunction());
+
+ final YogaNode root_child1 = createNode(config);
+ root_child1.setHeight(10f);
+ root.addChildAt(root_child1, 1);
+ root.setDirection(YogaDirection.LTR);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(110f, root.getLayoutWidth(), 0.0f);
+ assertEquals(20f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(10f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(90f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(30f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(30f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(110f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutHeight(), 0.0f);
+
+ root.setDirection(YogaDirection.RTL);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(110f, root.getLayoutWidth(), 0.0f);
+ assertEquals(20f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(10f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(90f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(30f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(30f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(110f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutHeight(), 0.0f);
+ }
+
+ @Test
+ public void test_auto_min_size_text_wraps_at_stated_width() {
+ YogaConfig config = YogaConfigFactory.create();
+ config.setExperimentalFeatureEnabled(YogaExperimentalFeature.MIN_CONTENT_HEIGHT_AT_GIVEN_WIDTH, true);
+ config.setErrata(YogaErrata.NONE);
+
+ final YogaNode root = createNode(config);
+ root.setPositionType(YogaPositionType.ABSOLUTE);
+ root.setWidth(110f);
+ root.setHeight(20f);
+
+ final YogaNode root_child0 = createNode(config);
+ root_child0.setFlexShrink(1f);
+ root_child0.setWidthPercent(50f);
+ root_child0.setPadding(YogaEdge.VERTICAL, 0);
+ root_child0.setPadding(YogaEdge.HORIZONTAL, 5);
+ root.addChildAt(root_child0, 0);
+ root_child0.setData("aaaa aaaa aaaa");
+ root_child0.setMeasureFunction(new TestUtils.intrinsicMeasureFunction());
+
+ final YogaNode root_child1 = createNode(config);
+ root_child1.setHeight(10f);
+ root.addChildAt(root_child1, 1);
+ root.setDirection(YogaDirection.LTR);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(110f, root.getLayoutWidth(), 0.0f);
+ assertEquals(20f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(55f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(30f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(30f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(110f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutHeight(), 0.0f);
+
+ root.setDirection(YogaDirection.RTL);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(110f, root.getLayoutWidth(), 0.0f);
+ assertEquals(20f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(55f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(55f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(30f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(30f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(110f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutHeight(), 0.0f);
+ }
+
+ @Test
+ public void test_auto_min_size_text_wraps_at_stated_content_box_width() {
+ YogaConfig config = YogaConfigFactory.create();
+ config.setExperimentalFeatureEnabled(YogaExperimentalFeature.MIN_CONTENT_HEIGHT_AT_GIVEN_WIDTH, true);
+ config.setErrata(YogaErrata.NONE);
+
+ final YogaNode root = createNode(config);
+ root.setPositionType(YogaPositionType.ABSOLUTE);
+ root.setWidth(200f);
+ root.setHeight(20f);
+
+ final YogaNode root_child0 = createNode(config);
+ root_child0.setFlexShrink(1f);
+ root_child0.setBoxSizing(YogaBoxSizing.CONTENT_BOX);
+ root_child0.setWidth(90f);
+ root_child0.setPadding(YogaEdge.VERTICAL, 0);
+ root_child0.setPadding(YogaEdge.HORIZONTAL, 20);
+ root.addChildAt(root_child0, 0);
+ root_child0.setData("aaaa aaaa aaaa");
+ root_child0.setMeasureFunction(new TestUtils.intrinsicMeasureFunction());
+
+ final YogaNode root_child1 = createNode(config);
+ root_child1.setHeight(15f);
+ root.addChildAt(root_child1, 1);
+ root.setDirection(YogaDirection.LTR);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(200f, root.getLayoutWidth(), 0.0f);
+ assertEquals(20f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(130f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(20f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(20f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(200f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(15f, root_child1.getLayoutHeight(), 0.0f);
+
+ root.setDirection(YogaDirection.RTL);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(200f, root.getLayoutWidth(), 0.0f);
+ assertEquals(20f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(70f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(130f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(20f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(20f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(200f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(15f, root_child1.getLayoutHeight(), 0.0f);
+ }
+
+ @Test
+ public void test_auto_min_size_text_wraps_inside_padded_parent() {
+ YogaConfig config = YogaConfigFactory.create();
+ config.setExperimentalFeatureEnabled(YogaExperimentalFeature.MIN_CONTENT_HEIGHT_AT_GIVEN_WIDTH, true);
+ config.setErrata(YogaErrata.NONE);
+
+ final YogaNode root = createNode(config);
+ root.setPositionType(YogaPositionType.ABSOLUTE);
+ root.setWidth(110f);
+ root.setHeight(20f);
+
+ final YogaNode root_child0 = createNode(config);
+ root_child0.setFlexShrink(1f);
+ root_child0.setPadding(YogaEdge.VERTICAL, 0);
+ root_child0.setPadding(YogaEdge.HORIZONTAL, 30);
+ root.addChildAt(root_child0, 0);
+
+ final YogaNode root_child0_child0 = createNode(config);
+ root_child0.addChildAt(root_child0_child0, 0);
+ root_child0_child0.setData("aaaa aaaa aaaa");
+ root_child0_child0.setMeasureFunction(new TestUtils.intrinsicMeasureFunction());
+
+ final YogaNode root_child1 = createNode(config);
+ root_child1.setHeight(10f);
+ root.addChildAt(root_child1, 1);
+ root.setDirection(YogaDirection.LTR);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(110f, root.getLayoutWidth(), 0.0f);
+ assertEquals(20f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(110f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(30f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(30f, root_child0_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f);
+ assertEquals(30f, root_child0_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(30f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(110f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutHeight(), 0.0f);
+
+ root.setDirection(YogaDirection.RTL);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(110f, root.getLayoutWidth(), 0.0f);
+ assertEquals(20f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(110f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(30f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(30f, root_child0_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f);
+ assertEquals(30f, root_child0_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(30f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(110f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutHeight(), 0.0f);
+ }
+
+ @Test
+ public void test_auto_min_size_percent_margin_resolves_against_parent_content_width() {
+ YogaConfig config = YogaConfigFactory.create();
+ config.setExperimentalFeatureEnabled(YogaExperimentalFeature.MIN_CONTENT_HEIGHT_AT_GIVEN_WIDTH, true);
+ config.setErrata(YogaErrata.NONE);
+
+ final YogaNode root = createNode(config);
+ root.setPositionType(YogaPositionType.ABSOLUTE);
+ root.setWidth(200f);
+ root.setHeight(50f);
+
+ final YogaNode root_child0 = createNode(config);
+ root_child0.setFlexShrink(1f);
+ root_child0.setPadding(YogaEdge.LEFT, 50);
+ root.addChildAt(root_child0, 0);
+
+ final YogaNode root_child0_child0 = createNode(config);
+ root_child0_child0.setHeight(10f);
+ root_child0_child0.setMarginPercent(YogaEdge.TOP, 10f);
+ root_child0.addChildAt(root_child0_child0, 0);
+
+ final YogaNode root_child1 = createNode(config);
+ root_child1.setHeight(40f);
+ root.addChildAt(root_child1, 1);
+ root.setDirection(YogaDirection.LTR);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(200f, root.getLayoutWidth(), 0.0f);
+ assertEquals(50f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(200f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(25f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(50f, root_child0_child0.getLayoutX(), 0.0f);
+ assertEquals(15f, root_child0_child0.getLayoutY(), 0.0f);
+ assertEquals(150f, root_child0_child0.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child0_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(25f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(200f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(40f, root_child1.getLayoutHeight(), 0.0f);
+
+ root.setDirection(YogaDirection.RTL);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(200f, root.getLayoutWidth(), 0.0f);
+ assertEquals(50f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(200f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(25f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(50f, root_child0_child0.getLayoutX(), 0.0f);
+ assertEquals(15f, root_child0_child0.getLayoutY(), 0.0f);
+ assertEquals(150f, root_child0_child0.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child0_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(25f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(200f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(40f, root_child1.getLayoutHeight(), 0.0f);
+ }
+
+ @Test
+ public void test_auto_min_size_text_fits_wider_parent() {
+ YogaConfig config = YogaConfigFactory.create();
+ config.setExperimentalFeatureEnabled(YogaExperimentalFeature.MIN_CONTENT_HEIGHT_AT_GIVEN_WIDTH, true);
+ config.setErrata(YogaErrata.NONE);
+
+ final YogaNode root = createNode(config);
+ root.setPositionType(YogaPositionType.ABSOLUTE);
+ root.setWidth(50f);
+ root.setHeight(15f);
+
+ final YogaNode root_child0 = createNode(config);
+ root_child0.setFlexShrink(1f);
+ root.addChildAt(root_child0, 0);
+
+ final YogaNode root_child0_child0 = createNode(config);
+ root_child0_child0.setWidth(200f);
+ root_child0.addChildAt(root_child0_child0, 0);
+
+ final YogaNode root_child0_child0_child0 = createNode(config);
+ root_child0_child0.addChildAt(root_child0_child0_child0, 0);
+ root_child0_child0_child0.setData("aaaa aaaa aaaa");
+ root_child0_child0_child0.setMeasureFunction(new TestUtils.intrinsicMeasureFunction());
+
+ final YogaNode root_child1 = createNode(config);
+ root_child1.setHeight(10f);
+ root.addChildAt(root_child1, 1);
+ root.setDirection(YogaDirection.LTR);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(50f, root.getLayoutWidth(), 0.0f);
+ assertEquals(15f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
+ assertEquals(200f, root_child0_child0.getLayoutWidth(), 0.0f);
+ assertEquals(10f, 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(200f, root_child0_child0_child0.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child0_child0_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutHeight(), 0.0f);
+
+ root.setDirection(YogaDirection.RTL);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(50f, root.getLayoutWidth(), 0.0f);
+ assertEquals(15f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(-150f, root_child0_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
+ assertEquals(200f, root_child0_child0.getLayoutWidth(), 0.0f);
+ assertEquals(10f, 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(200f, root_child0_child0_child0.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child0_child0_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutHeight(), 0.0f);
+ }
+
+ @Test
+ public void test_auto_min_size_text_fits_min_width() {
+ YogaConfig config = YogaConfigFactory.create();
+ config.setExperimentalFeatureEnabled(YogaExperimentalFeature.MIN_CONTENT_HEIGHT_AT_GIVEN_WIDTH, true);
+ config.setErrata(YogaErrata.NONE);
+
+ final YogaNode root = createNode(config);
+ root.setPositionType(YogaPositionType.ABSOLUTE);
+ root.setWidth(50f);
+ root.setHeight(15f);
+
+ final YogaNode root_child0 = createNode(config);
+ root_child0.setFlexShrink(1f);
+ root_child0.setMinWidth(200f);
+ root.addChildAt(root_child0, 0);
+ root_child0.setData("aaaa aaaa aaaa");
+ root_child0.setMeasureFunction(new TestUtils.intrinsicMeasureFunction());
+
+ final YogaNode root_child1 = createNode(config);
+ root_child1.setHeight(10f);
+ root.addChildAt(root_child1, 1);
+ root.setDirection(YogaDirection.LTR);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(50f, root.getLayoutWidth(), 0.0f);
+ assertEquals(15f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(200f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutHeight(), 0.0f);
+
+ root.setDirection(YogaDirection.RTL);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(50f, root.getLayoutWidth(), 0.0f);
+ assertEquals(15f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(-150f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(200f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutHeight(), 0.0f);
+ }
+
+ @Test
+ public void test_auto_min_size_text_wraps_at_max_width() {
+ YogaConfig config = YogaConfigFactory.create();
+ config.setExperimentalFeatureEnabled(YogaExperimentalFeature.MIN_CONTENT_HEIGHT_AT_GIVEN_WIDTH, true);
+ config.setErrata(YogaErrata.NONE);
+
+ final YogaNode root = createNode(config);
+ root.setPositionType(YogaPositionType.ABSOLUTE);
+ root.setWidth(200f);
+ root.setHeight(20f);
+
+ final YogaNode root_child0 = createNode(config);
+ root_child0.setFlexShrink(1f);
+ root_child0.setMaxWidth(50f);
+ root.addChildAt(root_child0, 0);
+ root_child0.setData("aaaa aaaa aaaa");
+ root_child0.setMeasureFunction(new TestUtils.intrinsicMeasureFunction());
+
+ final YogaNode root_child1 = createNode(config);
+ root_child1.setHeight(10f);
+ root.addChildAt(root_child1, 1);
+ root.setDirection(YogaDirection.LTR);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(200f, root.getLayoutWidth(), 0.0f);
+ assertEquals(20f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(30f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(30f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(200f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutHeight(), 0.0f);
+
+ root.setDirection(YogaDirection.RTL);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(200f, root.getLayoutWidth(), 0.0f);
+ assertEquals(20f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(150f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(30f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(30f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(200f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutHeight(), 0.0f);
+ }
+
+ @Test
+ public void test_auto_min_size_text_below_row_wraps_at_max_width() {
+ YogaConfig config = YogaConfigFactory.create();
+ config.setExperimentalFeatureEnabled(YogaExperimentalFeature.MIN_CONTENT_HEIGHT_AT_GIVEN_WIDTH, true);
+ config.setErrata(YogaErrata.NONE);
+
+ final YogaNode root = createNode(config);
+ root.setPositionType(YogaPositionType.ABSOLUTE);
+ root.setWidth(200f);
+ root.setHeight(20f);
+
+ final YogaNode root_child0 = createNode(config);
+ root_child0.setFlexShrink(1f);
+ root_child0.setFlexDirection(YogaFlexDirection.ROW);
+ root.addChildAt(root_child0, 0);
+
+ final YogaNode root_child0_child0 = createNode(config);
+ root_child0_child0.setMaxWidth(50f);
+ root_child0.addChildAt(root_child0_child0, 0);
+ root_child0_child0.setData("aaaa aaaa aaaa");
+ root_child0_child0.setMeasureFunction(new TestUtils.intrinsicMeasureFunction());
+
+ final YogaNode root_child1 = createNode(config);
+ root_child1.setHeight(10f);
+ root.addChildAt(root_child1, 1);
+ root.setDirection(YogaDirection.LTR);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(200f, root.getLayoutWidth(), 0.0f);
+ assertEquals(20f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(200f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(30f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f);
+ assertEquals(30f, root_child0_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(30f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(200f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutHeight(), 0.0f);
+
+ root.setDirection(YogaDirection.RTL);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(200f, root.getLayoutWidth(), 0.0f);
+ assertEquals(20f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(200f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(30f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(150f, root_child0_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f);
+ assertEquals(30f, root_child0_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(30f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(200f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutHeight(), 0.0f);
+ }
+
+ @Test
+ public void test_auto_min_size_text_below_row_is_not_wrapped() {
+ YogaConfig config = YogaConfigFactory.create();
+ config.setExperimentalFeatureEnabled(YogaExperimentalFeature.MIN_CONTENT_HEIGHT_AT_GIVEN_WIDTH, true);
+ config.setErrata(YogaErrata.NONE);
+
+ final YogaNode root = createNode(config);
+ root.setPositionType(YogaPositionType.ABSOLUTE);
+ root.setWidth(50f);
+ root.setHeight(15f);
+
+ final YogaNode root_child0 = createNode(config);
+ root_child0.setFlexShrink(1f);
+ root.addChildAt(root_child0, 0);
+
+ final YogaNode root_child0_child0 = createNode(config);
+ root_child0_child0.setFlexDirection(YogaFlexDirection.ROW);
+ root_child0.addChildAt(root_child0_child0, 0);
+
+ final YogaNode root_child0_child0_child0 = createNode(config);
+ root_child0_child0.addChildAt(root_child0_child0_child0, 0);
+
+ final YogaNode root_child0_child0_child0_child0 = createNode(config);
+ root_child0_child0_child0.addChildAt(root_child0_child0_child0_child0, 0);
+ root_child0_child0_child0_child0.setData("aaaa aaaa aaaa");
+ root_child0_child0_child0_child0.setMeasureFunction(new TestUtils.intrinsicMeasureFunction());
+
+ final YogaNode root_child0_child0_child0_child1 = createNode(config);
+ root_child0_child0_child0_child1.setWidth(200f);
+ root_child0_child0_child0.addChildAt(root_child0_child0_child0_child1, 1);
+
+ final YogaNode root_child1 = createNode(config);
+ root_child1.setHeight(10f);
+ root.addChildAt(root_child1, 1);
+ root.setDirection(YogaDirection.LTR);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(50f, root.getLayoutWidth(), 0.0f);
+ assertEquals(15f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f);
+ assertEquals(10f, 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(200f, root_child0_child0_child0.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child0_child0_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0_child0_child0_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0_child0_child0_child0.getLayoutY(), 0.0f);
+ assertEquals(200f, root_child0_child0_child0_child0.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child0_child0_child0_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0_child0_child0_child1.getLayoutX(), 0.0f);
+ assertEquals(10f, root_child0_child0_child0_child1.getLayoutY(), 0.0f);
+ assertEquals(200f, root_child0_child0_child0_child1.getLayoutWidth(), 0.0f);
+ assertEquals(0f, root_child0_child0_child0_child1.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutHeight(), 0.0f);
+
+ root.setDirection(YogaDirection.RTL);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(50f, root.getLayoutWidth(), 0.0f);
+ assertEquals(15f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child0_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(-150f, root_child0_child0_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0_child0_child0.getLayoutY(), 0.0f);
+ assertEquals(200f, root_child0_child0_child0.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child0_child0_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0_child0_child0_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0_child0_child0_child0.getLayoutY(), 0.0f);
+ assertEquals(200f, root_child0_child0_child0_child0.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child0_child0_child0_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0_child0_child0_child1.getLayoutX(), 0.0f);
+ assertEquals(10f, root_child0_child0_child0_child1.getLayoutY(), 0.0f);
+ assertEquals(200f, root_child0_child0_child0_child1.getLayoutWidth(), 0.0f);
+ assertEquals(0f, root_child0_child0_child0_child1.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutHeight(), 0.0f);
+ }
+
+ @Test
+ public void test_auto_min_size_text_in_wrapping_column_keeps_wrapped_lines() {
+ YogaConfig config = YogaConfigFactory.create();
+ config.setExperimentalFeatureEnabled(YogaExperimentalFeature.MIN_CONTENT_HEIGHT_AT_GIVEN_WIDTH, true);
+ config.setErrata(YogaErrata.NONE);
+
+ final YogaNode root = createNode(config);
+ root.setPositionType(YogaPositionType.ABSOLUTE);
+ root.setWidth(50f);
+ root.setHeight(15f);
+
+ final YogaNode root_child0 = createNode(config);
+ root_child0.setFlexShrink(1f);
+ root_child0.setWrap(YogaWrap.WRAP);
+ root.addChildAt(root_child0, 0);
+
+ final YogaNode root_child0_child0 = createNode(config);
+ root_child0.addChildAt(root_child0_child0, 0);
+ root_child0_child0.setData("aaaa aaaa aaaa");
+ root_child0_child0.setMeasureFunction(new TestUtils.intrinsicMeasureFunction());
+
+ final YogaNode root_child0_child1 = createNode(config);
+ root_child0_child1.setWidth(200f);
+ root_child0.addChildAt(root_child0_child1, 1);
+
+ final YogaNode root_child1 = createNode(config);
+ root_child1.setHeight(10f);
+ root.addChildAt(root_child1, 1);
+ root.setDirection(YogaDirection.LTR);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(50f, root.getLayoutWidth(), 0.0f);
+ assertEquals(15f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(30f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
+ assertEquals(200f, root_child0_child0.getLayoutWidth(), 0.0f);
+ assertEquals(30f, root_child0_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0_child1.getLayoutX(), 0.0f);
+ assertEquals(30f, root_child0_child1.getLayoutY(), 0.0f);
+ assertEquals(200f, root_child0_child1.getLayoutWidth(), 0.0f);
+ assertEquals(0f, root_child0_child1.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(30f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutHeight(), 0.0f);
+
+ root.setDirection(YogaDirection.RTL);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(50f, root.getLayoutWidth(), 0.0f);
+ assertEquals(15f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(30f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(-150f, root_child0_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
+ assertEquals(200f, root_child0_child0.getLayoutWidth(), 0.0f);
+ assertEquals(30f, root_child0_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(-150f, root_child0_child1.getLayoutX(), 0.0f);
+ assertEquals(30f, root_child0_child1.getLayoutY(), 0.0f);
+ assertEquals(200f, root_child0_child1.getLayoutWidth(), 0.0f);
+ assertEquals(0f, root_child0_child1.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(30f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutHeight(), 0.0f);
+ }
+
private YogaNode createNode(YogaConfig config) {
return mNodeFactory.create(config);
}
diff --git a/javascript/src/generated/YGEnums.ts b/javascript/src/generated/YGEnums.ts
index 18f52e86a0..15ebecf161 100644
--- a/javascript/src/generated/YGEnums.ts
+++ b/javascript/src/generated/YGEnums.ts
@@ -70,6 +70,7 @@ export enum Errata {
export enum ExperimentalFeature {
WebFlexBasis = 0,
FixFlexBasisFitContent = 1,
+ MinContentHeightAtGivenWidth = 2,
}
export enum FlexDirection {
@@ -196,6 +197,7 @@ const constants = {
ERRATA_CLASSIC: Errata.Classic,
EXPERIMENTAL_FEATURE_WEB_FLEX_BASIS: ExperimentalFeature.WebFlexBasis,
EXPERIMENTAL_FEATURE_FIX_FLEX_BASIS_FIT_CONTENT: ExperimentalFeature.FixFlexBasisFitContent,
+ EXPERIMENTAL_FEATURE_MIN_CONTENT_HEIGHT_AT_GIVEN_WIDTH: ExperimentalFeature.MinContentHeightAtGivenWidth,
FLEX_DIRECTION_COLUMN: FlexDirection.Column,
FLEX_DIRECTION_COLUMN_REVERSE: FlexDirection.ColumnReverse,
FLEX_DIRECTION_ROW: FlexDirection.Row,
diff --git a/javascript/tests/generated/YGAutoMinSizeTest.test.ts b/javascript/tests/generated/YGAutoMinSizeTest.test.ts
index 86d934c54e..5a3ea7ec9a 100644
--- a/javascript/tests/generated/YGAutoMinSizeTest.test.ts
+++ b/javascript/tests/generated/YGAutoMinSizeTest.test.ts
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
- * @generated SignedSource<>
+ * @generated SignedSource<<6ef7449d7bea7cd8440d84bdd2812ffd>>
* generated by gentest/src/GentestDriver.ts from gentest/fixtures/YGAutoMinSizeTest.html
*/
@@ -1927,3 +1927,886 @@ test('auto_min_size_wrapping_column_counts_all_children', () => {
expect(root_child1.getComputedWidth()).toBe(100);
expect(root_child1.getComputedHeight()).toBe(180);
});
+test('auto_min_size_text_keeps_wrapped_lines', () => {
+ const config = Yoga.Config.create();
+
+ config.setExperimentalFeatureEnabled(ExperimentalFeature.MinContentHeightAtGivenWidth, true);
+
+ config.setErrata(Errata.None);
+
+ const root = Yoga.Node.create(config);
+ root.setPositionType(PositionType.Absolute);
+ root.setWidth(50);
+ root.setHeight(20);
+
+ const root_child0 = Yoga.Node.create(config);
+ root_child0.setFlexShrink(1);
+ root.insertChild(root_child0, 0);
+ root_child0.setMeasureFunc(intrinsicSizeMeasureFunc.bind({text: "aaaa aaaa aaaa", flexDirection: FlexDirection.Column}));
+
+ const root_child1 = Yoga.Node.create(config);
+ root_child1.setHeight(10);
+ root.insertChild(root_child1, 1);
+ root.calculateLayout(undefined, undefined, Direction.LTR);
+
+ expect(root.getComputedLeft()).toBe(0);
+ expect(root.getComputedTop()).toBe(0);
+ expect(root.getComputedWidth()).toBe(50);
+ expect(root.getComputedHeight()).toBe(20);
+
+ expect(root_child0.getComputedLeft()).toBe(0);
+ expect(root_child0.getComputedTop()).toBe(0);
+ expect(root_child0.getComputedWidth()).toBe(50);
+ expect(root_child0.getComputedHeight()).toBe(30);
+
+ expect(root_child1.getComputedLeft()).toBe(0);
+ expect(root_child1.getComputedTop()).toBe(30);
+ expect(root_child1.getComputedWidth()).toBe(50);
+ expect(root_child1.getComputedHeight()).toBe(10);
+
+ root.calculateLayout(undefined, undefined, Direction.RTL);
+
+ expect(root.getComputedLeft()).toBe(0);
+ expect(root.getComputedTop()).toBe(0);
+ expect(root.getComputedWidth()).toBe(50);
+ expect(root.getComputedHeight()).toBe(20);
+
+ expect(root_child0.getComputedLeft()).toBe(0);
+ expect(root_child0.getComputedTop()).toBe(0);
+ expect(root_child0.getComputedWidth()).toBe(50);
+ expect(root_child0.getComputedHeight()).toBe(30);
+
+ expect(root_child1.getComputedLeft()).toBe(0);
+ expect(root_child1.getComputedTop()).toBe(30);
+ expect(root_child1.getComputedWidth()).toBe(50);
+ expect(root_child1.getComputedHeight()).toBe(10);
+});
+test('auto_min_size_nested_text_keeps_wrapped_lines', () => {
+ const config = Yoga.Config.create();
+
+ config.setExperimentalFeatureEnabled(ExperimentalFeature.MinContentHeightAtGivenWidth, true);
+
+ config.setErrata(Errata.None);
+
+ const root = Yoga.Node.create(config);
+ root.setPositionType(PositionType.Absolute);
+ root.setWidth(50);
+ root.setHeight(20);
+
+ const root_child0 = Yoga.Node.create(config);
+ root_child0.setFlexShrink(1);
+ root.insertChild(root_child0, 0);
+
+ const root_child0_child0 = Yoga.Node.create(config);
+ root_child0_child0.setMargin(Edge.Bottom, 5);
+ root_child0.insertChild(root_child0_child0, 0);
+ root_child0_child0.setMeasureFunc(intrinsicSizeMeasureFunc.bind({text: "aaaa aaaa aaaa", flexDirection: FlexDirection.Column}));
+
+ const root_child1 = Yoga.Node.create(config);
+ root_child1.setHeight(10);
+ root.insertChild(root_child1, 1);
+ root.calculateLayout(undefined, undefined, Direction.LTR);
+
+ expect(root.getComputedLeft()).toBe(0);
+ expect(root.getComputedTop()).toBe(0);
+ expect(root.getComputedWidth()).toBe(50);
+ expect(root.getComputedHeight()).toBe(20);
+
+ expect(root_child0.getComputedLeft()).toBe(0);
+ expect(root_child0.getComputedTop()).toBe(0);
+ expect(root_child0.getComputedWidth()).toBe(50);
+ expect(root_child0.getComputedHeight()).toBe(35);
+
+ expect(root_child0_child0.getComputedLeft()).toBe(0);
+ expect(root_child0_child0.getComputedTop()).toBe(0);
+ expect(root_child0_child0.getComputedWidth()).toBe(50);
+ expect(root_child0_child0.getComputedHeight()).toBe(30);
+
+ expect(root_child1.getComputedLeft()).toBe(0);
+ expect(root_child1.getComputedTop()).toBe(35);
+ expect(root_child1.getComputedWidth()).toBe(50);
+ expect(root_child1.getComputedHeight()).toBe(10);
+
+ root.calculateLayout(undefined, undefined, Direction.RTL);
+
+ expect(root.getComputedLeft()).toBe(0);
+ expect(root.getComputedTop()).toBe(0);
+ expect(root.getComputedWidth()).toBe(50);
+ expect(root.getComputedHeight()).toBe(20);
+
+ expect(root_child0.getComputedLeft()).toBe(0);
+ expect(root_child0.getComputedTop()).toBe(0);
+ expect(root_child0.getComputedWidth()).toBe(50);
+ expect(root_child0.getComputedHeight()).toBe(35);
+
+ expect(root_child0_child0.getComputedLeft()).toBe(0);
+ expect(root_child0_child0.getComputedTop()).toBe(0);
+ expect(root_child0_child0.getComputedWidth()).toBe(50);
+ expect(root_child0_child0.getComputedHeight()).toBe(30);
+
+ expect(root_child1.getComputedLeft()).toBe(0);
+ expect(root_child1.getComputedTop()).toBe(35);
+ expect(root_child1.getComputedWidth()).toBe(50);
+ expect(root_child1.getComputedHeight()).toBe(10);
+});
+test('auto_min_size_text_wraps_inside_margin_and_padding', () => {
+ const config = Yoga.Config.create();
+
+ config.setExperimentalFeatureEnabled(ExperimentalFeature.MinContentHeightAtGivenWidth, true);
+
+ config.setErrata(Errata.None);
+
+ const root = Yoga.Node.create(config);
+ root.setPositionType(PositionType.Absolute);
+ root.setWidth(110);
+ root.setHeight(20);
+
+ const root_child0 = Yoga.Node.create(config);
+ root_child0.setFlexShrink(1);
+ root_child0.setMargin(Edge.Vertical, 0);
+ root_child0.setMargin(Edge.Horizontal, 10);
+ root_child0.setPadding(Edge.Vertical, 0);
+ root_child0.setPadding(Edge.Horizontal, 20);
+ root.insertChild(root_child0, 0);
+ root_child0.setMeasureFunc(intrinsicSizeMeasureFunc.bind({text: "aaaa aaaa aaaa", flexDirection: FlexDirection.Column}));
+
+ const root_child1 = Yoga.Node.create(config);
+ root_child1.setHeight(10);
+ root.insertChild(root_child1, 1);
+ root.calculateLayout(undefined, undefined, Direction.LTR);
+
+ expect(root.getComputedLeft()).toBe(0);
+ expect(root.getComputedTop()).toBe(0);
+ expect(root.getComputedWidth()).toBe(110);
+ expect(root.getComputedHeight()).toBe(20);
+
+ expect(root_child0.getComputedLeft()).toBe(10);
+ expect(root_child0.getComputedTop()).toBe(0);
+ expect(root_child0.getComputedWidth()).toBe(90);
+ expect(root_child0.getComputedHeight()).toBe(30);
+
+ expect(root_child1.getComputedLeft()).toBe(0);
+ expect(root_child1.getComputedTop()).toBe(30);
+ expect(root_child1.getComputedWidth()).toBe(110);
+ expect(root_child1.getComputedHeight()).toBe(10);
+
+ root.calculateLayout(undefined, undefined, Direction.RTL);
+
+ expect(root.getComputedLeft()).toBe(0);
+ expect(root.getComputedTop()).toBe(0);
+ expect(root.getComputedWidth()).toBe(110);
+ expect(root.getComputedHeight()).toBe(20);
+
+ expect(root_child0.getComputedLeft()).toBe(10);
+ expect(root_child0.getComputedTop()).toBe(0);
+ expect(root_child0.getComputedWidth()).toBe(90);
+ expect(root_child0.getComputedHeight()).toBe(30);
+
+ expect(root_child1.getComputedLeft()).toBe(0);
+ expect(root_child1.getComputedTop()).toBe(30);
+ expect(root_child1.getComputedWidth()).toBe(110);
+ expect(root_child1.getComputedHeight()).toBe(10);
+});
+test('auto_min_size_text_wraps_at_stated_width', () => {
+ const config = Yoga.Config.create();
+
+ config.setExperimentalFeatureEnabled(ExperimentalFeature.MinContentHeightAtGivenWidth, true);
+
+ config.setErrata(Errata.None);
+
+ const root = Yoga.Node.create(config);
+ root.setPositionType(PositionType.Absolute);
+ root.setWidth(110);
+ root.setHeight(20);
+
+ const root_child0 = Yoga.Node.create(config);
+ root_child0.setFlexShrink(1);
+ root_child0.setWidth("50%");
+ root_child0.setPadding(Edge.Vertical, 0);
+ root_child0.setPadding(Edge.Horizontal, 5);
+ root.insertChild(root_child0, 0);
+ root_child0.setMeasureFunc(intrinsicSizeMeasureFunc.bind({text: "aaaa aaaa aaaa", flexDirection: FlexDirection.Column}));
+
+ const root_child1 = Yoga.Node.create(config);
+ root_child1.setHeight(10);
+ root.insertChild(root_child1, 1);
+ root.calculateLayout(undefined, undefined, Direction.LTR);
+
+ expect(root.getComputedLeft()).toBe(0);
+ expect(root.getComputedTop()).toBe(0);
+ expect(root.getComputedWidth()).toBe(110);
+ expect(root.getComputedHeight()).toBe(20);
+
+ expect(root_child0.getComputedLeft()).toBe(0);
+ expect(root_child0.getComputedTop()).toBe(0);
+ expect(root_child0.getComputedWidth()).toBe(55);
+ expect(root_child0.getComputedHeight()).toBe(30);
+
+ expect(root_child1.getComputedLeft()).toBe(0);
+ expect(root_child1.getComputedTop()).toBe(30);
+ expect(root_child1.getComputedWidth()).toBe(110);
+ expect(root_child1.getComputedHeight()).toBe(10);
+
+ root.calculateLayout(undefined, undefined, Direction.RTL);
+
+ expect(root.getComputedLeft()).toBe(0);
+ expect(root.getComputedTop()).toBe(0);
+ expect(root.getComputedWidth()).toBe(110);
+ expect(root.getComputedHeight()).toBe(20);
+
+ expect(root_child0.getComputedLeft()).toBe(55);
+ expect(root_child0.getComputedTop()).toBe(0);
+ expect(root_child0.getComputedWidth()).toBe(55);
+ expect(root_child0.getComputedHeight()).toBe(30);
+
+ expect(root_child1.getComputedLeft()).toBe(0);
+ expect(root_child1.getComputedTop()).toBe(30);
+ expect(root_child1.getComputedWidth()).toBe(110);
+ expect(root_child1.getComputedHeight()).toBe(10);
+});
+test('auto_min_size_text_wraps_at_stated_content_box_width', () => {
+ const config = Yoga.Config.create();
+
+ config.setExperimentalFeatureEnabled(ExperimentalFeature.MinContentHeightAtGivenWidth, true);
+
+ config.setErrata(Errata.None);
+
+ const root = Yoga.Node.create(config);
+ root.setPositionType(PositionType.Absolute);
+ root.setWidth(200);
+ root.setHeight(20);
+
+ const root_child0 = Yoga.Node.create(config);
+ root_child0.setFlexShrink(1);
+ root_child0.setBoxSizing(BoxSizing.ContentBox);
+ root_child0.setWidth(90);
+ root_child0.setPadding(Edge.Vertical, 0);
+ root_child0.setPadding(Edge.Horizontal, 20);
+ root.insertChild(root_child0, 0);
+ root_child0.setMeasureFunc(intrinsicSizeMeasureFunc.bind({text: "aaaa aaaa aaaa", flexDirection: FlexDirection.Column}));
+
+ const root_child1 = Yoga.Node.create(config);
+ root_child1.setHeight(15);
+ root.insertChild(root_child1, 1);
+ root.calculateLayout(undefined, undefined, Direction.LTR);
+
+ expect(root.getComputedLeft()).toBe(0);
+ expect(root.getComputedTop()).toBe(0);
+ expect(root.getComputedWidth()).toBe(200);
+ expect(root.getComputedHeight()).toBe(20);
+
+ expect(root_child0.getComputedLeft()).toBe(0);
+ expect(root_child0.getComputedTop()).toBe(0);
+ expect(root_child0.getComputedWidth()).toBe(130);
+ expect(root_child0.getComputedHeight()).toBe(20);
+
+ expect(root_child1.getComputedLeft()).toBe(0);
+ expect(root_child1.getComputedTop()).toBe(20);
+ expect(root_child1.getComputedWidth()).toBe(200);
+ expect(root_child1.getComputedHeight()).toBe(15);
+
+ root.calculateLayout(undefined, undefined, Direction.RTL);
+
+ expect(root.getComputedLeft()).toBe(0);
+ expect(root.getComputedTop()).toBe(0);
+ expect(root.getComputedWidth()).toBe(200);
+ expect(root.getComputedHeight()).toBe(20);
+
+ expect(root_child0.getComputedLeft()).toBe(70);
+ expect(root_child0.getComputedTop()).toBe(0);
+ expect(root_child0.getComputedWidth()).toBe(130);
+ expect(root_child0.getComputedHeight()).toBe(20);
+
+ expect(root_child1.getComputedLeft()).toBe(0);
+ expect(root_child1.getComputedTop()).toBe(20);
+ expect(root_child1.getComputedWidth()).toBe(200);
+ expect(root_child1.getComputedHeight()).toBe(15);
+});
+test('auto_min_size_text_wraps_inside_padded_parent', () => {
+ const config = Yoga.Config.create();
+
+ config.setExperimentalFeatureEnabled(ExperimentalFeature.MinContentHeightAtGivenWidth, true);
+
+ config.setErrata(Errata.None);
+
+ const root = Yoga.Node.create(config);
+ root.setPositionType(PositionType.Absolute);
+ root.setWidth(110);
+ root.setHeight(20);
+
+ const root_child0 = Yoga.Node.create(config);
+ root_child0.setFlexShrink(1);
+ root_child0.setPadding(Edge.Vertical, 0);
+ root_child0.setPadding(Edge.Horizontal, 30);
+ root.insertChild(root_child0, 0);
+
+ const root_child0_child0 = Yoga.Node.create(config);
+ root_child0.insertChild(root_child0_child0, 0);
+ root_child0_child0.setMeasureFunc(intrinsicSizeMeasureFunc.bind({text: "aaaa aaaa aaaa", flexDirection: FlexDirection.Column}));
+
+ const root_child1 = Yoga.Node.create(config);
+ root_child1.setHeight(10);
+ root.insertChild(root_child1, 1);
+ root.calculateLayout(undefined, undefined, Direction.LTR);
+
+ expect(root.getComputedLeft()).toBe(0);
+ expect(root.getComputedTop()).toBe(0);
+ expect(root.getComputedWidth()).toBe(110);
+ expect(root.getComputedHeight()).toBe(20);
+
+ expect(root_child0.getComputedLeft()).toBe(0);
+ expect(root_child0.getComputedTop()).toBe(0);
+ expect(root_child0.getComputedWidth()).toBe(110);
+ expect(root_child0.getComputedHeight()).toBe(30);
+
+ expect(root_child0_child0.getComputedLeft()).toBe(30);
+ expect(root_child0_child0.getComputedTop()).toBe(0);
+ expect(root_child0_child0.getComputedWidth()).toBe(50);
+ expect(root_child0_child0.getComputedHeight()).toBe(30);
+
+ expect(root_child1.getComputedLeft()).toBe(0);
+ expect(root_child1.getComputedTop()).toBe(30);
+ expect(root_child1.getComputedWidth()).toBe(110);
+ expect(root_child1.getComputedHeight()).toBe(10);
+
+ root.calculateLayout(undefined, undefined, Direction.RTL);
+
+ expect(root.getComputedLeft()).toBe(0);
+ expect(root.getComputedTop()).toBe(0);
+ expect(root.getComputedWidth()).toBe(110);
+ expect(root.getComputedHeight()).toBe(20);
+
+ expect(root_child0.getComputedLeft()).toBe(0);
+ expect(root_child0.getComputedTop()).toBe(0);
+ expect(root_child0.getComputedWidth()).toBe(110);
+ expect(root_child0.getComputedHeight()).toBe(30);
+
+ expect(root_child0_child0.getComputedLeft()).toBe(30);
+ expect(root_child0_child0.getComputedTop()).toBe(0);
+ expect(root_child0_child0.getComputedWidth()).toBe(50);
+ expect(root_child0_child0.getComputedHeight()).toBe(30);
+
+ expect(root_child1.getComputedLeft()).toBe(0);
+ expect(root_child1.getComputedTop()).toBe(30);
+ expect(root_child1.getComputedWidth()).toBe(110);
+ expect(root_child1.getComputedHeight()).toBe(10);
+});
+test('auto_min_size_percent_margin_resolves_against_parent_content_width', () => {
+ const config = Yoga.Config.create();
+
+ config.setExperimentalFeatureEnabled(ExperimentalFeature.MinContentHeightAtGivenWidth, true);
+
+ config.setErrata(Errata.None);
+
+ const root = Yoga.Node.create(config);
+ root.setPositionType(PositionType.Absolute);
+ root.setWidth(200);
+ root.setHeight(50);
+
+ const root_child0 = Yoga.Node.create(config);
+ root_child0.setFlexShrink(1);
+ root_child0.setPadding(Edge.Left, 50);
+ root.insertChild(root_child0, 0);
+
+ const root_child0_child0 = Yoga.Node.create(config);
+ root_child0_child0.setHeight(10);
+ root_child0_child0.setMargin(Edge.Top, "10%");
+ root_child0.insertChild(root_child0_child0, 0);
+
+ const root_child1 = Yoga.Node.create(config);
+ root_child1.setHeight(40);
+ root.insertChild(root_child1, 1);
+ root.calculateLayout(undefined, undefined, Direction.LTR);
+
+ expect(root.getComputedLeft()).toBe(0);
+ expect(root.getComputedTop()).toBe(0);
+ expect(root.getComputedWidth()).toBe(200);
+ expect(root.getComputedHeight()).toBe(50);
+
+ expect(root_child0.getComputedLeft()).toBe(0);
+ expect(root_child0.getComputedTop()).toBe(0);
+ expect(root_child0.getComputedWidth()).toBe(200);
+ expect(root_child0.getComputedHeight()).toBe(25);
+
+ expect(root_child0_child0.getComputedLeft()).toBe(50);
+ expect(root_child0_child0.getComputedTop()).toBe(15);
+ expect(root_child0_child0.getComputedWidth()).toBe(150);
+ expect(root_child0_child0.getComputedHeight()).toBe(10);
+
+ expect(root_child1.getComputedLeft()).toBe(0);
+ expect(root_child1.getComputedTop()).toBe(25);
+ expect(root_child1.getComputedWidth()).toBe(200);
+ expect(root_child1.getComputedHeight()).toBe(40);
+
+ root.calculateLayout(undefined, undefined, Direction.RTL);
+
+ expect(root.getComputedLeft()).toBe(0);
+ expect(root.getComputedTop()).toBe(0);
+ expect(root.getComputedWidth()).toBe(200);
+ expect(root.getComputedHeight()).toBe(50);
+
+ expect(root_child0.getComputedLeft()).toBe(0);
+ expect(root_child0.getComputedTop()).toBe(0);
+ expect(root_child0.getComputedWidth()).toBe(200);
+ expect(root_child0.getComputedHeight()).toBe(25);
+
+ expect(root_child0_child0.getComputedLeft()).toBe(50);
+ expect(root_child0_child0.getComputedTop()).toBe(15);
+ expect(root_child0_child0.getComputedWidth()).toBe(150);
+ expect(root_child0_child0.getComputedHeight()).toBe(10);
+
+ expect(root_child1.getComputedLeft()).toBe(0);
+ expect(root_child1.getComputedTop()).toBe(25);
+ expect(root_child1.getComputedWidth()).toBe(200);
+ expect(root_child1.getComputedHeight()).toBe(40);
+});
+test('auto_min_size_text_fits_wider_parent', () => {
+ const config = Yoga.Config.create();
+
+ config.setExperimentalFeatureEnabled(ExperimentalFeature.MinContentHeightAtGivenWidth, true);
+
+ config.setErrata(Errata.None);
+
+ const root = Yoga.Node.create(config);
+ root.setPositionType(PositionType.Absolute);
+ root.setWidth(50);
+ root.setHeight(15);
+
+ const root_child0 = Yoga.Node.create(config);
+ root_child0.setFlexShrink(1);
+ root.insertChild(root_child0, 0);
+
+ const root_child0_child0 = Yoga.Node.create(config);
+ root_child0_child0.setWidth(200);
+ root_child0.insertChild(root_child0_child0, 0);
+
+ const root_child0_child0_child0 = Yoga.Node.create(config);
+ root_child0_child0.insertChild(root_child0_child0_child0, 0);
+ root_child0_child0_child0.setMeasureFunc(intrinsicSizeMeasureFunc.bind({text: "aaaa aaaa aaaa", flexDirection: FlexDirection.Column}));
+
+ const root_child1 = Yoga.Node.create(config);
+ root_child1.setHeight(10);
+ root.insertChild(root_child1, 1);
+ root.calculateLayout(undefined, undefined, Direction.LTR);
+
+ expect(root.getComputedLeft()).toBe(0);
+ expect(root.getComputedTop()).toBe(0);
+ expect(root.getComputedWidth()).toBe(50);
+ expect(root.getComputedHeight()).toBe(15);
+
+ expect(root_child0.getComputedLeft()).toBe(0);
+ expect(root_child0.getComputedTop()).toBe(0);
+ expect(root_child0.getComputedWidth()).toBe(50);
+ expect(root_child0.getComputedHeight()).toBe(10);
+
+ expect(root_child0_child0.getComputedLeft()).toBe(0);
+ expect(root_child0_child0.getComputedTop()).toBe(0);
+ expect(root_child0_child0.getComputedWidth()).toBe(200);
+ expect(root_child0_child0.getComputedHeight()).toBe(10);
+
+ expect(root_child0_child0_child0.getComputedLeft()).toBe(0);
+ expect(root_child0_child0_child0.getComputedTop()).toBe(0);
+ expect(root_child0_child0_child0.getComputedWidth()).toBe(200);
+ expect(root_child0_child0_child0.getComputedHeight()).toBe(10);
+
+ expect(root_child1.getComputedLeft()).toBe(0);
+ expect(root_child1.getComputedTop()).toBe(10);
+ expect(root_child1.getComputedWidth()).toBe(50);
+ expect(root_child1.getComputedHeight()).toBe(10);
+
+ root.calculateLayout(undefined, undefined, Direction.RTL);
+
+ expect(root.getComputedLeft()).toBe(0);
+ expect(root.getComputedTop()).toBe(0);
+ expect(root.getComputedWidth()).toBe(50);
+ expect(root.getComputedHeight()).toBe(15);
+
+ expect(root_child0.getComputedLeft()).toBe(0);
+ expect(root_child0.getComputedTop()).toBe(0);
+ expect(root_child0.getComputedWidth()).toBe(50);
+ expect(root_child0.getComputedHeight()).toBe(10);
+
+ expect(root_child0_child0.getComputedLeft()).toBe(-150);
+ expect(root_child0_child0.getComputedTop()).toBe(0);
+ expect(root_child0_child0.getComputedWidth()).toBe(200);
+ expect(root_child0_child0.getComputedHeight()).toBe(10);
+
+ expect(root_child0_child0_child0.getComputedLeft()).toBe(0);
+ expect(root_child0_child0_child0.getComputedTop()).toBe(0);
+ expect(root_child0_child0_child0.getComputedWidth()).toBe(200);
+ expect(root_child0_child0_child0.getComputedHeight()).toBe(10);
+
+ expect(root_child1.getComputedLeft()).toBe(0);
+ expect(root_child1.getComputedTop()).toBe(10);
+ expect(root_child1.getComputedWidth()).toBe(50);
+ expect(root_child1.getComputedHeight()).toBe(10);
+});
+test('auto_min_size_text_fits_min_width', () => {
+ const config = Yoga.Config.create();
+
+ config.setExperimentalFeatureEnabled(ExperimentalFeature.MinContentHeightAtGivenWidth, true);
+
+ config.setErrata(Errata.None);
+
+ const root = Yoga.Node.create(config);
+ root.setPositionType(PositionType.Absolute);
+ root.setWidth(50);
+ root.setHeight(15);
+
+ const root_child0 = Yoga.Node.create(config);
+ root_child0.setFlexShrink(1);
+ root_child0.setMinWidth(200);
+ root.insertChild(root_child0, 0);
+ root_child0.setMeasureFunc(intrinsicSizeMeasureFunc.bind({text: "aaaa aaaa aaaa", flexDirection: FlexDirection.Column}));
+
+ const root_child1 = Yoga.Node.create(config);
+ root_child1.setHeight(10);
+ root.insertChild(root_child1, 1);
+ root.calculateLayout(undefined, undefined, Direction.LTR);
+
+ expect(root.getComputedLeft()).toBe(0);
+ expect(root.getComputedTop()).toBe(0);
+ expect(root.getComputedWidth()).toBe(50);
+ expect(root.getComputedHeight()).toBe(15);
+
+ expect(root_child0.getComputedLeft()).toBe(0);
+ expect(root_child0.getComputedTop()).toBe(0);
+ expect(root_child0.getComputedWidth()).toBe(200);
+ expect(root_child0.getComputedHeight()).toBe(10);
+
+ expect(root_child1.getComputedLeft()).toBe(0);
+ expect(root_child1.getComputedTop()).toBe(10);
+ expect(root_child1.getComputedWidth()).toBe(50);
+ expect(root_child1.getComputedHeight()).toBe(10);
+
+ root.calculateLayout(undefined, undefined, Direction.RTL);
+
+ expect(root.getComputedLeft()).toBe(0);
+ expect(root.getComputedTop()).toBe(0);
+ expect(root.getComputedWidth()).toBe(50);
+ expect(root.getComputedHeight()).toBe(15);
+
+ expect(root_child0.getComputedLeft()).toBe(-150);
+ expect(root_child0.getComputedTop()).toBe(0);
+ expect(root_child0.getComputedWidth()).toBe(200);
+ expect(root_child0.getComputedHeight()).toBe(10);
+
+ expect(root_child1.getComputedLeft()).toBe(0);
+ expect(root_child1.getComputedTop()).toBe(10);
+ expect(root_child1.getComputedWidth()).toBe(50);
+ expect(root_child1.getComputedHeight()).toBe(10);
+});
+test('auto_min_size_text_wraps_at_max_width', () => {
+ const config = Yoga.Config.create();
+
+ config.setExperimentalFeatureEnabled(ExperimentalFeature.MinContentHeightAtGivenWidth, true);
+
+ config.setErrata(Errata.None);
+
+ const root = Yoga.Node.create(config);
+ root.setPositionType(PositionType.Absolute);
+ root.setWidth(200);
+ root.setHeight(20);
+
+ const root_child0 = Yoga.Node.create(config);
+ root_child0.setFlexShrink(1);
+ root_child0.setMaxWidth(50);
+ root.insertChild(root_child0, 0);
+ root_child0.setMeasureFunc(intrinsicSizeMeasureFunc.bind({text: "aaaa aaaa aaaa", flexDirection: FlexDirection.Column}));
+
+ const root_child1 = Yoga.Node.create(config);
+ root_child1.setHeight(10);
+ root.insertChild(root_child1, 1);
+ root.calculateLayout(undefined, undefined, Direction.LTR);
+
+ expect(root.getComputedLeft()).toBe(0);
+ expect(root.getComputedTop()).toBe(0);
+ expect(root.getComputedWidth()).toBe(200);
+ expect(root.getComputedHeight()).toBe(20);
+
+ expect(root_child0.getComputedLeft()).toBe(0);
+ expect(root_child0.getComputedTop()).toBe(0);
+ expect(root_child0.getComputedWidth()).toBe(50);
+ expect(root_child0.getComputedHeight()).toBe(30);
+
+ expect(root_child1.getComputedLeft()).toBe(0);
+ expect(root_child1.getComputedTop()).toBe(30);
+ expect(root_child1.getComputedWidth()).toBe(200);
+ expect(root_child1.getComputedHeight()).toBe(10);
+
+ root.calculateLayout(undefined, undefined, Direction.RTL);
+
+ expect(root.getComputedLeft()).toBe(0);
+ expect(root.getComputedTop()).toBe(0);
+ expect(root.getComputedWidth()).toBe(200);
+ expect(root.getComputedHeight()).toBe(20);
+
+ expect(root_child0.getComputedLeft()).toBe(150);
+ expect(root_child0.getComputedTop()).toBe(0);
+ expect(root_child0.getComputedWidth()).toBe(50);
+ expect(root_child0.getComputedHeight()).toBe(30);
+
+ expect(root_child1.getComputedLeft()).toBe(0);
+ expect(root_child1.getComputedTop()).toBe(30);
+ expect(root_child1.getComputedWidth()).toBe(200);
+ expect(root_child1.getComputedHeight()).toBe(10);
+});
+test('auto_min_size_text_below_row_wraps_at_max_width', () => {
+ const config = Yoga.Config.create();
+
+ config.setExperimentalFeatureEnabled(ExperimentalFeature.MinContentHeightAtGivenWidth, true);
+
+ config.setErrata(Errata.None);
+
+ const root = Yoga.Node.create(config);
+ root.setPositionType(PositionType.Absolute);
+ root.setWidth(200);
+ root.setHeight(20);
+
+ const root_child0 = Yoga.Node.create(config);
+ root_child0.setFlexShrink(1);
+ root_child0.setFlexDirection(FlexDirection.Row);
+ root.insertChild(root_child0, 0);
+
+ const root_child0_child0 = Yoga.Node.create(config);
+ root_child0_child0.setMaxWidth(50);
+ root_child0.insertChild(root_child0_child0, 0);
+ root_child0_child0.setMeasureFunc(intrinsicSizeMeasureFunc.bind({text: "aaaa aaaa aaaa", flexDirection: FlexDirection.Column}));
+
+ const root_child1 = Yoga.Node.create(config);
+ root_child1.setHeight(10);
+ root.insertChild(root_child1, 1);
+ root.calculateLayout(undefined, undefined, Direction.LTR);
+
+ expect(root.getComputedLeft()).toBe(0);
+ expect(root.getComputedTop()).toBe(0);
+ expect(root.getComputedWidth()).toBe(200);
+ expect(root.getComputedHeight()).toBe(20);
+
+ expect(root_child0.getComputedLeft()).toBe(0);
+ expect(root_child0.getComputedTop()).toBe(0);
+ expect(root_child0.getComputedWidth()).toBe(200);
+ expect(root_child0.getComputedHeight()).toBe(30);
+
+ expect(root_child0_child0.getComputedLeft()).toBe(0);
+ expect(root_child0_child0.getComputedTop()).toBe(0);
+ expect(root_child0_child0.getComputedWidth()).toBe(50);
+ expect(root_child0_child0.getComputedHeight()).toBe(30);
+
+ expect(root_child1.getComputedLeft()).toBe(0);
+ expect(root_child1.getComputedTop()).toBe(30);
+ expect(root_child1.getComputedWidth()).toBe(200);
+ expect(root_child1.getComputedHeight()).toBe(10);
+
+ root.calculateLayout(undefined, undefined, Direction.RTL);
+
+ expect(root.getComputedLeft()).toBe(0);
+ expect(root.getComputedTop()).toBe(0);
+ expect(root.getComputedWidth()).toBe(200);
+ expect(root.getComputedHeight()).toBe(20);
+
+ expect(root_child0.getComputedLeft()).toBe(0);
+ expect(root_child0.getComputedTop()).toBe(0);
+ expect(root_child0.getComputedWidth()).toBe(200);
+ expect(root_child0.getComputedHeight()).toBe(30);
+
+ expect(root_child0_child0.getComputedLeft()).toBe(150);
+ expect(root_child0_child0.getComputedTop()).toBe(0);
+ expect(root_child0_child0.getComputedWidth()).toBe(50);
+ expect(root_child0_child0.getComputedHeight()).toBe(30);
+
+ expect(root_child1.getComputedLeft()).toBe(0);
+ expect(root_child1.getComputedTop()).toBe(30);
+ expect(root_child1.getComputedWidth()).toBe(200);
+ expect(root_child1.getComputedHeight()).toBe(10);
+});
+test('auto_min_size_text_below_row_is_not_wrapped', () => {
+ const config = Yoga.Config.create();
+
+ config.setExperimentalFeatureEnabled(ExperimentalFeature.MinContentHeightAtGivenWidth, true);
+
+ config.setErrata(Errata.None);
+
+ const root = Yoga.Node.create(config);
+ root.setPositionType(PositionType.Absolute);
+ root.setWidth(50);
+ root.setHeight(15);
+
+ const root_child0 = Yoga.Node.create(config);
+ root_child0.setFlexShrink(1);
+ root.insertChild(root_child0, 0);
+
+ const root_child0_child0 = Yoga.Node.create(config);
+ root_child0_child0.setFlexDirection(FlexDirection.Row);
+ root_child0.insertChild(root_child0_child0, 0);
+
+ const root_child0_child0_child0 = Yoga.Node.create(config);
+ root_child0_child0.insertChild(root_child0_child0_child0, 0);
+
+ const root_child0_child0_child0_child0 = Yoga.Node.create(config);
+ root_child0_child0_child0.insertChild(root_child0_child0_child0_child0, 0);
+ root_child0_child0_child0_child0.setMeasureFunc(intrinsicSizeMeasureFunc.bind({text: "aaaa aaaa aaaa", flexDirection: FlexDirection.Column}));
+
+ const root_child0_child0_child0_child1 = Yoga.Node.create(config);
+ root_child0_child0_child0_child1.setWidth(200);
+ root_child0_child0_child0.insertChild(root_child0_child0_child0_child1, 1);
+
+ const root_child1 = Yoga.Node.create(config);
+ root_child1.setHeight(10);
+ root.insertChild(root_child1, 1);
+ root.calculateLayout(undefined, undefined, Direction.LTR);
+
+ expect(root.getComputedLeft()).toBe(0);
+ expect(root.getComputedTop()).toBe(0);
+ expect(root.getComputedWidth()).toBe(50);
+ expect(root.getComputedHeight()).toBe(15);
+
+ expect(root_child0.getComputedLeft()).toBe(0);
+ expect(root_child0.getComputedTop()).toBe(0);
+ expect(root_child0.getComputedWidth()).toBe(50);
+ expect(root_child0.getComputedHeight()).toBe(10);
+
+ expect(root_child0_child0.getComputedLeft()).toBe(0);
+ expect(root_child0_child0.getComputedTop()).toBe(0);
+ expect(root_child0_child0.getComputedWidth()).toBe(50);
+ expect(root_child0_child0.getComputedHeight()).toBe(10);
+
+ expect(root_child0_child0_child0.getComputedLeft()).toBe(0);
+ expect(root_child0_child0_child0.getComputedTop()).toBe(0);
+ expect(root_child0_child0_child0.getComputedWidth()).toBe(200);
+ expect(root_child0_child0_child0.getComputedHeight()).toBe(10);
+
+ expect(root_child0_child0_child0_child0.getComputedLeft()).toBe(0);
+ expect(root_child0_child0_child0_child0.getComputedTop()).toBe(0);
+ expect(root_child0_child0_child0_child0.getComputedWidth()).toBe(200);
+ expect(root_child0_child0_child0_child0.getComputedHeight()).toBe(10);
+
+ expect(root_child0_child0_child0_child1.getComputedLeft()).toBe(0);
+ expect(root_child0_child0_child0_child1.getComputedTop()).toBe(10);
+ expect(root_child0_child0_child0_child1.getComputedWidth()).toBe(200);
+ expect(root_child0_child0_child0_child1.getComputedHeight()).toBe(0);
+
+ expect(root_child1.getComputedLeft()).toBe(0);
+ expect(root_child1.getComputedTop()).toBe(10);
+ expect(root_child1.getComputedWidth()).toBe(50);
+ expect(root_child1.getComputedHeight()).toBe(10);
+
+ root.calculateLayout(undefined, undefined, Direction.RTL);
+
+ expect(root.getComputedLeft()).toBe(0);
+ expect(root.getComputedTop()).toBe(0);
+ expect(root.getComputedWidth()).toBe(50);
+ expect(root.getComputedHeight()).toBe(15);
+
+ expect(root_child0.getComputedLeft()).toBe(0);
+ expect(root_child0.getComputedTop()).toBe(0);
+ expect(root_child0.getComputedWidth()).toBe(50);
+ expect(root_child0.getComputedHeight()).toBe(10);
+
+ expect(root_child0_child0.getComputedLeft()).toBe(0);
+ expect(root_child0_child0.getComputedTop()).toBe(0);
+ expect(root_child0_child0.getComputedWidth()).toBe(50);
+ expect(root_child0_child0.getComputedHeight()).toBe(10);
+
+ expect(root_child0_child0_child0.getComputedLeft()).toBe(-150);
+ expect(root_child0_child0_child0.getComputedTop()).toBe(0);
+ expect(root_child0_child0_child0.getComputedWidth()).toBe(200);
+ expect(root_child0_child0_child0.getComputedHeight()).toBe(10);
+
+ expect(root_child0_child0_child0_child0.getComputedLeft()).toBe(0);
+ expect(root_child0_child0_child0_child0.getComputedTop()).toBe(0);
+ expect(root_child0_child0_child0_child0.getComputedWidth()).toBe(200);
+ expect(root_child0_child0_child0_child0.getComputedHeight()).toBe(10);
+
+ expect(root_child0_child0_child0_child1.getComputedLeft()).toBe(0);
+ expect(root_child0_child0_child0_child1.getComputedTop()).toBe(10);
+ expect(root_child0_child0_child0_child1.getComputedWidth()).toBe(200);
+ expect(root_child0_child0_child0_child1.getComputedHeight()).toBe(0);
+
+ expect(root_child1.getComputedLeft()).toBe(0);
+ expect(root_child1.getComputedTop()).toBe(10);
+ expect(root_child1.getComputedWidth()).toBe(50);
+ expect(root_child1.getComputedHeight()).toBe(10);
+});
+test('auto_min_size_text_in_wrapping_column_keeps_wrapped_lines', () => {
+ const config = Yoga.Config.create();
+
+ config.setExperimentalFeatureEnabled(ExperimentalFeature.MinContentHeightAtGivenWidth, true);
+
+ config.setErrata(Errata.None);
+
+ const root = Yoga.Node.create(config);
+ root.setPositionType(PositionType.Absolute);
+ root.setWidth(50);
+ root.setHeight(15);
+
+ const root_child0 = Yoga.Node.create(config);
+ root_child0.setFlexShrink(1);
+ root_child0.setFlexWrap(Wrap.Wrap);
+ root.insertChild(root_child0, 0);
+
+ const root_child0_child0 = Yoga.Node.create(config);
+ root_child0.insertChild(root_child0_child0, 0);
+ root_child0_child0.setMeasureFunc(intrinsicSizeMeasureFunc.bind({text: "aaaa aaaa aaaa", flexDirection: FlexDirection.Column}));
+
+ const root_child0_child1 = Yoga.Node.create(config);
+ root_child0_child1.setWidth(200);
+ root_child0.insertChild(root_child0_child1, 1);
+
+ const root_child1 = Yoga.Node.create(config);
+ root_child1.setHeight(10);
+ root.insertChild(root_child1, 1);
+ root.calculateLayout(undefined, undefined, Direction.LTR);
+
+ expect(root.getComputedLeft()).toBe(0);
+ expect(root.getComputedTop()).toBe(0);
+ expect(root.getComputedWidth()).toBe(50);
+ expect(root.getComputedHeight()).toBe(15);
+
+ expect(root_child0.getComputedLeft()).toBe(0);
+ expect(root_child0.getComputedTop()).toBe(0);
+ expect(root_child0.getComputedWidth()).toBe(50);
+ expect(root_child0.getComputedHeight()).toBe(30);
+
+ expect(root_child0_child0.getComputedLeft()).toBe(0);
+ expect(root_child0_child0.getComputedTop()).toBe(0);
+ expect(root_child0_child0.getComputedWidth()).toBe(200);
+ expect(root_child0_child0.getComputedHeight()).toBe(30);
+
+ expect(root_child0_child1.getComputedLeft()).toBe(0);
+ expect(root_child0_child1.getComputedTop()).toBe(30);
+ expect(root_child0_child1.getComputedWidth()).toBe(200);
+ expect(root_child0_child1.getComputedHeight()).toBe(0);
+
+ expect(root_child1.getComputedLeft()).toBe(0);
+ expect(root_child1.getComputedTop()).toBe(30);
+ expect(root_child1.getComputedWidth()).toBe(50);
+ expect(root_child1.getComputedHeight()).toBe(10);
+
+ root.calculateLayout(undefined, undefined, Direction.RTL);
+
+ expect(root.getComputedLeft()).toBe(0);
+ expect(root.getComputedTop()).toBe(0);
+ expect(root.getComputedWidth()).toBe(50);
+ expect(root.getComputedHeight()).toBe(15);
+
+ expect(root_child0.getComputedLeft()).toBe(0);
+ expect(root_child0.getComputedTop()).toBe(0);
+ expect(root_child0.getComputedWidth()).toBe(50);
+ expect(root_child0.getComputedHeight()).toBe(30);
+
+ expect(root_child0_child0.getComputedLeft()).toBe(-150);
+ expect(root_child0_child0.getComputedTop()).toBe(0);
+ expect(root_child0_child0.getComputedWidth()).toBe(200);
+ expect(root_child0_child0.getComputedHeight()).toBe(30);
+
+ expect(root_child0_child1.getComputedLeft()).toBe(-150);
+ expect(root_child0_child1.getComputedTop()).toBe(30);
+ expect(root_child0_child1.getComputedWidth()).toBe(200);
+ expect(root_child0_child1.getComputedHeight()).toBe(0);
+
+ expect(root_child1.getComputedLeft()).toBe(0);
+ expect(root_child1.getComputedTop()).toBe(30);
+ expect(root_child1.getComputedWidth()).toBe(50);
+ expect(root_child1.getComputedHeight()).toBe(10);
+});
diff --git a/tests/YGAutoMinSizeTest.cpp b/tests/YGAutoMinSizeTest.cpp
index 63fc357a31..0a6ce5d58c 100644
--- a/tests/YGAutoMinSizeTest.cpp
+++ b/tests/YGAutoMinSizeTest.cpp
@@ -765,6 +765,134 @@ TEST(YogaAutoMinSize, empty_child_percentage_padding_follows_owner_width) {
YGConfigFree(config);
}
+// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
+static YGSize gLastHeightProbe = {};
+// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
+static YGMeasureMode gLastHeightProbeWidthMode = YGMeasureModeUndefined;
+// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
+static YGMeasureMode gLastHeightProbeHeightMode = YGMeasureModeUndefined;
+
+static YGSize measureMinContentRecordingArgs(
+ YGNodeConstRef node,
+ float width,
+ YGMeasureMode widthMode,
+ float height,
+ YGMeasureMode heightMode) {
+ gLastHeightProbe = YGSize{width, height};
+ gLastHeightProbeWidthMode = widthMode;
+ gLastHeightProbeHeightMode = heightMode;
+ return measureWordWrappingText(node, width, widthMode, height, heightMode);
+}
+
+// A column that is 20 tall holding wrapping text and a 10-tall spacer, so its
+// first child is asked to shrink and its min-content height is probed. That
+// child is the text or, when `nested`, a box around it.
+static YGNodeRef makeTextColumn(YGConfigRef config, float width, bool nested) {
+ YGNodeRef root = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn);
+ YGNodeStyleSetWidth(root, width);
+ YGNodeStyleSetHeight(root, 20);
+
+ YGNodeRef text = YGNodeNewWithConfig(config);
+ YGNodeSetMeasureFunc(text, measureWordWrappingText);
+ YGNodeSetMinContentMeasureFunc(text, measureMinContentRecordingArgs);
+ YGNodeStyleSetMargin(text, YGEdgeLeft, 4);
+ YGNodeStyleSetPadding(text, YGEdgeRight, 6);
+ if (nested) {
+ YGNodeRef box = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexDirection(box, YGFlexDirectionColumn);
+ YGNodeInsertChild(box, text, 0);
+ YGNodeInsertChild(root, box, 0);
+ } else {
+ YGNodeInsertChild(root, text, 0);
+ }
+
+ YGNodeRef spacer = YGNodeNewWithConfig(config);
+ YGNodeStyleSetHeight(spacer, 10);
+ YGNodeStyleSetFlexShrink(spacer, 0);
+ YGNodeInsertChild(root, spacer, 1);
+ return root;
+}
+
+// Without the experimental feature, a height is probed as a width is: at most
+// zero on the probed axis and no constraint on the other.
+TEST(YogaAutoMinSize, min_content_height_probe_asks_for_at_most_zero) {
+ YGConfigRef config = makeWebConfig(/*useAutoMinSize=*/true);
+ YGNodeRef root = makeTextColumn(config, 70, /*nested=*/false);
+
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
+
+ EXPECT_EQ(YGMeasureModeUndefined, gLastHeightProbeWidthMode);
+ EXPECT_EQ(YGMeasureModeAtMost, gLastHeightProbeHeightMode);
+ EXPECT_FLOAT_EQ(0.0f, gLastHeightProbe.height);
+
+ YGNodeFreeRecursive(root);
+ YGConfigFree(config);
+}
+
+// With it, the leaf is measured at its content width, and measured again when
+// the owner's width changes although the leaf, and a box around it, are clean.
+TEST(YogaAutoMinSize, min_content_height_follows_given_width) {
+ YGConfigRef config = makeWebConfig(/*useAutoMinSize=*/true);
+ YGConfigSetExperimentalFeatureEnabled(
+ config, YGExperimentalFeatureMinContentHeightAtGivenWidth, true);
+ for (const bool nested : {false, true}) {
+ YGNodeRef root = makeTextColumn(config, 70, nested);
+ YGNodeRef item = YGNodeGetChild(root, 0);
+
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
+
+ EXPECT_EQ(YGMeasureModeAtMost, gLastHeightProbeWidthMode);
+ EXPECT_FLOAT_EQ(70.0f - 4.0f - 6.0f, gLastHeightProbe.width);
+ EXPECT_EQ(YGMeasureModeUndefined, gLastHeightProbeHeightMode);
+ EXPECT_FLOAT_EQ(kLineHeight * 2, YGNodeLayoutGetHeight(item));
+
+ YGNodeStyleSetWidth(root, 30);
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
+
+ EXPECT_FLOAT_EQ(30.0f - 4.0f - 6.0f, gLastHeightProbe.width);
+ EXPECT_FLOAT_EQ(kLineHeight * 3, YGNodeLayoutGetHeight(item));
+
+ YGNodeFreeRecursive(root);
+ }
+ YGConfigFree(config);
+}
+
+// A column sized by its content has no width to give, so the leaf is measured
+// with no limit on either axis.
+TEST(YogaAutoMinSize, min_content_height_without_owner_width_is_unconstrained) {
+ YGConfigRef config = makeWebConfig(/*useAutoMinSize=*/true);
+ YGConfigSetExperimentalFeatureEnabled(
+ config, YGExperimentalFeatureMinContentHeightAtGivenWidth, true);
+ YGNodeRef root = makeTextColumn(config, YGUndefined, /*nested=*/false);
+
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
+
+ EXPECT_EQ(YGMeasureModeUndefined, gLastHeightProbeWidthMode);
+ EXPECT_EQ(YGMeasureModeUndefined, gLastHeightProbeHeightMode);
+ EXPECT_FLOAT_EQ(kLineHeight, YGNodeLayoutGetHeight(YGNodeGetChild(root, 0)));
+
+ YGNodeFreeRecursive(root);
+ YGConfigFree(config);
+}
+
+// A width probe does not depend on the owner's width, so the leaf's memo for
+// it survives a new width with the feature on.
+TEST(YogaAutoMinSize, min_content_width_memo_survives_new_owner_width) {
+ ShrinkRow row(/*useAutoMinSize=*/true, /*containerWidth=*/20);
+ YGConfigSetExperimentalFeatureEnabled(
+ row.config, YGExperimentalFeatureMinContentHeightAtGivenWidth, true);
+ YGNodeSetMinContentMeasureFunc(row.text, measureMinContentWord);
+ row.layout();
+
+ gMinContentCalls = 0;
+ YGNodeStyleSetWidth(row.root, 25);
+ row.layout();
+
+ EXPECT_EQ(0, gMinContentCalls);
+ EXPECT_FLOAT_EQ(kWordWidth, YGNodeLayoutGetWidth(row.text));
+}
+
// Min-content is memoized for a single layout only: the next layout probes
// again, so a leaf whose min-content changed gets its new floor.
TEST(YogaAutoMinSize, min_content_reprobed_on_next_layout) {
diff --git a/tests/generated/YGAutoMinSizeTest.cpp b/tests/generated/YGAutoMinSizeTest.cpp
index 6fe98c3829..a5623b9e17 100644
--- a/tests/generated/YGAutoMinSizeTest.cpp
+++ b/tests/generated/YGAutoMinSizeTest.cpp
@@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*
* clang-format off
- * @generated SignedSource<>
+ * @generated SignedSource<>
* generated by gentest/src/GentestDriver.ts from gentest/fixtures/YGAutoMinSizeTest.html
*/
@@ -2003,3 +2003,937 @@ TEST(YogaTest, auto_min_size_wrapping_column_counts_all_children) {
YGConfigFree(config);
}
+
+TEST(YogaTest, auto_min_size_text_keeps_wrapped_lines) {
+ YGConfigRef config = YGConfigNew();
+ YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureMinContentHeightAtGivenWidth, true);
+ YGConfigSetErrata(config, YGErrataNone);
+
+ YGNodeRef root = YGNodeNewWithConfig(config);
+ YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
+ YGNodeStyleSetWidth(root, 50);
+ YGNodeStyleSetHeight(root, 20);
+
+ YGNodeRef root_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexShrink(root_child0, 1);
+ YGNodeInsertChild(root, root_child0, 0);
+ YGNodeSetContext(root_child0, (void*)"aaaa aaaa aaaa");
+ YGNodeSetMeasureFunc(root_child0, &facebook::yoga::test::IntrinsicSizeMeasure);
+
+ YGNodeRef root_child1 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetHeight(root_child1, 10);
+ YGNodeInsertChild(root, root_child1, 1);
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeFreeRecursive(root);
+
+ YGConfigFree(config);
+}
+
+TEST(YogaTest, auto_min_size_nested_text_keeps_wrapped_lines) {
+ YGConfigRef config = YGConfigNew();
+ YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureMinContentHeightAtGivenWidth, true);
+ YGConfigSetErrata(config, YGErrataNone);
+
+ YGNodeRef root = YGNodeNewWithConfig(config);
+ YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
+ YGNodeStyleSetWidth(root, 50);
+ YGNodeStyleSetHeight(root, 20);
+
+ YGNodeRef root_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexShrink(root_child0, 1);
+ YGNodeInsertChild(root, root_child0, 0);
+
+ YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetMargin(root_child0_child0, YGEdgeBottom, 5);
+ YGNodeInsertChild(root_child0, root_child0_child0, 0);
+ YGNodeSetContext(root_child0_child0, (void*)"aaaa aaaa aaaa");
+ YGNodeSetMeasureFunc(root_child0_child0, &facebook::yoga::test::IntrinsicSizeMeasure);
+
+ YGNodeRef root_child1 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetHeight(root_child1, 10);
+ YGNodeInsertChild(root, root_child1, 1);
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(35, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child0_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(35, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(35, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child0_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(35, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeFreeRecursive(root);
+
+ YGConfigFree(config);
+}
+
+TEST(YogaTest, auto_min_size_text_wraps_inside_margin_and_padding) {
+ YGConfigRef config = YGConfigNew();
+ YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureMinContentHeightAtGivenWidth, true);
+ YGConfigSetErrata(config, YGErrataNone);
+
+ YGNodeRef root = YGNodeNewWithConfig(config);
+ YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
+ YGNodeStyleSetWidth(root, 110);
+ YGNodeStyleSetHeight(root, 20);
+
+ YGNodeRef root_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexShrink(root_child0, 1);
+ YGNodeStyleSetMargin(root_child0, YGEdgeVertical, 0);
+ YGNodeStyleSetMargin(root_child0, YGEdgeHorizontal, 10);
+ YGNodeStyleSetPadding(root_child0, YGEdgeVertical, 0);
+ YGNodeStyleSetPadding(root_child0, YGEdgeHorizontal, 20);
+ YGNodeInsertChild(root, root_child0, 0);
+ YGNodeSetContext(root_child0, (void*)"aaaa aaaa aaaa");
+ YGNodeSetMeasureFunc(root_child0, &facebook::yoga::test::IntrinsicSizeMeasure);
+
+ YGNodeRef root_child1 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetHeight(root_child1, 10);
+ YGNodeInsertChild(root, root_child1, 1);
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(110, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(90, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(110, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(110, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(90, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(110, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeFreeRecursive(root);
+
+ YGConfigFree(config);
+}
+
+TEST(YogaTest, auto_min_size_text_wraps_at_stated_width) {
+ YGConfigRef config = YGConfigNew();
+ YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureMinContentHeightAtGivenWidth, true);
+ YGConfigSetErrata(config, YGErrataNone);
+
+ YGNodeRef root = YGNodeNewWithConfig(config);
+ YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
+ YGNodeStyleSetWidth(root, 110);
+ YGNodeStyleSetHeight(root, 20);
+
+ YGNodeRef root_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexShrink(root_child0, 1);
+ YGNodeStyleSetWidthPercent(root_child0, 50);
+ YGNodeStyleSetPadding(root_child0, YGEdgeVertical, 0);
+ YGNodeStyleSetPadding(root_child0, YGEdgeHorizontal, 5);
+ YGNodeInsertChild(root, root_child0, 0);
+ YGNodeSetContext(root_child0, (void*)"aaaa aaaa aaaa");
+ YGNodeSetMeasureFunc(root_child0, &facebook::yoga::test::IntrinsicSizeMeasure);
+
+ YGNodeRef root_child1 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetHeight(root_child1, 10);
+ YGNodeInsertChild(root, root_child1, 1);
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(110, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(55, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(110, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(110, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(55, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(55, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(110, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeFreeRecursive(root);
+
+ YGConfigFree(config);
+}
+
+TEST(YogaTest, auto_min_size_text_wraps_at_stated_content_box_width) {
+ YGConfigRef config = YGConfigNew();
+ YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureMinContentHeightAtGivenWidth, true);
+ YGConfigSetErrata(config, YGErrataNone);
+
+ YGNodeRef root = YGNodeNewWithConfig(config);
+ YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
+ YGNodeStyleSetWidth(root, 200);
+ YGNodeStyleSetHeight(root, 20);
+
+ YGNodeRef root_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexShrink(root_child0, 1);
+ YGNodeStyleSetBoxSizing(root_child0, YGBoxSizingContentBox);
+ YGNodeStyleSetWidth(root_child0, 90);
+ YGNodeStyleSetPadding(root_child0, YGEdgeVertical, 0);
+ YGNodeStyleSetPadding(root_child0, YGEdgeHorizontal, 20);
+ YGNodeInsertChild(root, root_child0, 0);
+ YGNodeSetContext(root_child0, (void*)"aaaa aaaa aaaa");
+ YGNodeSetMeasureFunc(root_child0, &facebook::yoga::test::IntrinsicSizeMeasure);
+
+ YGNodeRef root_child1 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetHeight(root_child1, 15);
+ YGNodeInsertChild(root, root_child1, 1);
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(130, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(15, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(70, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(130, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(15, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeFreeRecursive(root);
+
+ YGConfigFree(config);
+}
+
+TEST(YogaTest, auto_min_size_text_wraps_inside_padded_parent) {
+ YGConfigRef config = YGConfigNew();
+ YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureMinContentHeightAtGivenWidth, true);
+ YGConfigSetErrata(config, YGErrataNone);
+
+ YGNodeRef root = YGNodeNewWithConfig(config);
+ YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
+ YGNodeStyleSetWidth(root, 110);
+ YGNodeStyleSetHeight(root, 20);
+
+ YGNodeRef root_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexShrink(root_child0, 1);
+ YGNodeStyleSetPadding(root_child0, YGEdgeVertical, 0);
+ YGNodeStyleSetPadding(root_child0, YGEdgeHorizontal, 30);
+ YGNodeInsertChild(root, root_child0, 0);
+
+ YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config);
+ YGNodeInsertChild(root_child0, root_child0_child0, 0);
+ YGNodeSetContext(root_child0_child0, (void*)"aaaa aaaa aaaa");
+ YGNodeSetMeasureFunc(root_child0_child0, &facebook::yoga::test::IntrinsicSizeMeasure);
+
+ YGNodeRef root_child1 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetHeight(root_child1, 10);
+ YGNodeInsertChild(root, root_child1, 1);
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(110, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(110, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child0_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child0_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(110, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(110, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(110, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child0_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child0_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(110, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeFreeRecursive(root);
+
+ YGConfigFree(config);
+}
+
+TEST(YogaTest, auto_min_size_percent_margin_resolves_against_parent_content_width) {
+ YGConfigRef config = YGConfigNew();
+ YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureMinContentHeightAtGivenWidth, true);
+ YGConfigSetErrata(config, YGErrataNone);
+
+ YGNodeRef root = YGNodeNewWithConfig(config);
+ YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
+ YGNodeStyleSetWidth(root, 200);
+ YGNodeStyleSetHeight(root, 50);
+
+ YGNodeRef root_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexShrink(root_child0, 1);
+ YGNodeStyleSetPadding(root_child0, YGEdgeLeft, 50);
+ YGNodeInsertChild(root, root_child0, 0);
+
+ YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetHeight(root_child0_child0, 10);
+ YGNodeStyleSetMarginPercent(root_child0_child0, YGEdgeTop, 10);
+ YGNodeInsertChild(root_child0, root_child0_child0, 0);
+
+ YGNodeRef root_child1 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetHeight(root_child1, 40);
+ YGNodeInsertChild(root, root_child1, 1);
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0_child0));
+ ASSERT_FLOAT_EQ(15, YGNodeLayoutGetTop(root_child0_child0));
+ ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root_child0_child0));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(25, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0_child0));
+ ASSERT_FLOAT_EQ(15, YGNodeLayoutGetTop(root_child0_child0));
+ ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root_child0_child0));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(25, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeFreeRecursive(root);
+
+ YGConfigFree(config);
+}
+
+TEST(YogaTest, auto_min_size_text_fits_wider_parent) {
+ YGConfigRef config = YGConfigNew();
+ YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureMinContentHeightAtGivenWidth, true);
+ YGConfigSetErrata(config, YGErrataNone);
+
+ YGNodeRef root = YGNodeNewWithConfig(config);
+ YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
+ YGNodeStyleSetWidth(root, 50);
+ YGNodeStyleSetHeight(root, 15);
+
+ YGNodeRef root_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexShrink(root_child0, 1);
+ YGNodeInsertChild(root, root_child0, 0);
+
+ YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetWidth(root_child0_child0, 200);
+ YGNodeInsertChild(root_child0, root_child0_child0, 0);
+
+ YGNodeRef root_child0_child0_child0 = YGNodeNewWithConfig(config);
+ YGNodeInsertChild(root_child0_child0, root_child0_child0_child0, 0);
+ YGNodeSetContext(root_child0_child0_child0, (void*)"aaaa aaaa aaaa");
+ YGNodeSetMeasureFunc(root_child0_child0_child0, &facebook::yoga::test::IntrinsicSizeMeasure);
+
+ YGNodeRef root_child1 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetHeight(root_child1, 10);
+ YGNodeInsertChild(root, root_child1, 1);
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(15, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0_child0));
+ ASSERT_FLOAT_EQ(10, 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(200, YGNodeLayoutGetWidth(root_child0_child0_child0));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0_child0_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(15, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(-150, YGNodeLayoutGetLeft(root_child0_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0_child0));
+ ASSERT_FLOAT_EQ(10, 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(200, YGNodeLayoutGetWidth(root_child0_child0_child0));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0_child0_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeFreeRecursive(root);
+
+ YGConfigFree(config);
+}
+
+TEST(YogaTest, auto_min_size_text_fits_min_width) {
+ YGConfigRef config = YGConfigNew();
+ YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureMinContentHeightAtGivenWidth, true);
+ YGConfigSetErrata(config, YGErrataNone);
+
+ YGNodeRef root = YGNodeNewWithConfig(config);
+ YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
+ YGNodeStyleSetWidth(root, 50);
+ YGNodeStyleSetHeight(root, 15);
+
+ YGNodeRef root_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexShrink(root_child0, 1);
+ YGNodeStyleSetMinWidth(root_child0, 200);
+ YGNodeInsertChild(root, root_child0, 0);
+ YGNodeSetContext(root_child0, (void*)"aaaa aaaa aaaa");
+ YGNodeSetMeasureFunc(root_child0, &facebook::yoga::test::IntrinsicSizeMeasure);
+
+ YGNodeRef root_child1 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetHeight(root_child1, 10);
+ YGNodeInsertChild(root, root_child1, 1);
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(15, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(15, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(-150, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeFreeRecursive(root);
+
+ YGConfigFree(config);
+}
+
+TEST(YogaTest, auto_min_size_text_wraps_at_max_width) {
+ YGConfigRef config = YGConfigNew();
+ YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureMinContentHeightAtGivenWidth, true);
+ YGConfigSetErrata(config, YGErrataNone);
+
+ YGNodeRef root = YGNodeNewWithConfig(config);
+ YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
+ YGNodeStyleSetWidth(root, 200);
+ YGNodeStyleSetHeight(root, 20);
+
+ YGNodeRef root_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexShrink(root_child0, 1);
+ YGNodeStyleSetMaxWidth(root_child0, 50);
+ YGNodeInsertChild(root, root_child0, 0);
+ YGNodeSetContext(root_child0, (void*)"aaaa aaaa aaaa");
+ YGNodeSetMeasureFunc(root_child0, &facebook::yoga::test::IntrinsicSizeMeasure);
+
+ YGNodeRef root_child1 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetHeight(root_child1, 10);
+ YGNodeInsertChild(root, root_child1, 1);
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(150, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeFreeRecursive(root);
+
+ YGConfigFree(config);
+}
+
+TEST(YogaTest, auto_min_size_text_below_row_wraps_at_max_width) {
+ YGConfigRef config = YGConfigNew();
+ YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureMinContentHeightAtGivenWidth, true);
+ YGConfigSetErrata(config, YGErrataNone);
+
+ YGNodeRef root = YGNodeNewWithConfig(config);
+ YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
+ YGNodeStyleSetWidth(root, 200);
+ YGNodeStyleSetHeight(root, 20);
+
+ YGNodeRef root_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexShrink(root_child0, 1);
+ YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow);
+ YGNodeInsertChild(root, root_child0, 0);
+
+ YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetMaxWidth(root_child0_child0, 50);
+ YGNodeInsertChild(root_child0, root_child0_child0, 0);
+ YGNodeSetContext(root_child0_child0, (void*)"aaaa aaaa aaaa");
+ YGNodeSetMeasureFunc(root_child0_child0, &facebook::yoga::test::IntrinsicSizeMeasure);
+
+ YGNodeRef root_child1 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetHeight(root_child1, 10);
+ YGNodeInsertChild(root, root_child1, 1);
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child0_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(150, YGNodeLayoutGetLeft(root_child0_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child0_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeFreeRecursive(root);
+
+ YGConfigFree(config);
+}
+
+TEST(YogaTest, auto_min_size_text_below_row_is_not_wrapped) {
+ YGConfigRef config = YGConfigNew();
+ YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureMinContentHeightAtGivenWidth, true);
+ YGConfigSetErrata(config, YGErrataNone);
+
+ YGNodeRef root = YGNodeNewWithConfig(config);
+ YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
+ YGNodeStyleSetWidth(root, 50);
+ YGNodeStyleSetHeight(root, 15);
+
+ YGNodeRef root_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexShrink(root_child0, 1);
+ YGNodeInsertChild(root, root_child0, 0);
+
+ YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexDirection(root_child0_child0, YGFlexDirectionRow);
+ YGNodeInsertChild(root_child0, root_child0_child0, 0);
+
+ YGNodeRef root_child0_child0_child0 = YGNodeNewWithConfig(config);
+ YGNodeInsertChild(root_child0_child0, root_child0_child0_child0, 0);
+
+ YGNodeRef root_child0_child0_child0_child0 = YGNodeNewWithConfig(config);
+ YGNodeInsertChild(root_child0_child0_child0, root_child0_child0_child0_child0, 0);
+ YGNodeSetContext(root_child0_child0_child0_child0, (void*)"aaaa aaaa aaaa");
+ YGNodeSetMeasureFunc(root_child0_child0_child0_child0, &facebook::yoga::test::IntrinsicSizeMeasure);
+
+ YGNodeRef root_child0_child0_child0_child1 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetWidth(root_child0_child0_child0_child1, 200);
+ YGNodeInsertChild(root_child0_child0_child0, root_child0_child0_child0_child1, 1);
+
+ YGNodeRef root_child1 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetHeight(root_child1, 10);
+ YGNodeInsertChild(root, root_child1, 1);
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(15, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0));
+ ASSERT_FLOAT_EQ(10, 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(200, YGNodeLayoutGetWidth(root_child0_child0_child0));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0_child0_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0_child0));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0_child0_child0_child0));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0_child0_child0_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0_child0_child0_child1));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0_child0_child0_child1));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0_child0_child0_child1));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(15, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0_child0));
+
+ ASSERT_FLOAT_EQ(-150, YGNodeLayoutGetLeft(root_child0_child0_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0_child0_child0));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0_child0_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0_child0));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0_child0_child0_child0));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0_child0_child0_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0_child0_child0_child1));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0_child0_child0_child1));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0_child0_child0_child1));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeFreeRecursive(root);
+
+ YGConfigFree(config);
+}
+
+TEST(YogaTest, auto_min_size_text_in_wrapping_column_keeps_wrapped_lines) {
+ YGConfigRef config = YGConfigNew();
+ YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureMinContentHeightAtGivenWidth, true);
+ YGConfigSetErrata(config, YGErrataNone);
+
+ YGNodeRef root = YGNodeNewWithConfig(config);
+ YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
+ YGNodeStyleSetWidth(root, 50);
+ YGNodeStyleSetHeight(root, 15);
+
+ YGNodeRef root_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexShrink(root_child0, 1);
+ YGNodeStyleSetFlexWrap(root_child0, YGWrapWrap);
+ YGNodeInsertChild(root, root_child0, 0);
+
+ YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config);
+ YGNodeInsertChild(root_child0, root_child0_child0, 0);
+ YGNodeSetContext(root_child0_child0, (void*)"aaaa aaaa aaaa");
+ YGNodeSetMeasureFunc(root_child0_child0, &facebook::yoga::test::IntrinsicSizeMeasure);
+
+ YGNodeRef root_child0_child1 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetWidth(root_child0_child1, 200);
+ YGNodeInsertChild(root_child0, root_child0_child1, 1);
+
+ YGNodeRef root_child1 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetHeight(root_child1, 10);
+ YGNodeInsertChild(root, root_child1, 1);
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(15, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0_child0));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child0_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child1));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child0_child1));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0_child1));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0_child1));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(15, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(-150, YGNodeLayoutGetLeft(root_child0_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0_child0));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child0_child0));
+
+ ASSERT_FLOAT_EQ(-150, YGNodeLayoutGetLeft(root_child0_child1));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child0_child1));
+ ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0_child1));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0_child1));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeFreeRecursive(root);
+
+ YGConfigFree(config);
+}
diff --git a/yoga/YGEnums.cpp b/yoga/YGEnums.cpp
index 017d6ee45a..194e99a6aa 100644
--- a/yoga/YGEnums.cpp
+++ b/yoga/YGEnums.cpp
@@ -135,6 +135,8 @@ const char* YGExperimentalFeatureToString(const YGExperimentalFeature value) {
return "web-flex-basis";
case YGExperimentalFeatureFixFlexBasisFitContent:
return "fix-flex-basis-fit-content";
+ case YGExperimentalFeatureMinContentHeightAtGivenWidth:
+ return "min-content-height-at-given-width";
}
return "unknown";
}
diff --git a/yoga/YGEnums.h b/yoga/YGEnums.h
index c672870023..b10b74f98f 100644
--- a/yoga/YGEnums.h
+++ b/yoga/YGEnums.h
@@ -76,7 +76,8 @@ YG_DEFINE_ENUM_FLAG_OPERATORS(YGErrata)
YG_ENUM_DECL(
YGExperimentalFeature,
YGExperimentalFeatureWebFlexBasis,
- YGExperimentalFeatureFixFlexBasisFitContent)
+ YGExperimentalFeatureFixFlexBasisFitContent,
+ YGExperimentalFeatureMinContentHeightAtGivenWidth)
YG_ENUM_DECL(
YGFlexDirection,
diff --git a/yoga/YGNode.h b/yoga/YGNode.h
index 4f8cdf81a5..89aa72b99d 100644
--- a/yoga/YGNode.h
+++ b/yoga/YGNode.h
@@ -226,17 +226,20 @@ YG_EXPORT bool YGNodeHasMeasureFunc(YGNodeConstRef node);
* size along the main axis.
*
* The signature mirrors `YGMeasureFunc`. The algorithm calls this with
- * `AtMost 0` along the probed axis and `Undefined` on the other. A
+ * `AtMost 0` along the probed axis and `Undefined` on the other. With
+ * `YGExperimentalFeatureMinContentHeightAtGivenWidth`, it probes a height
+ * with the node's width as an `AtMost` width and an `Undefined` height. A
* min-content-aware Primitive can return its true minimum (e.g., `Image`
* and `Collection` along the scroll axis can return 0; text returns its
* longest-word width; etc.) without doing a full measure pass.
*
- * When unset, the algorithm falls back to the regular `YGMeasureFunc`
- * invoked with the same `AtMost 0` constraint — preserving today's
- * behavior. Setting this is a perf opt-in for Primitives whose min-content
- * size is cheap to compute or differs from what the regular measure would
- * return. Its results are kept, as a measure function's are, until the node is
- * marked dirty.
+ * When unset, the algorithm falls back to the regular `YGMeasureFunc` with
+ * the same arguments. Setting this is a perf opt-in for Primitives whose
+ * min-content size is cheap to compute or differs from what the regular
+ * measure would return. Its results are kept, as a measure function's are,
+ * until the node is marked dirty. With
+ * `YGExperimentalFeatureMinContentHeightAtGivenWidth`, a height result is also
+ * measured again when the width it was measured at changes.
*/
typedef YGSize (*YGMinContentMeasureFunc)(
YGNodeConstRef node,
diff --git a/yoga/algorithm/CalculateLayout.cpp b/yoga/algorithm/CalculateLayout.cpp
index b490dcca86..aa6131b410 100644
--- a/yoga/algorithm/CalculateLayout.cpp
+++ b/yoga/algorithm/CalculateLayout.cpp
@@ -916,7 +916,8 @@ struct MinContentSize {
};
// The min-content of a leaf with a measure function: its memoized measurement,
-// which leaves out its padding and border, with them added.
+// which leaves out its padding and border, with them added. A height measured
+// at the leaf's width depends on the owner's width as well.
static MinContentSize leafMinContentSize(
const yoga::Node* const node,
const FlexDirection requestedAxis,
@@ -927,11 +928,12 @@ static MinContentSize leafMinContentSize(
requestedAxis, leafDirection, ownerWidth) +
node->style().computeFlexEndPaddingAndBorder(
requestedAxis, leafDirection, ownerWidth);
+ const LayoutResults& layout = node->getLayout();
+ const Dimension axisDimension = dimension(requestedAxis);
return {
- node->getLayout()
- .minContent[yoga::to_underlying(dimension(requestedAxis))] +
- paddingAndBorder,
- node->style().hasPercentPadding()};
+ layout.minContent[yoga::to_underlying(axisDimension)] + paddingAndBorder,
+ node->style().hasPercentPadding() ||
+ layout.minContentResolvesAgainstOwnerWidth(axisDimension)};
}
// The min-content of `node` that reading it gives, without writing to it: a
@@ -955,31 +957,26 @@ static std::optional readMinContentMainSize(
return MinContentSize{staticMin.unwrap(), false};
}
- const Dimension axisDimension = dimension(requestedAxis);
- if (node->hasMeasureFunc()) {
- if (!hasMemoizedMinContent(
- node, axisDimension, ownerDirection, generationCount)) {
- return std::nullopt;
- }
- return leafMinContentSize(node, requestedAxis, ownerDirection, ownerWidth);
- }
-
- if (node->getChildCount() == 0) {
+ if (!node->hasMeasureFunc() && node->getChildCount() == 0) {
return MinContentSize{0.0f, false};
}
+ const Dimension axisDimension = dimension(requestedAxis);
const LayoutResults& layout = node->getLayout();
const auto axisIndex = yoga::to_underlying(axisDimension);
- if (hasMemoizedMinContent(
- node, axisDimension, ownerDirection, generationCount) &&
- (!layout.minContentResolvesAgainstOwnerWidth(axisDimension) ||
- yoga::inexactEquals(
+ if (!hasMemoizedMinContent(
+ node, axisDimension, ownerDirection, generationCount) ||
+ (layout.minContentResolvesAgainstOwnerWidth(axisDimension) &&
+ !yoga::inexactEquals(
layout.minContentOwnerWidth[axisIndex], ownerWidth))) {
- return MinContentSize{
- layout.minContent[axisIndex],
- layout.minContentResolvesAgainstOwnerWidth(axisDimension)};
+ return std::nullopt;
}
- return std::nullopt;
+ if (node->hasMeasureFunc()) {
+ return leafMinContentSize(node, requestedAxis, ownerDirection, ownerWidth);
+ }
+ return MinContentSize{
+ layout.minContent[axisIndex],
+ layout.minContentResolvesAgainstOwnerWidth(axisDimension)};
}
static MinContentSize computeChildMinContentContribution(
@@ -991,6 +988,52 @@ static MinContentSize computeChildMinContentContribution(
float ownerHeight,
uint32_t generationCount);
+// The content-box width of `node` under an owner whose content box is
+// `ownerWidth` wide: the width it states, else the owner's less its margins,
+// within the minimum and maximum it states. This is its width as a stretched
+// item of a column; one that is not stretched may be narrower, which the walk
+// does not model.
+static float contentWidthUnderOwner(
+ const yoga::Node* const node,
+ const Direction ownerDirection,
+ const float ownerWidth) {
+ const Style& style = node->style();
+ const Direction direction = node->resolveDirection(ownerDirection);
+ const float paddingAndBorder = style.computePaddingAndBorderForDimension(
+ direction, Dimension::Width, ownerWidth);
+ const FloatOptional stated =
+ style.dimension(Dimension::Width).resolve(ownerWidth);
+ FloatOptional borderBoxWidth{
+ ownerWidth - style.computeMarginForAxis(FlexDirection::Row, ownerWidth)};
+ if (stated.isDefined()) {
+ borderBoxWidth = style.boxSizing() == BoxSizing::ContentBox
+ ? stated + FloatOptional{paddingAndBorder}
+ : stated;
+ }
+ borderBoxWidth = boundAxisWithinMinAndMax(
+ node,
+ direction,
+ FlexDirection::Row,
+ borderBoxWidth,
+ ownerWidth,
+ ownerWidth);
+ if (borderBoxWidth.isUndefined()) {
+ // With no width to fill, the box is still no wider than its maximum.
+ borderBoxWidth = boundAxisWithinMinAndMax(
+ node,
+ direction,
+ FlexDirection::Row,
+ style.resolvedMaxDimension(
+ direction, Dimension::Width, ownerWidth, ownerWidth),
+ ownerWidth,
+ ownerWidth);
+ }
+ if (borderBoxWidth.isUndefined()) {
+ return YGUndefined;
+ }
+ return yoga::maxOrDefined(borderBoxWidth.unwrap() - paddingAndBorder, 0.0f);
+}
+
// Measures or walks `node`, which the tree being laid out owns, and memoizes
// the result.
static MinContentSize measureOrWalkMinContentMainSize(
@@ -1007,20 +1050,31 @@ static MinContentSize measureOrWalkMinContentMainSize(
if (node->hasMeasureFunc()) {
// 2. Dynamic min-content callback if set (for Primitives whose
// min-content depends on state). Otherwise fall back to the regular
- // measure function with `AtMost 0`, which text measurers naturally
- // answer with longest-word width.
+ // measure function. A width is probed with `AtMost 0`, which text
+ // measurers naturally answer with longest-word width. A height is probed
+ // the same way unless `MinContentHeightAtGivenWidth` is on: a text
+ // measurer answers `AtMost 0` with no height at all, where a min-content
+ // height is the height the content takes at the box's width (css-sizing-3
+ // §2.1), so the leaf is measured at its width with no limit on its height.
+ const bool heightAtGivenWidth = !wantRow &&
+ node->getConfig()->isExperimentalFeatureEnabled(
+ ExperimentalFeature::MinContentHeightAtGivenWidth);
+ float width = wantRow ? 0.0f : YGUndefined;
+ if (heightAtGivenWidth) {
+ width = contentWidthUnderOwner(node, ownerDirection, ownerWidth);
+ }
+ const MeasureMode widthMode =
+ yoga::isDefined(width) ? MeasureMode::AtMost : MeasureMode::Undefined;
+ const float height = wantRow || heightAtGivenWidth ? YGUndefined : 0.0f;
+ const MeasureMode heightMode =
+ yoga::isDefined(height) ? MeasureMode::AtMost : MeasureMode::Undefined;
const YGSize size = node->hasMinContentMeasureFunc()
- ? node->measureMinContent(
- wantRow ? 0.0f : YGUndefined,
- wantRow ? MeasureMode::AtMost : MeasureMode::Undefined,
- wantRow ? YGUndefined : 0.0f,
- wantRow ? MeasureMode::Undefined : MeasureMode::AtMost)
- : node->measure(
- wantRow ? 0.0f : YGUndefined,
- wantRow ? MeasureMode::AtMost : MeasureMode::Undefined,
- wantRow ? YGUndefined : 0.0f,
- wantRow ? MeasureMode::Undefined : MeasureMode::AtMost);
+ ? node->measureMinContent(width, widthMode, height, heightMode)
+ : node->measure(width, widthMode, height, heightMode);
layout.minContent[axisIndex] = wantRow ? size.width : size.height;
+ layout.minContentOwnerWidth[axisIndex] = ownerWidth;
+ layout.setMinContentResolvesAgainstOwnerWidth(
+ dimension(requestedAxis), heightAtGivenWidth);
layout.minContentGeneration[axisIndex] = generationCount;
return leafMinContentSize(node, requestedAxis, ownerDirection, ownerWidth);
}
@@ -1034,6 +1088,20 @@ static MinContentSize measureOrWalkMinContentMainSize(
const bool childrenAddUp = isRow(node->style().flexDirection()) == wantRow &&
(node->style().flexWrap() == Wrap::NoWrap || !wantRow);
+ // A height measured at a leaf's width needs the width of each box above the
+ // leaf. A column's children are walked against its content width, which a
+ // stretched child fills. A row's children share its width by their content,
+ // which the walk does not know, so they are walked against no width and
+ // their text is as tall as it is unwrapped, the least it can be.
+ float childOwnerWidth = ownerWidth;
+ if (!wantRow &&
+ node->getConfig()->isExperimentalFeatureEnabled(
+ ExperimentalFeature::MinContentHeightAtGivenWidth)) {
+ childOwnerWidth = childrenAddUp
+ ? contentWidthUnderOwner(node, ownerDirection, ownerWidth)
+ : YGUndefined;
+ }
+
float minContent = 0.0f;
size_t itemCount = 0;
bool resolvesAgainstOwnerWidth = node->style().hasPercentPadding();
@@ -1051,11 +1119,11 @@ static MinContentSize measureOrWalkMinContentMainSize(
i,
requestedAxis,
direction,
- ownerWidth,
+ childOwnerWidth,
ownerHeight,
generationCount);
- const float childSize =
- child.size + childStyle.computeMarginForAxis(requestedAxis, ownerWidth);
+ const float childSize = child.size +
+ childStyle.computeMarginForAxis(requestedAxis, childOwnerWidth);
minContent = childrenAddUp ? minContent + childSize
: std::max(minContent, childSize);
resolvesAgainstOwnerWidth = resolvesAgainstOwnerWidth ||
diff --git a/yoga/enums/ExperimentalFeature.h b/yoga/enums/ExperimentalFeature.h
index 7e6c5eb8b6..26328d6abb 100644
--- a/yoga/enums/ExperimentalFeature.h
+++ b/yoga/enums/ExperimentalFeature.h
@@ -18,11 +18,12 @@ namespace facebook::yoga {
enum class ExperimentalFeature : uint8_t {
WebFlexBasis = YGExperimentalFeatureWebFlexBasis,
FixFlexBasisFitContent = YGExperimentalFeatureFixFlexBasisFitContent,
+ MinContentHeightAtGivenWidth = YGExperimentalFeatureMinContentHeightAtGivenWidth,
};
template <>
constexpr int32_t ordinalCount() {
- return 2;
+ return 3;
}
constexpr ExperimentalFeature scopedEnum(YGExperimentalFeature unscoped) {