Forwards the fractialLeft/Top to the children
This commit is contained in:
60
yoga/Yoga.c
60
yoga/Yoga.c
@@ -3283,49 +3283,41 @@ void YGConfigSetPointScaleFactor(const YGConfigRef config, const float pixelsInP
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void YGRoundToPixelGrid(const YGNodeRef node, const float pointScaleFactor) {
|
static void YGRoundToPixelGrid(const YGNodeRef node, const float pointScaleFactor, const float parentNodeLeft, const float parentNodeTop, const float parentRoundedLeft, const float parentRoundedTop) {
|
||||||
if (pointScaleFactor == 0.0f) {
|
if (pointScaleFactor == 0.0f) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const float nodeLeft = node->layout.position[YGEdgeLeft];
|
|
||||||
const float nodeTop = node->layout.position[YGEdgeTop];
|
|
||||||
|
|
||||||
// To round correctly to the pixel grid, first we calculate left and top coordinates
|
const float nodeLeft = parentNodeLeft + node->layout.position[YGEdgeLeft];
|
||||||
float fractialLeft = fmodf(nodeLeft, pointScaleFactor);
|
const float nodeTop = parentNodeTop + node->layout.position[YGEdgeTop];
|
||||||
float fractialTop = fmodf(nodeTop, pointScaleFactor);
|
|
||||||
float roundedLeft = nodeLeft - fractialLeft;
|
|
||||||
float roundedTop = nodeTop - fractialTop;
|
|
||||||
|
|
||||||
// To do the actual rounding we check if leftover fraction is bigger or equal than half of the grid step
|
const float nodeRight = nodeLeft + node->layout.dimensions[YGDimensionWidth];
|
||||||
if (fractialLeft >= pointScaleFactor / 2.0f) {
|
const float nodeBottom = nodeTop + node->layout.dimensions[YGDimensionHeight];
|
||||||
roundedLeft += pointScaleFactor;
|
|
||||||
fractialLeft -= pointScaleFactor;
|
|
||||||
}
|
|
||||||
if (fractialTop >= pointScaleFactor / 2.0f) {
|
|
||||||
roundedTop += pointScaleFactor;
|
|
||||||
fractialTop -= pointScaleFactor;
|
|
||||||
}
|
|
||||||
node->layout.position[YGEdgeLeft] = roundedLeft;
|
|
||||||
node->layout.position[YGEdgeTop] = roundedTop;
|
|
||||||
|
|
||||||
// Now we round width and height in the same way accounting for fractial leftovers from rounding position
|
#define YG_FRACTIAL(Name) float rounded##Name = 0.0; { \
|
||||||
const float adjustedWidth = fractialLeft + node->layout.dimensions[YGDimensionWidth];
|
float fractial = fmodf(node##Name, pointScaleFactor); \
|
||||||
const float adjustedHeight = fractialTop + node->layout.dimensions[YGDimensionHeight];
|
rounded##Name = node##Name - fractial; \
|
||||||
float roundedWidth = adjustedWidth - fmodf(adjustedWidth, pointScaleFactor);
|
\
|
||||||
float roundedHeight = adjustedHeight - fmodf(adjustedHeight, pointScaleFactor);
|
if (fractial >= pointScaleFactor / 2.0f) { \
|
||||||
|
rounded##Name += pointScaleFactor; \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
if (adjustedWidth - roundedWidth >= pointScaleFactor / 2.0f) {
|
YG_FRACTIAL(Left);
|
||||||
roundedWidth += pointScaleFactor;
|
YG_FRACTIAL(Top);
|
||||||
}
|
|
||||||
if (adjustedHeight - roundedHeight >= pointScaleFactor / 2.0f) {
|
YG_FRACTIAL(Right);
|
||||||
roundedHeight += pointScaleFactor;
|
YG_FRACTIAL(Bottom);
|
||||||
}
|
|
||||||
node->layout.dimensions[YGDimensionWidth] = roundedWidth;
|
node->layout.position[YGEdgeLeft] = roundedLeft - parentRoundedLeft;
|
||||||
node->layout.dimensions[YGDimensionHeight] = roundedHeight;
|
node->layout.position[YGEdgeTop] = roundedTop - parentRoundedTop;
|
||||||
|
|
||||||
|
node->layout.dimensions[YGDimensionWidth] = roundedRight - roundedLeft;
|
||||||
|
node->layout.dimensions[YGDimensionHeight] = roundedBottom - roundedTop;
|
||||||
|
|
||||||
const uint32_t childCount = YGNodeListCount(node->children);
|
const uint32_t childCount = YGNodeListCount(node->children);
|
||||||
for (uint32_t i = 0; i < childCount; i++) {
|
for (uint32_t i = 0; i < childCount; i++) {
|
||||||
YGRoundToPixelGrid(YGNodeGetChild(node, i), pointScaleFactor);
|
YGRoundToPixelGrid(YGNodeGetChild(node, i), pointScaleFactor, nodeLeft, nodeTop, roundedLeft, roundedTop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3385,7 +3377,7 @@ void YGNodeCalculateLayout(const YGNodeRef node,
|
|||||||
YGNodeSetPosition(node, node->layout.direction, parentWidth, parentHeight, parentWidth);
|
YGNodeSetPosition(node, node->layout.direction, parentWidth, parentHeight, parentWidth);
|
||||||
|
|
||||||
if (YGConfigIsExperimentalFeatureEnabled(node->config, YGExperimentalFeatureRounding)) {
|
if (YGConfigIsExperimentalFeatureEnabled(node->config, YGExperimentalFeatureRounding)) {
|
||||||
YGRoundToPixelGrid(node, node->config->pointScaleFactor);
|
YGRoundToPixelGrid(node, node->config->pointScaleFactor, 0.0, 0.0, 0.0, 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gPrintTree) {
|
if (gPrintTree) {
|
||||||
|
Reference in New Issue
Block a user