Include margin when calculating if children overflow

Summary: Include margin when calculating if children overflow

Reviewed By: passy

Differential Revision: D5044471

fbshipit-source-id: e7c1eb694445ffb898bcf375d9deefc558c49f11
This commit is contained in:
Emil Sjolander
2017-05-12 09:03:23 -07:00
committed by Facebook Github Bot
parent 85c2e406e4
commit 488a7c1fe0
6 changed files with 413 additions and 5 deletions

View File

@@ -1545,5 +1545,103 @@ namespace Facebook.Yoga
Assert.AreEqual(100f, root_child2.LayoutHeight); Assert.AreEqual(100f, root_child2.LayoutHeight);
} }
[Test]
public void Test_wrap_nodes_with_content_sizing_overflowing_margin()
{
YogaConfig config = new YogaConfig();
YogaNode root = new YogaNode(config);
root.Width = 500;
root.Height = 500;
YogaNode root_child0 = new YogaNode(config);
root_child0.FlexDirection = YogaFlexDirection.Row;
root_child0.Wrap = YogaWrap.Wrap;
root_child0.Width = 85;
root.Insert(0, root_child0);
YogaNode root_child0_child0 = new YogaNode(config);
root_child0.Insert(0, root_child0_child0);
YogaNode root_child0_child0_child0 = new YogaNode(config);
root_child0_child0_child0.Width = 40;
root_child0_child0_child0.Height = 40;
root_child0_child0.Insert(0, root_child0_child0_child0);
YogaNode root_child0_child1 = new YogaNode(config);
root_child0_child1.MarginRight = 10;
root_child0.Insert(1, root_child0_child1);
YogaNode root_child0_child1_child0 = new YogaNode(config);
root_child0_child1_child0.Width = 40;
root_child0_child1_child0.Height = 40;
root_child0_child1.Insert(0, root_child0_child1_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(500f, root.LayoutWidth);
Assert.AreEqual(500f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(85f, root_child0.LayoutWidth);
Assert.AreEqual(80f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0.LayoutY);
Assert.AreEqual(40f, root_child0_child0.LayoutWidth);
Assert.AreEqual(40f, root_child0_child0.LayoutHeight);
Assert.AreEqual(0f, root_child0_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0_child0.LayoutY);
Assert.AreEqual(40f, root_child0_child0_child0.LayoutWidth);
Assert.AreEqual(40f, root_child0_child0_child0.LayoutHeight);
Assert.AreEqual(0f, root_child0_child1.LayoutX);
Assert.AreEqual(40f, root_child0_child1.LayoutY);
Assert.AreEqual(40f, root_child0_child1.LayoutWidth);
Assert.AreEqual(40f, root_child0_child1.LayoutHeight);
Assert.AreEqual(0f, root_child0_child1_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child1_child0.LayoutY);
Assert.AreEqual(40f, root_child0_child1_child0.LayoutWidth);
Assert.AreEqual(40f, root_child0_child1_child0.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(500f, root.LayoutWidth);
Assert.AreEqual(500f, root.LayoutHeight);
Assert.AreEqual(415f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(85f, root_child0.LayoutWidth);
Assert.AreEqual(80f, root_child0.LayoutHeight);
Assert.AreEqual(45f, root_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0.LayoutY);
Assert.AreEqual(40f, root_child0_child0.LayoutWidth);
Assert.AreEqual(40f, root_child0_child0.LayoutHeight);
Assert.AreEqual(0f, root_child0_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0_child0.LayoutY);
Assert.AreEqual(40f, root_child0_child0_child0.LayoutWidth);
Assert.AreEqual(40f, root_child0_child0_child0.LayoutHeight);
Assert.AreEqual(35f, root_child0_child1.LayoutX);
Assert.AreEqual(40f, root_child0_child1.LayoutY);
Assert.AreEqual(40f, root_child0_child1.LayoutWidth);
Assert.AreEqual(40f, root_child0_child1.LayoutHeight);
Assert.AreEqual(0f, root_child0_child1_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child1_child0.LayoutY);
Assert.AreEqual(40f, root_child0_child1_child0.LayoutWidth);
Assert.AreEqual(40f, root_child0_child1_child0.LayoutHeight);
}
} }
} }

View File

@@ -124,4 +124,15 @@
<div style="width: 100px; height: 500px; max-height: 200px; flex: 1;"></div> <div style="width: 100px; height: 500px; max-height: 200px; flex: 1;"></div>
<div style="width: 200px; height: 200px; margin: 20px; flex: 1"></div> <div style="width: 200px; height: 200px; margin: 20px; flex: 1"></div>
<div style="width: 100px; height: 100px;"></div> <div style="width: 100px; height: 100px;"></div>
</div> </div>
<div id="wrap_nodes_with_content_sizing_overflowing_margin" style="width: 500px; height: 500px;">
<div style="flex-direction: row; flex-wrap: wrap; width: 85px;">
<div>
<div style="height: 40px; width: 40px;"></div>
</div>
<div style="margin-right: 10px;">
<div style="height: 40px; width: 40px;"></div>
</div>
</div>
</div>

View File

@@ -1526,4 +1526,101 @@ public class YGFlexWrapTest {
assertEquals(100f, root_child2.getLayoutHeight(), 0.0f); assertEquals(100f, root_child2.getLayoutHeight(), 0.0f);
} }
@Test
public void test_wrap_nodes_with_content_sizing_overflowing_margin() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
root.setWidth(500f);
root.setHeight(500f);
final YogaNode root_child0 = new YogaNode(config);
root_child0.setFlexDirection(YogaFlexDirection.ROW);
root_child0.setWrap(YogaWrap.WRAP);
root_child0.setWidth(85f);
root.addChildAt(root_child0, 0);
final YogaNode root_child0_child0 = new YogaNode(config);
root_child0.addChildAt(root_child0_child0, 0);
final YogaNode root_child0_child0_child0 = new YogaNode(config);
root_child0_child0_child0.setWidth(40f);
root_child0_child0_child0.setHeight(40f);
root_child0_child0.addChildAt(root_child0_child0_child0, 0);
final YogaNode root_child0_child1 = new YogaNode(config);
root_child0_child1.setMargin(YogaEdge.RIGHT, 10f);
root_child0.addChildAt(root_child0_child1, 1);
final YogaNode root_child0_child1_child0 = new YogaNode(config);
root_child0_child1_child0.setWidth(40f);
root_child0_child1_child0.setHeight(40f);
root_child0_child1.addChildAt(root_child0_child1_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(500f, root.getLayoutWidth(), 0.0f);
assertEquals(500f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(85f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(80f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(40f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, 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(40f, root_child0_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0_child0_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child1.getLayoutX(), 0.0f);
assertEquals(40f, root_child0_child1.getLayoutY(), 0.0f);
assertEquals(40f, root_child0_child1.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0_child1.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child1_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child1_child0.getLayoutY(), 0.0f);
assertEquals(40f, root_child0_child1_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0_child1_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(500f, root.getLayoutWidth(), 0.0f);
assertEquals(500f, root.getLayoutHeight(), 0.0f);
assertEquals(415f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(85f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(80f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(45f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(40f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, 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(40f, root_child0_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0_child0_child0.getLayoutHeight(), 0.0f);
assertEquals(35f, root_child0_child1.getLayoutX(), 0.0f);
assertEquals(40f, root_child0_child1.getLayoutY(), 0.0f);
assertEquals(40f, root_child0_child1.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0_child1.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child1_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child1_child0.getLayoutY(), 0.0f);
assertEquals(40f, root_child0_child1_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0_child1_child0.getLayoutHeight(), 0.0f);
}
} }

View File

@@ -1593,3 +1593,104 @@ it("wrapped_column_max_height_flex", function () {
config.free(); config.free();
} }
}); });
it("wrap_nodes_with_content_sizing_overflowing_margin", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setWidth(500);
root.setHeight(500);
var root_child0 = Yoga.Node.create(config);
root_child0.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
root_child0.setFlexWrap(Yoga.WRAP_WRAP);
root_child0.setWidth(85);
root.insertChild(root_child0, 0);
var root_child0_child0 = Yoga.Node.create(config);
root_child0.insertChild(root_child0_child0, 0);
var root_child0_child0_child0 = Yoga.Node.create(config);
root_child0_child0_child0.setWidth(40);
root_child0_child0_child0.setHeight(40);
root_child0_child0.insertChild(root_child0_child0_child0, 0);
var root_child0_child1 = Yoga.Node.create(config);
root_child0_child1.setMargin(Yoga.EDGE_RIGHT, 10);
root_child0.insertChild(root_child0_child1, 1);
var root_child0_child1_child0 = Yoga.Node.create(config);
root_child0_child1_child0.setWidth(40);
root_child0_child1_child0.setHeight(40);
root_child0_child1.insertChild(root_child0_child1_child0, 0);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(500 === root.getComputedWidth(), "500 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(500 === root.getComputedHeight(), "500 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(85 === root_child0.getComputedWidth(), "85 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(80 === root_child0.getComputedHeight(), "80 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(0 === root_child0_child0.getComputedLeft(), "0 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")");
console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")");
console.assert(40 === root_child0_child0.getComputedWidth(), "40 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")");
console.assert(40 === root_child0_child0.getComputedHeight(), "40 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")");
console.assert(0 === root_child0_child0_child0.getComputedLeft(), "0 === root_child0_child0_child0.getComputedLeft() (" + root_child0_child0_child0.getComputedLeft() + ")");
console.assert(0 === root_child0_child0_child0.getComputedTop(), "0 === root_child0_child0_child0.getComputedTop() (" + root_child0_child0_child0.getComputedTop() + ")");
console.assert(40 === root_child0_child0_child0.getComputedWidth(), "40 === root_child0_child0_child0.getComputedWidth() (" + root_child0_child0_child0.getComputedWidth() + ")");
console.assert(40 === root_child0_child0_child0.getComputedHeight(), "40 === root_child0_child0_child0.getComputedHeight() (" + root_child0_child0_child0.getComputedHeight() + ")");
console.assert(0 === root_child0_child1.getComputedLeft(), "0 === root_child0_child1.getComputedLeft() (" + root_child0_child1.getComputedLeft() + ")");
console.assert(40 === root_child0_child1.getComputedTop(), "40 === root_child0_child1.getComputedTop() (" + root_child0_child1.getComputedTop() + ")");
console.assert(40 === root_child0_child1.getComputedWidth(), "40 === root_child0_child1.getComputedWidth() (" + root_child0_child1.getComputedWidth() + ")");
console.assert(40 === root_child0_child1.getComputedHeight(), "40 === root_child0_child1.getComputedHeight() (" + root_child0_child1.getComputedHeight() + ")");
console.assert(0 === root_child0_child1_child0.getComputedLeft(), "0 === root_child0_child1_child0.getComputedLeft() (" + root_child0_child1_child0.getComputedLeft() + ")");
console.assert(0 === root_child0_child1_child0.getComputedTop(), "0 === root_child0_child1_child0.getComputedTop() (" + root_child0_child1_child0.getComputedTop() + ")");
console.assert(40 === root_child0_child1_child0.getComputedWidth(), "40 === root_child0_child1_child0.getComputedWidth() (" + root_child0_child1_child0.getComputedWidth() + ")");
console.assert(40 === root_child0_child1_child0.getComputedHeight(), "40 === root_child0_child1_child0.getComputedHeight() (" + root_child0_child1_child0.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(500 === root.getComputedWidth(), "500 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(500 === root.getComputedHeight(), "500 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(415 === root_child0.getComputedLeft(), "415 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(85 === root_child0.getComputedWidth(), "85 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(80 === root_child0.getComputedHeight(), "80 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(45 === root_child0_child0.getComputedLeft(), "45 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")");
console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")");
console.assert(40 === root_child0_child0.getComputedWidth(), "40 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")");
console.assert(40 === root_child0_child0.getComputedHeight(), "40 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")");
console.assert(0 === root_child0_child0_child0.getComputedLeft(), "0 === root_child0_child0_child0.getComputedLeft() (" + root_child0_child0_child0.getComputedLeft() + ")");
console.assert(0 === root_child0_child0_child0.getComputedTop(), "0 === root_child0_child0_child0.getComputedTop() (" + root_child0_child0_child0.getComputedTop() + ")");
console.assert(40 === root_child0_child0_child0.getComputedWidth(), "40 === root_child0_child0_child0.getComputedWidth() (" + root_child0_child0_child0.getComputedWidth() + ")");
console.assert(40 === root_child0_child0_child0.getComputedHeight(), "40 === root_child0_child0_child0.getComputedHeight() (" + root_child0_child0_child0.getComputedHeight() + ")");
console.assert(35 === root_child0_child1.getComputedLeft(), "35 === root_child0_child1.getComputedLeft() (" + root_child0_child1.getComputedLeft() + ")");
console.assert(40 === root_child0_child1.getComputedTop(), "40 === root_child0_child1.getComputedTop() (" + root_child0_child1.getComputedTop() + ")");
console.assert(40 === root_child0_child1.getComputedWidth(), "40 === root_child0_child1.getComputedWidth() (" + root_child0_child1.getComputedWidth() + ")");
console.assert(40 === root_child0_child1.getComputedHeight(), "40 === root_child0_child1.getComputedHeight() (" + root_child0_child1.getComputedHeight() + ")");
console.assert(0 === root_child0_child1_child0.getComputedLeft(), "0 === root_child0_child1_child0.getComputedLeft() (" + root_child0_child1_child0.getComputedLeft() + ")");
console.assert(0 === root_child0_child1_child0.getComputedTop(), "0 === root_child0_child1_child0.getComputedTop() (" + root_child0_child1_child0.getComputedTop() + ")");
console.assert(40 === root_child0_child1_child0.getComputedWidth(), "40 === root_child0_child1_child0.getComputedWidth() (" + root_child0_child1_child0.getComputedWidth() + ")");
console.assert(40 === root_child0_child1_child0.getComputedHeight(), "40 === root_child0_child1_child0.getComputedHeight() (" + root_child0_child1_child0.getComputedHeight() + ")");
} finally {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});

View File

@@ -1539,3 +1539,101 @@ TEST(YogaTest, wrapped_column_max_height_flex) {
YGConfigFree(config); YGConfigFree(config);
} }
TEST(YogaTest, wrap_nodes_with_content_sizing_overflowing_margin) {
const YGConfigRef config = YGConfigNew();
const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root, 500);
YGNodeStyleSetHeight(root, 500);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow);
YGNodeStyleSetFlexWrap(root_child0, YGWrapWrap);
YGNodeStyleSetWidth(root_child0, 85);
YGNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config);
YGNodeInsertChild(root_child0, root_child0_child0, 0);
const YGNodeRef root_child0_child0_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root_child0_child0_child0, 40);
YGNodeStyleSetHeight(root_child0_child0_child0, 40);
YGNodeInsertChild(root_child0_child0, root_child0_child0_child0, 0);
const YGNodeRef root_child0_child1 = YGNodeNewWithConfig(config);
YGNodeStyleSetMargin(root_child0_child1, YGEdgeRight, 10);
YGNodeInsertChild(root_child0, root_child0_child1, 1);
const YGNodeRef root_child0_child1_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root_child0_child1_child0, 40);
YGNodeStyleSetHeight(root_child0_child1_child0, 40);
YGNodeInsertChild(root_child0_child1, root_child0_child1_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(85, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child0_child0));
ASSERT_FLOAT_EQ(40, 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(40, YGNodeLayoutGetWidth(root_child0_child0_child0));
ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child1));
ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child0_child1));
ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child0_child1));
ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0_child1));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child1_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child1_child0));
ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child0_child1_child0));
ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0_child1_child0));
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root));
ASSERT_FLOAT_EQ(415, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(85, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0));
ASSERT_FLOAT_EQ(45, YGNodeLayoutGetLeft(root_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child0_child0));
ASSERT_FLOAT_EQ(40, 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(40, YGNodeLayoutGetWidth(root_child0_child0_child0));
ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0_child0_child0));
ASSERT_FLOAT_EQ(35, YGNodeLayoutGetLeft(root_child0_child1));
ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child0_child1));
ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child0_child1));
ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0_child1));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child1_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child1_child0));
ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child0_child1_child0));
ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0_child1_child0));
YGNodeFreeRecursive(root);
YGConfigFree(config);
}

View File

@@ -2109,7 +2109,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
} }
} }
float totalFlexBasis = 0; float totalOuterFlexBasis = 0;
// STEP 3: DETERMINE FLEX BASIS FOR EACH ITEM // STEP 3: DETERMINE FLEX BASIS FOR EACH ITEM
for (uint32_t i = 0; i < childCount; i++) { for (uint32_t i = 0; i < childCount; i++) {
@@ -2162,11 +2162,14 @@ static void YGNodelayoutImpl(const YGNodeRef node,
} }
} }
totalFlexBasis += child->layout.computedFlexBasis; totalOuterFlexBasis +=
child->layout.computedFlexBasis + YGNodeMarginForAxis(child, mainAxis, availableInnerWidth);
;
} }
const bool flexBasisOverflows = const bool flexBasisOverflows = measureModeMainDim == YGMeasureModeUndefined
measureModeMainDim == YGMeasureModeUndefined ? false : totalFlexBasis > availableInnerMainDim; ? false
: totalOuterFlexBasis > availableInnerMainDim;
if (isNodeFlexWrap && flexBasisOverflows && measureModeMainDim == YGMeasureModeAtMost) { if (isNodeFlexWrap && flexBasisOverflows && measureModeMainDim == YGMeasureModeAtMost) {
measureModeMainDim = YGMeasureModeExactly; measureModeMainDim = YGMeasureModeExactly;
} }