Skip to content
Open
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
24 changes: 24 additions & 0 deletions tests/YGRoundingFunctionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,27 @@ TEST(YogaTest, raw_layout_dimensions) {

YGConfigFree(config);
}

TEST(YogaTest, roundLayoutResultsToPixelGrid_height_rounding_up) {
YGConfigRef config = YGConfigNew();
YGConfigSetPointScaleFactor(config, 3);

YGNodeRef node = YGNodeNewWithConfig(config);
YGNodeStyleSetPositionType(node, YGPositionTypeAbsolute);

// These are values extracted from a debugging session in a real iOS app
YGNodeStyleSetPosition(node, YGEdgeLeft, 38.333333969116211);
YGNodeStyleSetPosition(node, YGEdgeTop, 1970.3333333432674);
YGNodeStyleSetWidth(node, 339.66665649414063);
YGNodeStyleSetHeight(node, 96);
YGNodeSetNodeType(node, YGNodeTypeText);

YGNodeCalculateLayout(node, YGUndefined, YGUndefined, YGDirectionLTR);

// If this value is anything less than 96, iOS will not wrap the text to a 4th line
ASSERT_FLOAT_EQ(YGNodeLayoutGetHeight(node), 96.0f);

YGNodeFreeRecursive(node);

YGConfigFree(config);
}
26 changes: 17 additions & 9 deletions yoga/algorithm/PixelGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,23 @@ void roundLayoutResultsToPixelGrid(
roundValueToPixelGrid(
absoluteNodeLeft, pointScaleFactor, false, textRounding));

node->getLayout().setDimension(
Dimension::Height,
roundValueToPixelGrid(
absoluteNodeBottom,
pointScaleFactor,
(textRounding && hasFractionalHeight),
(textRounding && !hasFractionalHeight)) -
roundValueToPixelGrid(
absoluteNodeTop, pointScaleFactor, false, textRounding));
// -- Height --
const float roundedBottom = roundValueToPixelGrid(
absoluteNodeBottom,
pointScaleFactor,
(textRounding && hasFractionalHeight),
(textRounding && !hasFractionalHeight));
const float roundedTop = roundValueToPixelGrid(
absoluteNodeTop, pointScaleFactor, false, textRounding);

const float roundedHeight = roundValueToPixelGrid(
roundedBottom - roundedTop,
pointScaleFactor,
false, // Don't force ceil for height calculation
false // Don't force floor for height calculation
);

node->getLayout().setDimension(Dimension::Height, roundedHeight);
}

for (yoga::Node* child : node->getChildren()) {
Expand Down