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
20 changes: 20 additions & 0 deletions tests/YGRoundingFunctionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,23 @@ TEST(YogaTest, per_node_point_scale_factor) {
YGConfigFree(config2);
YGConfigFree(config3);
}

TEST(YogaTest, raw_layout_dimensions) {
YGConfigRef config = YGConfigNew();
YGConfigSetPointScaleFactor(config, 0.5f);

YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root, 11.5f);
YGNodeStyleSetHeight(root, 9.5f);

YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

ASSERT_EQ(YGNodeLayoutGetWidth(root), 12.0f);
ASSERT_EQ(YGNodeLayoutGetHeight(root), 10.0f);
ASSERT_EQ(YGNodeLayoutGetRawWidth(root), 11.5f);
ASSERT_EQ(YGNodeLayoutGetRawHeight(root), 9.5f);

YGNodeFreeRecursive(root);

YGConfigFree(config);
}
8 changes: 8 additions & 0 deletions yoga/YGNodeLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,11 @@ float YGNodeLayoutGetPadding(YGNodeConstRef node, YGEdge edge) {
return getResolvedLayoutProperty<&LayoutResults::padding>(
node, scopedEnum(edge));
}

float YGNodeLayoutGetRawHeight(YGNodeConstRef node) {
return resolveRef(node)->getLayout().rawDimension(Dimension::Height);
}

float YGNodeLayoutGetRawWidth(YGNodeConstRef node) {
return resolveRef(node)->getLayout().rawDimension(Dimension::Width);
}
10 changes: 10 additions & 0 deletions yoga/YGNodeLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,14 @@ YG_EXPORT float YGNodeLayoutGetMargin(YGNodeConstRef node, YGEdge edge);
YG_EXPORT float YGNodeLayoutGetBorder(YGNodeConstRef node, YGEdge edge);
YG_EXPORT float YGNodeLayoutGetPadding(YGNodeConstRef node, YGEdge edge);

/**
* Return the measured height of the node, before layout rounding
*/
YG_EXPORT float YGNodeLayoutGetRawHeight(YGNodeConstRef node);

/**
* Return the measured width of the node, before layout rounding
*/
YG_EXPORT float YGNodeLayoutGetRawWidth(YGNodeConstRef node);

YG_EXTERN_C_END
12 changes: 6 additions & 6 deletions yoga/algorithm/PixelGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,25 +106,25 @@ void roundLayoutResultsToPixelGrid(
const bool hasFractionalHeight =
!yoga::inexactEquals(round(scaledNodeHeight), scaledNodeHeight);

node->setLayoutDimension(
node->getLayout().setDimension(
Dimension::Width,
roundValueToPixelGrid(
absoluteNodeRight,
pointScaleFactor,
(textRounding && hasFractionalWidth),
(textRounding && !hasFractionalWidth)) -
roundValueToPixelGrid(
absoluteNodeLeft, pointScaleFactor, false, textRounding),
Dimension::Width);
absoluteNodeLeft, pointScaleFactor, false, textRounding));

node->setLayoutDimension(
node->getLayout().setDimension(
Dimension::Height,
roundValueToPixelGrid(
absoluteNodeBottom,
pointScaleFactor,
(textRounding && hasFractionalHeight),
(textRounding && !hasFractionalHeight)) -
roundValueToPixelGrid(
absoluteNodeTop, pointScaleFactor, false, textRounding),
Dimension::Height);
absoluteNodeTop, pointScaleFactor, false, textRounding));
}

for (yoga::Node* child : node->getChildren()) {
Expand Down
9 changes: 9 additions & 0 deletions yoga/node/LayoutResults.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,18 @@ struct LayoutResults {
return measuredDimensions_[yoga::to_underlying(axis)];
}

float rawDimension(Dimension axis) const {
return rawDimensions_[yoga::to_underlying(axis)];
}

void setMeasuredDimension(Dimension axis, float dimension) {
measuredDimensions_[yoga::to_underlying(axis)] = dimension;
}

void setRawDimension(Dimension axis, float dimension) {
rawDimensions_[yoga::to_underlying(axis)] = dimension;
}

float position(PhysicalEdge physicalEdge) const {
return position_[yoga::to_underlying(physicalEdge)];
}
Expand Down Expand Up @@ -113,6 +121,7 @@ struct LayoutResults {

std::array<float, 2> dimensions_ = {{YGUndefined, YGUndefined}};
std::array<float, 2> measuredDimensions_ = {{YGUndefined, YGUndefined}};
std::array<float, 2> rawDimensions_ = {{YGUndefined, YGUndefined}};
std::array<float, 4> position_ = {};
std::array<float, 4> margin_ = {};
std::array<float, 4> border_ = {};
Expand Down
1 change: 1 addition & 0 deletions yoga/node/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ void Node::setLayoutHadOverflow(bool hadOverflow) {

void Node::setLayoutDimension(float lengthValue, Dimension dimension) {
layout_.setDimension(dimension, lengthValue);
layout_.setRawDimension(dimension, lengthValue);
}

// If both left and right are defined, then use left. Otherwise return +left or
Expand Down
Loading