diff --git a/.gitignore b/.gitignore index 7d75c154c7..d6e57ce82f 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ node_modules # Visual studio code !.vscode +.build *.pdb *.tlog diff --git a/.vscode/launch.json b/.vscode/launch.json index db839dd557..d4c4a9abbf 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,7 +11,10 @@ "request": "launch", "program": "${workspaceFolder}/tests/build/yogatests", "cwd": "${workspaceFolder}", - "preLaunchTask": "Build Unit Tests" + "preLaunchTask": "Build Unit Tests", + "args": [ + "--gtest_filter=YogaTest.*" // Replace * with the name of your test case + ] }, { "name": "Debug C++ Unit tests (vsdbg)", @@ -19,7 +22,10 @@ "request": "launch", "program": "${workspaceFolder}/tests/build/yogatests", "cwd": "${workspaceFolder}", - "preLaunchTask": "Build Unit Tests" + "preLaunchTask": "Build Unit Tests", + "args": [ + "--gtest_filter=YogaTest.*" // Replace * with the name of your test case + ] } ] -} +} \ No newline at end of file diff --git a/tests/YGFlexTest.cpp b/tests/YGFlexTest.cpp new file mode 100644 index 0000000000..5217b60b40 --- /dev/null +++ b/tests/YGFlexTest.cpp @@ -0,0 +1,61 @@ + +#include +#include + +TEST(YogaTest, flex_min_height_children_wrap) { + const YGConfigRef config = YGConfigNew(); + const YGNodeRef root = YGNodeNewWithConfig(config); + + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + + YGNodeStyleSetWidth(root, 200); + YGNodeStyleSetHeightAuto(root); + YGNodeStyleSetMinHeight(root, 200); + YGNodeStyleSetFlexBasisAuto(root); + + YGNodeStyleSetJustifyContent(root, YGJustifyFlexStart); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetAlignContent(root, YGAlignFlexStart); + + for (size_t i = 0; i < 2; i++) { + YGNodeRef node = YGNodeNewWithConfig(config); + YGNodeStyleSetWidth(node, 120); + YGNodeStyleSetHeight(node, 120); + + YGNodeInsertChild(root, node, i); // index start from 0 + } + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(240, YGNodeLayoutGetHeight(root)); +} + +TEST(YogaTest, flex_min_width_children_wrap) { + const YGConfigRef config = YGConfigNew(); + const YGNodeRef root = YGNodeNewWithConfig(config); + + YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + + YGNodeStyleSetMinWidth(root, 200); + YGNodeStyleSetHeightAuto(root); + YGNodeStyleSetHeight(root, 200); + YGNodeStyleSetFlexBasisAuto(root); + + YGNodeStyleSetJustifyContent(root, YGJustifyFlexStart); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetAlignContent(root, YGAlignFlexStart); + + for (size_t i = 0; i < 2; i++) { + YGNodeRef node = YGNodeNewWithConfig(config); + YGNodeStyleSetWidth(node, 120); + YGNodeStyleSetHeight(node, 120); + + YGNodeInsertChild(root, node, i); // index start from 0 + } + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); + ASSERT_FLOAT_EQ(240, YGNodeLayoutGetWidth(root)); +} \ No newline at end of file diff --git a/yoga/algorithm/CalculateLayout.cpp b/yoga/algorithm/CalculateLayout.cpp index fe97b4e116..973441ee4c 100644 --- a/yoga/algorithm/CalculateLayout.cpp +++ b/yoga/algorithm/CalculateLayout.cpp @@ -1995,6 +1995,7 @@ static void calculateLayoutImpl( // STEP 8: MULTI-LINE CONTENT ALIGNMENT // currentLead stores the size of the cross dim + float totalLineHeight = 0; if (performLayout && (isNodeFlexWrap || isBaselineLayout(node))) { float crossDimLead = 0; float currentLead = leadingPaddingAndBorderCross; @@ -2010,8 +2011,10 @@ static void calculateLayoutImpl( break; case Align::Stretch: if (availableInnerCrossDim > totalLineCrossDim) { - crossDimLead = - remainingAlignContentDim / static_cast(lineCount); + if (lineCount > 1) { + crossDimLead = + remainingAlignContentDim / static_cast(lineCount); + } } break; case Align::SpaceAround: @@ -2203,11 +2206,20 @@ static void calculateLayoutImpl( } } currentLead += lineHeight; + totalLineHeight += lineHeight; } } // STEP 9: COMPUTING FINAL DIMENSIONS - + const FloatOptional minLineHeight = yoga::resolveValue( + node->getStyle().minDimension(dimension(crossAxis)), crossAxisownerSize); + if (minLineHeight.isDefined()) { + if (totalLineHeight > minLineHeight.unwrap()) { + totalLineCrossDim = totalLineHeight; + } else { + totalLineCrossDim = minLineHeight.unwrap(); + } + } node->setLayoutMeasuredDimension( boundAxis( node,