Added feature to use rounded values

Summary:
Added an experimental feature to allow to use only rounded values. See #184. It's not a perfect solution and definitely  can be further improved. I'm looking forward to your ideas.
Closes https://github.com/facebook/css-layout/pull/256

Reviewed By: splhack

Differential Revision: D4214168

Pulled By: emilsjolander

fbshipit-source-id: 6293352d479b7b4dad258eb3f9e0afaa11cf7236
This commit is contained in:
Lukas Woehrl
2016-11-22 05:33:36 -08:00
committed by Facebook Github Bot
parent d54f09e32b
commit b90f6e21bd
7 changed files with 890 additions and 6 deletions

View File

@@ -2534,6 +2534,25 @@ bool layoutNodeInternal(const CSSNodeRef node,
return (needToVisitNode || cachedResults == NULL);
}
static void roundToPixelGrid(const CSSNodeRef node) {
const float fractialLeft =
node->layout.position[CSSEdgeLeft] - floorf(node->layout.position[CSSEdgeLeft]);
const float fractialTop =
node->layout.position[CSSEdgeTop] - floorf(node->layout.position[CSSEdgeTop]);
node->layout.dimensions[CSSDimensionWidth] =
roundf(fractialLeft + node->layout.dimensions[CSSDimensionWidth]) - roundf(fractialLeft);
node->layout.dimensions[CSSDimensionHeight] =
roundf(fractialTop + node->layout.dimensions[CSSDimensionHeight]) - roundf(fractialTop);
node->layout.position[CSSEdgeLeft] = roundf(node->layout.position[CSSEdgeLeft]);
node->layout.position[CSSEdgeTop] = roundf(node->layout.position[CSSEdgeTop]);
const uint32_t childCount = CSSNodeListCount(node->children);
for (uint32_t i = 0; i < childCount; i++) {
roundToPixelGrid(CSSNodeGetChild(node, i));
}
}
void CSSNodeCalculateLayout(const CSSNodeRef node,
const float availableWidth,
const float availableHeight,
@@ -2583,6 +2602,10 @@ void CSSNodeCalculateLayout(const CSSNodeRef node,
"l")) {
setPosition(node, node->layout.direction);
if (CSSLayoutIsExperimentalFeatureEnabled(CSSExperimentalFeatureRounding)) {
roundToPixelGrid(node);
}
if (gPrintTree) {
CSSNodePrint(node, CSSPrintOptionsLayout | CSSPrintOptionsChildren | CSSPrintOptionsStyle);
}
@@ -2606,7 +2629,7 @@ void CSSLayoutSetExperimentalFeatureEnabled(CSSExperimentalFeature feature, bool
experimentalFeatures[feature] = enabled;
}
bool CSSLayoutIsExperimentalFeatureEnabled(CSSExperimentalFeature feature) {
inline bool CSSLayoutIsExperimentalFeatureEnabled(CSSExperimentalFeature feature) {
return experimentalFeatures[feature];
}