diff --git a/tests/YGAspectRatioTest.cpp b/tests/YGAspectRatioTest.cpp index 22846c9b..8b28abdb 100644 --- a/tests/YGAspectRatioTest.cpp +++ b/tests/YGAspectRatioTest.cpp @@ -351,7 +351,7 @@ TEST(YogaTest, aspect_ratio_double_main) { const YGNodeRef root_child0 = YGNodeNew(); YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetAspectRatio(root_child0, 2); + YGNodeStyleSetAspectRatio(root_child0, 0.5); YGNodeInsertChild(root, root_child0, 0); YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); @@ -372,7 +372,7 @@ TEST(YogaTest, aspect_ratio_half_main) { const YGNodeRef root_child0 = YGNodeNew(); YGNodeStyleSetWidth(root_child0, 100); - YGNodeStyleSetAspectRatio(root_child0, 0.5); + YGNodeStyleSetAspectRatio(root_child0, 2); YGNodeInsertChild(root, root_child0, 0); YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); diff --git a/yoga/Yoga.c b/yoga/Yoga.c index 4762cee4..8b1c5fda 100644 --- a/yoga/Yoga.c +++ b/yoga/Yoga.c @@ -1062,7 +1062,7 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node, if (!YGValueIsUndefined(child->style.aspectRatio)) { if (!isMainAxisRow && childWidthMeasureMode == YGMeasureModeExactly) { child->layout.computedFlexBasis = - fmaxf(childWidth * child->style.aspectRatio, + fmaxf(childWidth / child->style.aspectRatio, YGNodePaddingAndBorderForAxis(child, YGFlexDirectionColumn)); return; } else if (isMainAxisRow && childHeightMeasureMode == YGMeasureModeExactly) { @@ -1157,7 +1157,7 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node, childWidth = fmaxf(childHeight * child->style.aspectRatio, YGNodePaddingAndBorderForAxis(child, YGFlexDirectionColumn)); } else if (YGValueIsUndefined(childHeight)) { - childHeight = fmaxf(childWidth * child->style.aspectRatio, + childHeight = fmaxf(childWidth / child->style.aspectRatio, YGNodePaddingAndBorderForAxis(child, YGFlexDirectionRow)); } } @@ -1880,7 +1880,7 @@ static void YGNodelayoutImpl(const YGNodeRef node, if (!YGValueIsUndefined(currentRelativeChild->style.aspectRatio)) { if (isMainAxisRow && childHeightMeasureMode != YGMeasureModeExactly) { childHeight = - fmaxf(childWidth * currentRelativeChild->style.aspectRatio, + fmaxf(childWidth / currentRelativeChild->style.aspectRatio, YGNodePaddingAndBorderForAxis(currentRelativeChild, YGFlexDirectionColumn)); childHeightMeasureMode = YGMeasureModeExactly; } else if (!isMainAxisRow && childWidthMeasureMode != YGMeasureModeExactly) { diff --git a/yoga/Yoga.h b/yoga/Yoga.h index 3bb96727..5e10b503 100644 --- a/yoga/Yoga.h +++ b/yoga/Yoga.h @@ -151,6 +151,9 @@ YG_NODE_STYLE_PROPERTY(float, MaxHeight, maxHeight); // Yoga specific properties, not compatible with flexbox specification // Aspect ratio control the size of the undefined dimension of a node. +// Aspect ratio is encoded as a floating point value width/height. e.g. A value of 2 leads to a node +// with a width twice the size of its height while a value of 0.5 gives the opposite effect. +// // - On a node with a set width/height aspect ratio control the size of the unset dimension // - On a node with a set flex basis aspect ratio controls the size of the node in the cross axis if // unset