-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Padding style #5
Comments
This seems correct to me. Flex layout calculates positions and sizes (width/height/top/left) from input style (padding etc.) Your specified padding of 20 in each direction for all children which is reflected in their top/left positions given row layout. |
This is just a port of https://github.com/facebook/yoga If you have questions about the API and expected results, reach out to them. |
Thank you for your time. |
Here is the C code: YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 500);
YGNodeStyleSetHeight(root, 120);
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
YGNodeStyleSetPadding(root, YGEdgeAll, 20);
YGNodeRef image = YGNodeNew();
YGNodeStyleSetWidth(image, 80);
YGNodeStyleSetMargin(image, YGEdgeEnd, 20);
YGNodeRef text = YGNodeNew();
YGNodeStyleSetHeight(text, 25);
YGNodeStyleSetAlignSelf(text, YGAlignCenter);
YGNodeStyleSetFlexGrow(text, 1);
YGNodeInsertChild(root, image, 0);
YGNodeInsertChild(root, text, 1); Here is output (as presented on website): <div class="yoga sample" style="background-color: white; width: 500px; height: 120px; padding: 20px; flex-direction:row;">
<div class="yoga" style="background-color: #97dccf; width: 80px; margin-right: 20px;"></div>
<div class="yoga" style="background-color: #303846; flex-grow: 1; height: 25px; align-self: center;"></div>
</div> Here is Go code: root := flex.NewNodeWithConfig(config)
root.StyleSetWidth(500)
root.StyleSetHeight(120)
root.StyleSetFlexDirection(flex.FlexDirectionRow)
root.StyleSetPadding(flex.EdgeAll, 20)
image := flex.NewNodeWithConfig(config)
image.StyleSetWidth(80)
image.StyleSetMargin(flex.EdgeEnd, 20)
text := flex.NewNodeWithConfig(config)
text.StyleSetHeight(25)
text.StyleSetAlignSelf(flex.AlignCenter)
text.StyleSetFlexGrow(1)
root.InsertChild(image, 0)
root.InsertChild(text, 1) Here is output: <div layout="width: 500; height: 120; top: 0; left: 0;" style="flex-direction: row; width: 500px; height: 120px; ">
<div layout="width: 80; height: 80; top: 20; left: 20;" style="width: 80px; "></div>
<div layout="width: 360; height: 25; top: 48; left: 120;" style="align-self: center; flex-grow: 1; height: 25px; "></div>
</div> Again, no paddings nor margins in Go-produced layout. I am not trying to waste your time. I don't know yoga enough but it seems invalid to me, at least from what I see in the docs and results. |
The important thing is that calculated layout values (width/height/top/left) match and they do in both printouts. Node printing is only to help debugging issues. Go node printing is supposed to match C code (https://github.com/facebook/yoga/blob/master/yoga/Yoga.c#L1048). The output you show does not come from C code (C code doesn't print "class" attribute anywhere or "background-color"). Both C and Go code would omit styles that are the same as flex defaults. Missing "padding" does look like a bug but C code seems to have the same bug for EdgeAll, so it's a low priority to fix. |
Thank you for your explanation. |
Hey @kjk please let me know if I understand it correctly:
Is
padding
a CSS padding attribute? When I use:I thought I'd receive
padding: 20px
, here is the output:Let me know if I understand it correctly or I misused it, thanks.
complete source
The text was updated successfully, but these errors were encountered: