Skip to content

Commit

Permalink
support yoga 3.1.0 percent gaps
Browse files Browse the repository at this point in the history
  • Loading branch information
KurtGokhan committed Jul 15, 2024
1 parent 5efa27f commit a2f8703
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Runtime/Frameworks/UGUI/Components/UGUIComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ protected void ApplyYogaValues()
Layout.Top = StylingHelpers.GetStyleLength(computed, LayoutProperties.Top);
Layout.Bottom = StylingHelpers.GetStyleLength(computed, LayoutProperties.Bottom);

Layout.RowGap = StylingHelpers.GetStyleFloat(computed, LayoutProperties.RowGap);
Layout.ColumnGap = StylingHelpers.GetStyleFloat(computed, LayoutProperties.ColumnGap);
Layout.RowGap = StylingHelpers.GetStyleLength(computed, LayoutProperties.RowGap);
Layout.ColumnGap = StylingHelpers.GetStyleLength(computed, LayoutProperties.ColumnGap);

Layout.BorderLeftWidth = StylingHelpers.GetStyleFloatDouble(computed, LayoutProperties.BorderLeftWidth, LayoutProperties.BorderWidth);
Layout.BorderRightWidth = StylingHelpers.GetStyleFloatDouble(computed, LayoutProperties.BorderRightWidth, LayoutProperties.BorderWidth);
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Styling/Properties/LayoutProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public static class LayoutProperties
public static readonly LayoutProperty<float> BorderEndWidth = new LayoutProperty<float>("BorderEndWidth", true, converter: AllConverters.LengthConverter);
public static readonly LayoutProperty<int> Order = new LayoutProperty<int>("order", true);

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

public static Dictionary<string, ILayoutProperty> PropertyMap = new Dictionary<string, ILayoutProperty>(StringComparer.InvariantCultureIgnoreCase)
{
Expand Down
4 changes: 3 additions & 1 deletion Runtime/Styling/Shorthands/AllShorthands.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Yoga;

namespace ReactUnity.Styling.Shorthands
{
Expand Down Expand Up @@ -35,7 +36,8 @@ internal static class AllShorthands
internal static readonly StyleShorthand Animation = new AnimationShorthand("animation");
internal static readonly StyleShorthand Audio = new AudioShorthand("audio");
internal static readonly StyleShorthand Transform = new TransformShorthand("transform");
internal static readonly StyleShorthand Gap = new XYShorthand<float>("gap", LayoutProperties.RowGap, LayoutProperties.ColumnGap);
internal static readonly StyleShorthand Gap = new XYShorthand<YogaValue>("gap", LayoutProperties.RowGap, LayoutProperties.ColumnGap);

internal static readonly Dictionary<string, StyleShorthand> Map = new Dictionary<string, StyleShorthand>(StringComparer.InvariantCultureIgnoreCase)
{
{ "all", All },
Expand Down
3 changes: 3 additions & 0 deletions Runtime/Yoga/Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ internal static class Native
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetGap(YGNodeHandle node, YogaGutter gutter, float gapLength);

[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetGapPercent(YGNodeHandle node, YogaGutter gutter, float percent);

[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern float YGNodeStyleGetGap(YGNodeHandle node, YogaGutter gutter);

Expand Down
27 changes: 18 additions & 9 deletions Runtime/Yoga/YogaNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,22 +296,31 @@ public float AspectRatio
}
}

public float Gap
public YogaValue Gap
{
get => Native.YGNodeStyleGetGap(_ygNode, YogaGutter.All);
set => Native.YGNodeStyleSetGap(_ygNode, YogaGutter.All, value);
set
{
if (value.Unit == YogaUnit.Percent) Native.YGNodeStyleSetGapPercent(_ygNode, YogaGutter.All, value.Value);
else Native.YGNodeStyleSetGap(_ygNode, YogaGutter.All, value.Value);
}
}

public float ColumnGap
public YogaValue ColumnGap
{
get => Native.YGNodeStyleGetGap(_ygNode, YogaGutter.Column);
set => Native.YGNodeStyleSetGap(_ygNode, YogaGutter.Column, value);
set
{
if (value.Unit == YogaUnit.Percent) Native.YGNodeStyleSetGapPercent(_ygNode, YogaGutter.Column, value.Value);
else Native.YGNodeStyleSetGap(_ygNode, YogaGutter.Column, value.Value);
}
}

public float RowGap
public YogaValue RowGap
{
get => Native.YGNodeStyleGetGap(_ygNode, YogaGutter.Row);
set => Native.YGNodeStyleSetGap(_ygNode, YogaGutter.Row, value);
set
{
if (value.Unit == YogaUnit.Percent) Native.YGNodeStyleSetGapPercent(_ygNode, YogaGutter.Row, value.Value);
else Native.YGNodeStyleSetGap(_ygNode, YogaGutter.Row, value.Value);
}
}

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

0 comments on commit a2f8703

Please sign in to comment.