Skip to content

Commit

Permalink
Fixed: Incorrect width of children when using align baseline and chil…
Browse files Browse the repository at this point in the history
…d in row as reference
  • Loading branch information
NextThread committed Sep 9, 2023
1 parent f8e2bc0 commit a288ab3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tests/YGAlignBaselineTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ TEST(YogaTest, align_baseline_parent_using_child_in_row_as_reference) {
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0));

ASSERT_FLOAT_EQ(500, YGNodeLayoutGetLeft(root_child1_child1));
ASSERT_FLOAT_EQ(250, YGNodeLayoutGetLeft(root_child1_child1));
ASSERT_FLOAT_EQ(300, YGNodeLayoutGetTop(root_child1_child1));

YGNodeFreeRecursive(root);
Expand Down
17 changes: 16 additions & 1 deletion yoga/algorithm/CalculateLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2965,6 +2965,7 @@ void calculateLayout(
heightMeasureMode = yoga::isUndefined(height) ? YGMeasureModeUndefined
: YGMeasureModeExactly;
}

if (calculateLayoutInternal(
node,
width,
Expand All @@ -2981,6 +2982,19 @@ void calculateLayout(
layoutContext,
0, // tree root
gCurrentGenerationCount.load(std::memory_order_relaxed))) {

if (node->getLayout().direction() == YGFlexDirectionRow &&
node->getStyle().alignItems() == YGAlignBaseline) {
for (const auto& child : node->getChildren()) {
const YGLayout& childLayout = child->getLayout();
const float childBaseline = childLayout.getLayoutBaseline();
if (childBaseline != YGUndefined) {
node->setLayout(childBaseline);
break;
}
}
}

node->setPosition(
node->getLayout().direction(), ownerWidth, ownerHeight, ownerWidth);
roundLayoutResultsToPixelGrid(
Expand All @@ -2990,7 +3004,8 @@ void calculateLayout(
if (node->getConfig()->shouldPrintTree()) {
YGNodePrint(
node,
(YGPrintOptions) (YGPrintOptionsLayout | YGPrintOptionsChildren | YGPrintOptionsStyle));
(YGPrintOptions) (YGPrintOptionsLayout | YGPrintOptionsChildren |
YGPrintOptionsStyle));
}
#endif
}
Expand Down

0 comments on commit a288ab3

Please sign in to comment.