Implement AutoUtf8Buffer

This commit is contained in:
Soreepeong 2025-07-22 03:47:13 +09:00
parent 51a20300d8
commit 11aef2f4d6
20 changed files with 926 additions and 232 deletions

View file

@ -1,5 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Dalamud.Bindings.ImGui;
@ -8,7 +9,7 @@ namespace Dalamud.Bindings.ImGui;
public static unsafe partial class ImGui
{
public static ImFontPtr AddFontFromFileTTF(
ImFontAtlasPtr self, AutoUtf8Buffer filename, float sizePixels, ImFontConfigPtr fontCfg = default,
ImFontAtlasPtr self, [InterpolatedStringHandlerArgument] AutoUtf8Buffer filename, float sizePixels, ImFontConfigPtr fontCfg = default,
ushort* glyphRanges = null)
{
fixed (byte* filenamePtr = filename.NullTerminatedSpan)
@ -20,7 +21,7 @@ public static unsafe partial class ImGui
}
public static ImFontPtr AddFontFromMemoryCompressedBase85TTF(
ImFontAtlasPtr self, AutoUtf8Buffer compressedFontDatabase85, float sizePixels,
ImFontAtlasPtr self, [InterpolatedStringHandlerArgument] AutoUtf8Buffer compressedFontDatabase85, float sizePixels,
ImFontConfigPtr fontCfg = default, ushort* glyphRanges = null)
{
fixed (byte* compressedFontDatabase85Ptr = compressedFontDatabase85.NullTerminatedSpan)
@ -64,6 +65,62 @@ public static unsafe partial class ImGui
glyphRanges);
}
public static ref bool GetBoolRef(ImGuiStoragePtr self, uint key, bool defaultValue = false) =>
ref *ImGuiNative.GetBoolRef(self.Handle, key, defaultValue ? (byte)1 : (byte)0);
public static ref float GetFloatRef(ImGuiStoragePtr self, uint key, float defaultValue = 0.0f) =>
ref *ImGuiNative.GetFloatRef(self.Handle, key, defaultValue);
public static ref int GetIntRef(ImGuiStoragePtr self, uint key, int defaultValue = 0) =>
ref *ImGuiNative.GetIntRef(self.Handle, key, defaultValue);
public static ref void* GetVoidPtrRef(ImGuiStoragePtr self, uint key, void* defaultValue = null) =>
ref *ImGuiNative.GetVoidPtrRef(self.Handle, key, defaultValue);
public static ref T* GetPtrRef<T>(ImGuiStoragePtr self, uint key, T* defaultValue = null)
where T : unmanaged =>
ref *(T**)ImGuiNative.GetVoidPtrRef(self.Handle, key, defaultValue);
public static ref T GetRef<T>(ImGuiStoragePtr self, uint key, T defaultValue = default)
where T : unmanaged
{
if (sizeof(T) > sizeof(void*))
throw new ArgumentOutOfRangeException(nameof(T), typeof(T), null);
return ref *(T*)ImGuiNative.GetVoidPtrRef(self.Handle, key, *(void**)&defaultValue);
}
public static uint GetID([InterpolatedStringHandlerArgument] AutoUtf8Buffer strId)
{
fixed (byte* strIdPtr = strId.Span)
{
var r = ImGuiNative.GetID(strIdPtr, strIdPtr + strId.Length);
strId.Dispose();
return r;
}
}
public static uint GetID(nint ptrId) => ImGuiNative.GetID((void*)ptrId);
public static uint GetID(nuint ptrId) => ImGuiNative.GetID((void*)ptrId);
public static uint GetID(void* ptrId) => ImGuiNative.GetID(ptrId);
public static void PushID([InterpolatedStringHandlerArgument] AutoUtf8Buffer strId)
{
fixed (byte* strIdPtr = strId.Span)
{
ImGuiNative.PushID(strIdPtr, strIdPtr + strId.Length);
strId.Dispose();
}
}
public static void PushID(nint ptrId) => ImGuiNative.PushID((void*)ptrId);
public static void PushID(nuint ptrId) => ImGuiNative.PushID((void*)ptrId);
public static void PushID(void* ptrId) => ImGuiNative.PushID(ptrId);
// DISCARDED: PlotHistogram
// DISCARDED: PlotLines
}