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
21 changes: 21 additions & 0 deletions tests/YGAspectRatioTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -896,3 +896,24 @@ TEST(YogaTest, aspect_ratio_should_prefer_flexed_dimension) {

YGNodeFreeRecursive(root);
}

TEST(YogaTest, aspect_ratio_defined_by_cross_stretch_should_not_be_effected_by_margin_on_main_axis) {
const YGConfigRef config = YGConfigNew();
YGConfigSetUseWebDefaults(config, true);

const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root, 200);
YGNodeStyleSetHeight(root, 100);

const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetMargin(root_child0, YGEdgeStart, 50);
YGNodeStyleSetAspectRatio(root_child0, 1);
YGNodeInsertChild(root, root_child0, 0);

YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

ASSERT_EQ(100, YGNodeLayoutGetWidth(root_child0));
ASSERT_EQ(100, YGNodeLayoutGetHeight(root_child0));

YGNodeFreeRecursive(root);
}
10 changes: 10 additions & 0 deletions yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,16 @@ static void YGNodeComputeFlexBasisForChild(
auto marginColumn = YGUnwrapFloatOptional(
child->getMarginForAxis(YGFlexDirectionColumn, ownerWidth));

if (YGNodeAlignItem(node, child) == YGAlignStretch) {
if (isMainAxisRow && !YGFloatIsUndefined(height)) {
childHeight = height;
childHeightMeasureMode = YGMeasureModeExactly;
} else if (!isMainAxisRow && !YGFloatIsUndefined(width)) {
childWidth = width;
childWidthMeasureMode = YGMeasureModeExactly;
}
}

if (isRowStyleDimDefined) {
childWidth =
YGUnwrapFloatOptional(YGResolveValue(
Expand Down