From 7d5eb7596bd6d4c9c211c3308bde03fa934d28a6 Mon Sep 17 00:00:00 2001 From: catten Date: Mon, 4 Dec 2023 18:35:37 +0800 Subject: [PATCH 1/3] * fix Container min-height produces incorrect size when flex-wrap and Height is Auto --- tests/generated/YGMinMaxDimensionTest.cpp | 112 ++++++++++++++++++++++ yoga/algorithm/CalculateLayout.cpp | 7 +- 2 files changed, 114 insertions(+), 5 deletions(-) diff --git a/tests/generated/YGMinMaxDimensionTest.cpp b/tests/generated/YGMinMaxDimensionTest.cpp index 693bd132e5..7a9b591aff 100644 --- a/tests/generated/YGMinMaxDimensionTest.cpp +++ b/tests/generated/YGMinMaxDimensionTest.cpp @@ -1352,3 +1352,115 @@ TEST(YogaTest, min_max_percent_no_width_height) { YGConfigFree(config); } +TEST(YogaTest, Auto_Height_Min_Height) { + YGNodeRef node = nullptr; + YGNodeRef root = nullptr; + YGConfigRef config = nullptr; + config = YGConfigNew(); + root = YGNodeNewWithConfig(config); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + YGNodeStyleSetWidth(root, 200); + YGNodeStyleSetHeightAuto(root); + YGNodeStyleSetMinHeight(root, 120); + YGNodeStyleSetMaxHeight(root, 240); + YGNodeStyleSetFlexBasisAuto(root); + YGNodeStyleSetJustifyContent(root, YGJustifyFlexStart); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetAlignContent(root, YGAlignFlexStart); + for (int i = 0; i < 3; i++) { + node = YGNodeNewWithConfig(config); + YGNodeStyleSetWidth(node, 100); + YGNodeStyleSetHeight(node, 100); + YGNodeInsertChild(root, node, i); // index start from 0 + } + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + int nCount = YGNodeGetChildCount(root); + float fAllWidth = YGNodeLayoutGetWidth(root); + float fAllHeight = YGNodeLayoutGetHeight(root); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); + YGNodeFreeRecursive(root); + YGConfigFree(config); +} +TEST(YogaTest, Auto_Width_Min_Width) { + YGNodeRef node = nullptr; + YGNodeRef root = nullptr; + YGConfigRef config = nullptr; + config = YGConfigNew(); + root = YGNodeNewWithConfig(config); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + YGNodeStyleSetWidthAuto(root); + YGNodeStyleSetHeight(root, 200); + YGNodeStyleSetMinWidth(root, 120); + YGNodeStyleSetFlexBasisAuto(root); + YGNodeStyleSetJustifyContent(root, YGJustifyFlexStart); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetAlignContent(root, YGAlignFlexStart); + for (int i = 0; i < 3; i++) { + node = YGNodeNewWithConfig(config); + YGNodeStyleSetWidth(node, 100); + YGNodeStyleSetHeight(node, 100); + YGNodeInsertChild(root, node, i); // index start from 0 + } + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + int nCount = YGNodeGetChildCount(root); + float fAllWidth = YGNodeLayoutGetWidth(root); + float fAllHeight = YGNodeLayoutGetHeight(root); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); + YGNodeFreeRecursive(root); + YGConfigFree(config); +} +TEST(YogaTest, Child_Auto_Width_Min_Width) { + YGNodeRef node = nullptr; + YGNodeRef root = nullptr; + YGConfigRef config = nullptr; + config = YGConfigNew(); + root = YGNodeNewWithConfig(config); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + YGNodeStyleSetWidth(root, 500); + YGNodeStyleSetHeight(root, 500); + YGNodeStyleSetFlexBasisAuto(root); + YGNodeStyleSetJustifyContent(root, YGJustifyFlexStart); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetAlignContent(root, YGAlignFlexStart); + for (int i = 0; i < 2; i++) { + node = YGNodeNewWithConfig(config); + YGNodeStyleSetWidth(node, 100); + YGNodeStyleSetHeight(node, 100); + YGNodeInsertChild(root, node, i); // index start from 0 + } + node = YGNodeNewWithConfig(config); + YGNodeStyleSetWidthAuto(node); + YGNodeStyleSetHeight(node, 200); + YGNodeStyleSetMinWidth(node, 120); + YGNodeInsertChild(root, node, 2); // index start from 0 + YGNodeStyleSetFlexDirection(node, YGFlexDirectionColumn); + YGNodeStyleSetFlexWrap(node, YGWrapWrap); + for (int i = 0; i < 3; i++) { + YGNodeRef node1 = YGNodeNewWithConfig(config); + YGNodeStyleSetWidth(node1, 100); + YGNodeStyleSetHeight(node1, 100); + YGNodeInsertChild(node, node1, i); // index start from 0 + } + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + int nCount = YGNodeGetChildCount(root); + float fValue = YGNodeLayoutGetWidth(root); + float fAllHeight = YGNodeLayoutGetHeight(root); + node = YGNodeGetChild(root, 2); + float fLeft = YGNodeLayoutGetLeft(node); + float fRight = YGNodeLayoutGetTop(node); + float fWidth = YGNodeLayoutGetWidth(node); + float fHeight = YGNodeLayoutGetHeight(node); + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(node)); + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(node)); + YGNodeFreeRecursive(root); + YGConfigFree(config); +} diff --git a/yoga/algorithm/CalculateLayout.cpp b/yoga/algorithm/CalculateLayout.cpp index fe97b4e116..0b6cb74fe4 100644 --- a/yoga/algorithm/CalculateLayout.cpp +++ b/yoga/algorithm/CalculateLayout.cpp @@ -1832,12 +1832,9 @@ static void calculateLayoutImpl( // Clamp to the min/max size specified on the container. flexLine.layout.crossDim = - boundAxis( - node, - crossAxis, + yoga::maxOrDefined( flexLine.layout.crossDim + paddingAndBorderAxisCross, - crossAxisownerSize, - ownerWidth) - + paddingAndBorderForAxis(node, crossAxis, ownerWidth)) - paddingAndBorderAxisCross; // STEP 7: CROSS-AXIS ALIGNMENT From 0fa3d819831f384692f892202e07166046b89ff7 Mon Sep 17 00:00:00 2001 From: catten Date: Tue, 5 Dec 2023 17:45:11 +0800 Subject: [PATCH 2/3] fix gcc test error --- tests/generated/YGMinMaxDimensionTest.cpp | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/tests/generated/YGMinMaxDimensionTest.cpp b/tests/generated/YGMinMaxDimensionTest.cpp index 7a9b591aff..5602034af2 100644 --- a/tests/generated/YGMinMaxDimensionTest.cpp +++ b/tests/generated/YGMinMaxDimensionTest.cpp @@ -1375,9 +1375,6 @@ TEST(YogaTest, Auto_Height_Min_Height) { YGNodeInsertChild(root, node, i); // index start from 0 } YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - int nCount = YGNodeGetChildCount(root); - float fAllWidth = YGNodeLayoutGetWidth(root); - float fAllHeight = YGNodeLayoutGetHeight(root); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root)); @@ -1407,9 +1404,6 @@ TEST(YogaTest, Auto_Width_Min_Width) { YGNodeInsertChild(root, node, i); // index start from 0 } YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - int nCount = YGNodeGetChildCount(root); - float fAllWidth = YGNodeLayoutGetWidth(root); - float fAllHeight = YGNodeLayoutGetHeight(root); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root)); @@ -1451,14 +1445,7 @@ TEST(YogaTest, Child_Auto_Width_Min_Width) { YGNodeInsertChild(node, node1, i); // index start from 0 } YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - int nCount = YGNodeGetChildCount(root); - float fValue = YGNodeLayoutGetWidth(root); - float fAllHeight = YGNodeLayoutGetHeight(root); node = YGNodeGetChild(root, 2); - float fLeft = YGNodeLayoutGetLeft(node); - float fRight = YGNodeLayoutGetTop(node); - float fWidth = YGNodeLayoutGetWidth(node); - float fHeight = YGNodeLayoutGetHeight(node); ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(node)); ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(node)); YGNodeFreeRecursive(root); From b2ffdd577c875b786c5d48490be6ed0c1e0ff723 Mon Sep 17 00:00:00 2001 From: catten Date: Thu, 7 Dec 2023 21:44:55 +0800 Subject: [PATCH 3/3] fix the error that implicit conversion changes signedness: 'int' to 'size_t' --- tests/generated/YGMinMaxDimensionTest.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/generated/YGMinMaxDimensionTest.cpp b/tests/generated/YGMinMaxDimensionTest.cpp index 5602034af2..4ca13ac0fc 100644 --- a/tests/generated/YGMinMaxDimensionTest.cpp +++ b/tests/generated/YGMinMaxDimensionTest.cpp @@ -1368,7 +1368,7 @@ TEST(YogaTest, Auto_Height_Min_Height) { YGNodeStyleSetJustifyContent(root, YGJustifyFlexStart); YGNodeStyleSetAlignItems(root, YGAlignFlexStart); YGNodeStyleSetAlignContent(root, YGAlignFlexStart); - for (int i = 0; i < 3; i++) { + for (size_t i = 0; i < 3; i++) { node = YGNodeNewWithConfig(config); YGNodeStyleSetWidth(node, 100); YGNodeStyleSetHeight(node, 100); @@ -1397,7 +1397,7 @@ TEST(YogaTest, Auto_Width_Min_Width) { YGNodeStyleSetJustifyContent(root, YGJustifyFlexStart); YGNodeStyleSetAlignItems(root, YGAlignFlexStart); YGNodeStyleSetAlignContent(root, YGAlignFlexStart); - for (int i = 0; i < 3; i++) { + for (size_t i = 0; i < 3; i++) { node = YGNodeNewWithConfig(config); YGNodeStyleSetWidth(node, 100); YGNodeStyleSetHeight(node, 100); @@ -1425,7 +1425,7 @@ TEST(YogaTest, Child_Auto_Width_Min_Width) { YGNodeStyleSetJustifyContent(root, YGJustifyFlexStart); YGNodeStyleSetAlignItems(root, YGAlignFlexStart); YGNodeStyleSetAlignContent(root, YGAlignFlexStart); - for (int i = 0; i < 2; i++) { + for (size_t i = 0; i < 2; i++) { node = YGNodeNewWithConfig(config); YGNodeStyleSetWidth(node, 100); YGNodeStyleSetHeight(node, 100); @@ -1438,7 +1438,7 @@ TEST(YogaTest, Child_Auto_Width_Min_Width) { YGNodeInsertChild(root, node, 2); // index start from 0 YGNodeStyleSetFlexDirection(node, YGFlexDirectionColumn); YGNodeStyleSetFlexWrap(node, YGWrapWrap); - for (int i = 0; i < 3; i++) { + for (size_t i = 0; i < 3; i++) { YGNodeRef node1 = YGNodeNewWithConfig(config); YGNodeStyleSetWidth(node1, 100); YGNodeStyleSetHeight(node1, 100);