Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ node_modules

# Visual studio code
!.vscode
.build

*.pdb
*.tlog
Expand Down
12 changes: 9 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@
"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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think all the tests start with this

]
},
{
"name": "Debug C++ Unit tests (vsdbg)",
"type": "cppvsdbg",
"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
]
}
]
}
}
61 changes: 61 additions & 0 deletions tests/YGFlexTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

#include <gtest/gtest.h>
#include <yoga/Yoga.h>

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));
}
18 changes: 15 additions & 3 deletions yoga/algorithm/CalculateLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -2010,8 +2011,10 @@ static void calculateLayoutImpl(
break;
case Align::Stretch:
if (availableInnerCrossDim > totalLineCrossDim) {
crossDimLead =
remainingAlignContentDim / static_cast<float>(lineCount);
if (lineCount > 1) {
crossDimLead =
remainingAlignContentDim / static_cast<float>(lineCount);
}
}
break;
case Align::SpaceAround:
Expand Down Expand Up @@ -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();
}
}
Comment on lines +2214 to +2222
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lower down, we feed lineHeight to boundAxis to do something similar (but it also accounts for padding and border). How does the new logic differ?

node->setLayoutMeasuredDimension(
boundAxis(
node,
Expand Down