@@ -3297,9 +3297,20 @@ void YGConfigSetPointScaleFactor(const YGConfigRef config, const float pixelsInP
32973297 }
32983298}
32993299
3300- static float YGRoundValueToPixelGrid (const float value , const float pointScaleFactor ) {
3300+ static float YGRoundValueToPixelGrid (const float value , const float pointScaleFactor , const bool forceCeil , const bool forceFloor ) {
33013301 float fractial = fmodf (value , pointScaleFactor );
3302- return value - fractial + (fractial >= pointScaleFactor / 2.0f ? pointScaleFactor : 0 );
3302+ if (YGFloatsEqual (fractial , 0 )) {
3303+ // Still remove fractial as fractial could be extremely small.
3304+ return value - fractial ;
3305+ }
3306+
3307+ if (forceCeil ) {
3308+ return value - fractial + pointScaleFactor ;
3309+ } else if (forceFloor ) {
3310+ return value - fractial ;
3311+ } else {
3312+ return value - fractial + (fractial >= pointScaleFactor / 2.0f ? pointScaleFactor : 0 );
3313+ }
33033314}
33043315
33053316static void YGRoundToPixelGrid (const YGNodeRef node , const float pointScaleFactor , const float absoluteLeft , const float absoluteTop ) {
@@ -3319,13 +3330,17 @@ static void YGRoundToPixelGrid(const YGNodeRef node, const float pointScaleFacto
33193330 const float absoluteNodeRight = absoluteNodeLeft + nodeWidth ;
33203331 const float absoluteNodeBottom = absoluteNodeTop + nodeHeight ;
33213332
3322- node -> layout .position [YGEdgeLeft ] = YGRoundValueToPixelGrid (nodeLeft , pointScaleFactor );
3323- node -> layout .position [YGEdgeTop ] = YGRoundValueToPixelGrid (nodeTop , pointScaleFactor );
3333+ // If a node has a custom measure function we never want to round down its size as this could
3334+ // lead to unwanted text truncation.
3335+ const bool hasMeasure = node -> measure != NULL ;
3336+
3337+ node -> layout .position [YGEdgeLeft ] = YGRoundValueToPixelGrid (nodeLeft , pointScaleFactor , false, hasMeasure );
3338+ node -> layout .position [YGEdgeTop ] = YGRoundValueToPixelGrid (nodeTop , pointScaleFactor , false, hasMeasure );
33243339
33253340 node -> layout .dimensions [YGDimensionWidth ] =
3326- YGRoundValueToPixelGrid (absoluteNodeRight , pointScaleFactor ) - YGRoundValueToPixelGrid (absoluteNodeLeft , pointScaleFactor );
3341+ YGRoundValueToPixelGrid (absoluteNodeRight , pointScaleFactor , hasMeasure , false ) - YGRoundValueToPixelGrid (absoluteNodeLeft , pointScaleFactor , false, hasMeasure );
33273342 node -> layout .dimensions [YGDimensionHeight ] =
3328- YGRoundValueToPixelGrid (absoluteNodeBottom , pointScaleFactor ) - YGRoundValueToPixelGrid (absoluteNodeTop , pointScaleFactor );
3343+ YGRoundValueToPixelGrid (absoluteNodeBottom , pointScaleFactor , hasMeasure , false ) - YGRoundValueToPixelGrid (absoluteNodeTop , pointScaleFactor , false, hasMeasure );
33293344
33303345 const uint32_t childCount = YGNodeListCount (node -> children );
33313346 for (uint32_t i = 0 ; i < childCount ; i ++ ) {
0 commit comments