Skip to content

Commit a2f8703

Browse files
committed
support yoga 3.1.0 percent gaps
1 parent 5efa27f commit a2f8703

File tree

5 files changed

+28
-14
lines changed

5 files changed

+28
-14
lines changed

Runtime/Frameworks/UGUI/Components/UGUIComponent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ protected void ApplyYogaValues()
222222
Layout.Top = StylingHelpers.GetStyleLength(computed, LayoutProperties.Top);
223223
Layout.Bottom = StylingHelpers.GetStyleLength(computed, LayoutProperties.Bottom);
224224

225-
Layout.RowGap = StylingHelpers.GetStyleFloat(computed, LayoutProperties.RowGap);
226-
Layout.ColumnGap = StylingHelpers.GetStyleFloat(computed, LayoutProperties.ColumnGap);
225+
Layout.RowGap = StylingHelpers.GetStyleLength(computed, LayoutProperties.RowGap);
226+
Layout.ColumnGap = StylingHelpers.GetStyleLength(computed, LayoutProperties.ColumnGap);
227227

228228
Layout.BorderLeftWidth = StylingHelpers.GetStyleFloatDouble(computed, LayoutProperties.BorderLeftWidth, LayoutProperties.BorderWidth);
229229
Layout.BorderRightWidth = StylingHelpers.GetStyleFloatDouble(computed, LayoutProperties.BorderRightWidth, LayoutProperties.BorderWidth);

Runtime/Styling/Properties/LayoutProperties.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public static class LayoutProperties
5959
public static readonly LayoutProperty<float> BorderEndWidth = new LayoutProperty<float>("BorderEndWidth", true, converter: AllConverters.LengthConverter);
6060
public static readonly LayoutProperty<int> Order = new LayoutProperty<int>("order", true);
6161

62-
public static readonly LayoutProperty<float> RowGap = new LayoutProperty<float>("RowGap", true, 0f, converter: AllConverters.LengthConverter);
63-
public static readonly LayoutProperty<float> ColumnGap = new LayoutProperty<float>("ColumnGap", true, 0f, converter: AllConverters.LengthConverter);
62+
public static readonly LayoutProperty<YogaValue> RowGap = new LayoutProperty<YogaValue>("RowGap", true);
63+
public static readonly LayoutProperty<YogaValue> ColumnGap = new LayoutProperty<YogaValue>("ColumnGap", true);
6464

6565
public static Dictionary<string, ILayoutProperty> PropertyMap = new Dictionary<string, ILayoutProperty>(StringComparer.InvariantCultureIgnoreCase)
6666
{

Runtime/Styling/Shorthands/AllShorthands.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using Yoga;
34

45
namespace ReactUnity.Styling.Shorthands
56
{
@@ -35,7 +36,8 @@ internal static class AllShorthands
3536
internal static readonly StyleShorthand Animation = new AnimationShorthand("animation");
3637
internal static readonly StyleShorthand Audio = new AudioShorthand("audio");
3738
internal static readonly StyleShorthand Transform = new TransformShorthand("transform");
38-
internal static readonly StyleShorthand Gap = new XYShorthand<float>("gap", LayoutProperties.RowGap, LayoutProperties.ColumnGap);
39+
internal static readonly StyleShorthand Gap = new XYShorthand<YogaValue>("gap", LayoutProperties.RowGap, LayoutProperties.ColumnGap);
40+
3941
internal static readonly Dictionary<string, StyleShorthand> Map = new Dictionary<string, StyleShorthand>(StringComparer.InvariantCultureIgnoreCase)
4042
{
4143
{ "all", All },

Runtime/Yoga/Native.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ internal static class Native
317317
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
318318
public static extern void YGNodeStyleSetGap(YGNodeHandle node, YogaGutter gutter, float gapLength);
319319

320+
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
321+
public static extern void YGNodeStyleSetGapPercent(YGNodeHandle node, YogaGutter gutter, float percent);
322+
320323
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
321324
public static extern float YGNodeStyleGetGap(YGNodeHandle node, YogaGutter gutter);
322325

Runtime/Yoga/YogaNode.cs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -296,22 +296,31 @@ public float AspectRatio
296296
}
297297
}
298298

299-
public float Gap
299+
public YogaValue Gap
300300
{
301-
get => Native.YGNodeStyleGetGap(_ygNode, YogaGutter.All);
302-
set => Native.YGNodeStyleSetGap(_ygNode, YogaGutter.All, value);
301+
set
302+
{
303+
if (value.Unit == YogaUnit.Percent) Native.YGNodeStyleSetGapPercent(_ygNode, YogaGutter.All, value.Value);
304+
else Native.YGNodeStyleSetGap(_ygNode, YogaGutter.All, value.Value);
305+
}
303306
}
304307

305-
public float ColumnGap
308+
public YogaValue ColumnGap
306309
{
307-
get => Native.YGNodeStyleGetGap(_ygNode, YogaGutter.Column);
308-
set => Native.YGNodeStyleSetGap(_ygNode, YogaGutter.Column, value);
310+
set
311+
{
312+
if (value.Unit == YogaUnit.Percent) Native.YGNodeStyleSetGapPercent(_ygNode, YogaGutter.Column, value.Value);
313+
else Native.YGNodeStyleSetGap(_ygNode, YogaGutter.Column, value.Value);
314+
}
309315
}
310316

311-
public float RowGap
317+
public YogaValue RowGap
312318
{
313-
get => Native.YGNodeStyleGetGap(_ygNode, YogaGutter.Row);
314-
set => Native.YGNodeStyleSetGap(_ygNode, YogaGutter.Row, value);
319+
set
320+
{
321+
if (value.Unit == YogaUnit.Percent) Native.YGNodeStyleSetGapPercent(_ygNode, YogaGutter.Row, value.Value);
322+
else Native.YGNodeStyleSetGap(_ygNode, YogaGutter.Row, value.Value);
323+
}
315324
}
316325

317326
public float LayoutLeft => Native.YGNodeLayoutGetLeft(_ygNode);

0 commit comments

Comments
 (0)