Skip to content

Commit

Permalink
feat: add set name for renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
Rofli Sanches committed May 15, 2021
1 parent 88a91ab commit 8e4ba9d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Source/Utils/ImGuiExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,28 @@ internal static void SetIniFilename(this ImGuiIOPtr io, string name)
_managedAllocations.Add((IntPtr)nativeName);
}
}

public static void SetBackendRendererName(this ImGuiIOPtr io, string name)
{
if (io.NativePtr->BackendRendererName != (byte*)0)
{
if (_managedAllocations.Contains((IntPtr)io.NativePtr->BackendRendererName))
{
Marshal.FreeHGlobal((IntPtr)io.NativePtr->BackendRendererName);
io.NativePtr->BackendRendererName = (byte*)0;
}
}
if (name != null)
{
int byteCount = Encoding.UTF8.GetByteCount(name);
byte* nativeName = (byte*)Marshal.AllocHGlobal(byteCount + 1);
int offset = Utils.GetUtf8(name, nativeName, byteCount);

nativeName[offset] = 0;

io.NativePtr->BackendRendererName = nativeName;
_managedAllocations.Add((IntPtr)nativeName);
}
}
}
}

0 comments on commit 8e4ba9d

Please sign in to comment.