paddingStart overrides paddingHorizontal except when paddingStart is 0 #815

Closed
opened 2018-09-24 18:31:58 -07:00 by rigdern · 0 comments
rigdern commented 2018-09-24 18:31:58 -07:00 (Migrated from github.com)

Consider these two examples that set paddingHorizontal and paddingStart:

  1. Style: { paddingHorizontal: 10, paddingStart: 3 }. Computed layout: paddingStart: 3
  2. Style: { paddingHorizontal: 10, paddingStart: 0 }. Computed layout: paddingStart: 10

As you can see, paddingStart overrides paddingHorizontal when paddingStart is 3 but not when it's 0.

It looks like this code is responsible for the special behavior when paddingStart is 0 since it checks paddingEdgeStart.getValue() > 0.0f.

Here's an example C program which illustrates this behavior:

#include <stdio.h>
#include "Yoga.h"

int main(int argc, const char * argv[]) {
    const YGConfigRef config = YGConfigNew();
    
    const YGNodeRef root = YGNodeNewWithConfig(config);
    YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
    
    const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
    YGNodeStyleSetPadding(root_child0, YGEdgeHorizontal, 10);
    YGNodeStyleSetPadding(root_child0, YGEdgeStart, 0 /* also try 3 */);
    YGNodeInsertChild(root, root_child0, 0);
    
    YGNodeCalculateLayout(root, 500, 500, YGDirectionLTR);
    YGNodePrint(root, YGPrintOptionsChildren | YGPrintOptionsStyle | YGPrintOptionsLayout);
    
    YGNodeFreeRecursive(root);
    
    YGConfigFree(config);
    return 0;
}

When running this program with a paddingStart of 0, you'll see that the node's width is 20 (paddingStart + paddingEnd = 10 + 10 = 20). When paddingStart is 3, the node's width is 13 (paddingStart + paddingEnd = 3 + 10 = 13).

It looks like 3a82d2b1a8 (diff-07b4949bf42749fde386e769ff08a124) changed it from >= to > in getLeadingPadding. I suspect it was a mistake. getTrailingPadding still uses >=.

Adam Comella
Microsoft Corp.

Consider these two examples that set `paddingHorizontal` and `paddingStart`: 1. Style: `{ paddingHorizontal: 10, paddingStart: 3 }`. Computed layout: `paddingStart: 3` 2. Style: `{ paddingHorizontal: 10, paddingStart: 0 }`. Computed layout: `paddingStart: 10` As you can see, `paddingStart` overrides `paddingHorizontal` when `paddingStart` is `3` but not when it's `0`. It looks like [this code](https://github.com/facebook/yoga/blob/328ec7dc4d104b42b836d5ccebff04033d045133/yoga/YGNode.cpp#L461) is responsible for the special behavior when `paddingStart` is 0 since it checks `paddingEdgeStart.getValue() > 0.0f`. Here's an example C program which illustrates this behavior: ```c #include <stdio.h> #include "Yoga.h" int main(int argc, const char * argv[]) { const YGConfigRef config = YGConfigNew(); const YGNodeRef root = YGNodeNewWithConfig(config); YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); const YGNodeRef root_child0 = YGNodeNewWithConfig(config); YGNodeStyleSetPadding(root_child0, YGEdgeHorizontal, 10); YGNodeStyleSetPadding(root_child0, YGEdgeStart, 0 /* also try 3 */); YGNodeInsertChild(root, root_child0, 0); YGNodeCalculateLayout(root, 500, 500, YGDirectionLTR); YGNodePrint(root, YGPrintOptionsChildren | YGPrintOptionsStyle | YGPrintOptionsLayout); YGNodeFreeRecursive(root); YGConfigFree(config); return 0; } ``` When running this program with a `paddingStart` of `0`, you'll see that the node's width is `20` (`paddingStart + paddingEnd = 10 + 10 = 20`). When `paddingStart` is `3`, the node's width is `13` (`paddingStart + paddingEnd = 3 + 10 = 13`). It looks like https://github.com/facebook/yoga/commit/3a82d2b1a8f5b65a2c3bd1407552d3ed2226238e?diff=unified&w=1#diff-07b4949bf42749fde386e769ff08a124 changed it from `>=` to `>` in `getLeadingPadding`. I suspect it was a mistake. `getTrailingPadding` still uses `>=`. Adam Comella Microsoft Corp.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DaddyFrosty/yoga#815
No description provided.