Skip to content

Commit 1146013

Browse files
woehrl01facebook-github-bot
authored andcommitted
Feature auto margin
Summary: Even so I know there are some opinions against ```margin: 0 auto``` it's still part of the spec: https://www.w3.org/TR/css-flexbox-1/#auto-margins and pretty usefull if you have to position via ```justify-content```. This PR adds an implementation for that. It adds an additonal ```YGUnitAuto``` and margins got ```YGNodeStyleSetMarginAuto``` functions as well. Closes #357 Reviewed By: astreet Differential Revision: D4501142 Pulled By: emilsjolander fbshipit-source-id: 86519f8632496f46e78a7c9dbc5b21e212e3e0c7
1 parent 8a91c0a commit 1146013

File tree

29 files changed

+3353
-56
lines changed

29 files changed

+3353
-56
lines changed

csharp/Facebook.Yoga/Native.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ public static extern void YGNodeSetBaselineFunc(
196196
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
197197
public static extern void YGNodeStyleSetFlexBasisPercent(YGNodeHandle node, float flexBasis);
198198

199+
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
200+
public static extern void YGNodeStyleSetFlexBasisAuto(YGNodeHandle node);
201+
199202
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
200203
public static extern YogaValue YGNodeStyleGetFlexBasis(YGNodeHandle node);
201204

@@ -205,6 +208,9 @@ public static extern void YGNodeSetBaselineFunc(
205208
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
206209
public static extern void YGNodeStyleSetWidthPercent(YGNodeHandle node, float width);
207210

211+
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
212+
public static extern void YGNodeStyleSetWidthAuto(YGNodeHandle node);
213+
208214
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
209215
public static extern YogaValue YGNodeStyleGetWidth(YGNodeHandle node);
210216

@@ -213,6 +219,9 @@ public static extern void YGNodeSetBaselineFunc(
213219

214220
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
215221
public static extern void YGNodeStyleSetHeightPercent(YGNodeHandle node, float height);
222+
223+
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
224+
public static extern void YGNodeStyleSetHeightAuto(YGNodeHandle node);
216225

217226
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
218227
public static extern YogaValue YGNodeStyleGetHeight(YGNodeHandle node);
@@ -278,6 +287,9 @@ public static extern void YGNodeSetBaselineFunc(
278287
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
279288
public static extern void YGNodeStyleSetMarginPercent(YGNodeHandle node, YogaEdge edge, float margin);
280289

290+
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
291+
public static extern void YGNodeStyleSetMarginAuto(YGNodeHandle node, YogaEdge edge);
292+
281293
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
282294
public static extern YogaValue YGNodeStyleGetMargin(YGNodeHandle node, YogaEdge edge);
283295

csharp/Facebook.Yoga/YogaNode.Spacing.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ private void SetStyleMargin(YogaEdge edge, YogaValue value)
226226
{
227227
Native.YGNodeStyleSetMarginPercent(_ygNode, edge, value.Value);
228228
}
229+
else if (value.Unit == YogaUnit.Auto)
230+
{
231+
Native.YGNodeStyleSetMarginAuto(_ygNode, edge);
232+
}
229233
else
230234
{
231235
Native.YGNodeStyleSetMargin(_ygNode, edge, value.Value);

csharp/Facebook.Yoga/YogaNode.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ public YogaValue FlexBasis
270270
{
271271
Native.YGNodeStyleSetFlexBasisPercent(_ygNode, value.Value);
272272
}
273+
else if (value.Unit == YogaUnit.Auto)
274+
{
275+
Native.YGNodeStyleSetFlexBasisAuto(_ygNode);
276+
}
273277
else
274278
{
275279
Native.YGNodeStyleSetFlexBasis(_ygNode, value.Value);
@@ -290,6 +294,10 @@ public YogaValue Width
290294
{
291295
Native.YGNodeStyleSetWidthPercent(_ygNode, value.Value);
292296
}
297+
else if (value.Unit == YogaUnit.Auto)
298+
{
299+
Native.YGNodeStyleSetWidthAuto(_ygNode);
300+
}
293301
else
294302
{
295303
Native.YGNodeStyleSetWidth(_ygNode, value.Value);
@@ -310,6 +318,10 @@ public YogaValue Height
310318
{
311319
Native.YGNodeStyleSetHeightPercent(_ygNode, value.Value);
312320
}
321+
else if (value.Unit == YogaUnit.Auto)
322+
{
323+
Native.YGNodeStyleSetHeightAuto(_ygNode);
324+
}
313325
else
314326
{
315327
Native.YGNodeStyleSetHeight(_ygNode, value.Value);

csharp/Facebook.Yoga/YogaUnit.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ public enum YogaUnit
1414
Undefined,
1515
Pixel,
1616
Percent,
17+
Auto,
1718
}
1819
}

csharp/Facebook.Yoga/YogaValue.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ public static YogaValue Undefined()
7070
};
7171
}
7272

73+
public static YogaValue Auto()
74+
{
75+
return new YogaValue
76+
{
77+
value = 0f,
78+
unit = YogaUnit.Auto
79+
};
80+
}
81+
7382
public static YogaValue Percent(float value)
7483
{
7584
return new YogaValue

0 commit comments

Comments
 (0)