Skip to content

Commit

Permalink
add some missing yoga APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
KurtGokhan committed Apr 9, 2024
1 parent 4aaf6ea commit 77814f4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
18 changes: 12 additions & 6 deletions Runtime/Yoga/Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ internal static class Native
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern YGNodeHandle YGNodeGetParent(YGNodeHandle node);

// YGNodeSetConfig
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeSetConfig(YGNodeHandle node, YGConfigHandle config);

// YGNodeGetConfig
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern YGConfigHandle YGNodeGetConfig(YGNodeHandle node);

[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeSetContext(IntPtr node, IntPtr managed);
Expand Down Expand Up @@ -112,13 +114,17 @@ internal static class Native
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern bool YGNodeIsReferenceBaseline(YGNodeHandle node);

// YGNodeSetNodeType
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeSetNodeType(YGNodeHandle node, YogaNodeType nodeType);

// YGNodeGetNodeType
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern YogaNodeType YGNodeGetNodeType(YGNodeHandle node);

// YGNodeSetAlwaysFormsContainingBlock
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeSetAlwaysFormsContainingBlock(YGNodeHandle node, bool alwaysFormsContainingBlock);

// YGNodeGetAlwaysFormsContainingBlock
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern bool YGNodeGetAlwaysFormsContainingBlock(YGNodeHandle node);

// deprecated: YGNodeCanUseCachedMeasurement

Expand Down
5 changes: 0 additions & 5 deletions Runtime/Yoga/YGNodeHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@ public void SetContext(YogaNode node)
{
if (!_managedNodeHandle.IsAllocated)
{
#if UNITY_5_4_OR_NEWER
// Weak causes 'GCHandle value belongs to a different domain' error
_managedNodeHandle = GCHandle.Alloc(node);
#else
_managedNodeHandle = GCHandle.Alloc(node, GCHandleType.Weak);
#endif
var managedNodePtr = GCHandle.ToIntPtr(_managedNodeHandle);
Native.YGNodeSetContext(this.handle, managedNodePtr);
}
Expand Down
17 changes: 17 additions & 0 deletions Runtime/Yoga/YogaNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,18 @@ public bool IsReferenceBaseline
set => Native.YGNodeSetIsReferenceBaseline(_ygNode, value);
}

public YogaNodeType NodeType
{
get => Native.YGNodeGetNodeType(_ygNode);
set => Native.YGNodeSetNodeType(_ygNode, value);
}

public bool AlwaysFormsContainingBlock
{
get => Native.YGNodeGetAlwaysFormsContainingBlock(_ygNode);
set => Native.YGNodeSetAlwaysFormsContainingBlock(_ygNode, value);
}

public bool ValuesEqual(float f1, float f2)
{
if (float.IsNaN(f1) || float.IsNaN(f2))
Expand Down Expand Up @@ -379,6 +391,11 @@ public void RemoveAt(int index)
Native.YGNodeRemoveChild(_ygNode, child._ygNode);
}

public void RemoveAll()
{
Native.YGNodeRemoveAllChildren(_ygNode);
}

public void AddChild(YogaNode child)
{
Insert(Count, child);
Expand Down

0 comments on commit 77814f4

Please sign in to comment.