mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Add overloads for InputText which callbacks take Ptr instead
This commit is contained in:
parent
28658b4889
commit
cc21480d21
1 changed files with 116 additions and 2 deletions
|
|
@ -77,6 +77,8 @@ public unsafe partial class ImGui
|
||||||
|
|
||||||
public delegate int ImGuiInputTextCallbackDelegate(scoped ref ImGuiInputTextCallbackData data);
|
public delegate int ImGuiInputTextCallbackDelegate(scoped ref ImGuiInputTextCallbackData data);
|
||||||
|
|
||||||
|
public delegate int ImGuiInputTextCallbackPtrDelegate(ImGuiInputTextCallbackDataPtr data);
|
||||||
|
|
||||||
public delegate int ImGuiInputTextCallbackRefContextDelegate<TContext>(
|
public delegate int ImGuiInputTextCallbackRefContextDelegate<TContext>(
|
||||||
scoped ref ImGuiInputTextCallbackData data, scoped ref TContext context);
|
scoped ref ImGuiInputTextCallbackData data, scoped ref TContext context);
|
||||||
|
|
||||||
|
|
@ -92,6 +94,14 @@ public unsafe partial class ImGui
|
||||||
return InputTextEx(label, default, buf, default, flags, callback);
|
return InputTextEx(label, default, buf, default, flags, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool InputText(
|
||||||
|
ImU8String label, Span<byte> buf, ImGuiInputTextFlags flags, ImGuiInputTextCallbackPtrDelegate? callback)
|
||||||
|
{
|
||||||
|
if ((flags & (ImGuiInputTextFlags)ImGuiInputTextFlagsPrivate.Multiline) != ImGuiInputTextFlags.None)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(flags), flags, "Multiline must not be set");
|
||||||
|
return InputTextEx(label, default, buf, default, flags, callback);
|
||||||
|
}
|
||||||
|
|
||||||
public static bool InputText<TContext>(
|
public static bool InputText<TContext>(
|
||||||
ImU8String label, Span<byte> buf, ImGuiInputTextFlags flags,
|
ImU8String label, Span<byte> buf, ImGuiInputTextFlags flags,
|
||||||
ImGuiInputTextCallbackRefContextDelegate<TContext> callback, scoped ref TContext context)
|
ImGuiInputTextCallbackRefContextDelegate<TContext> callback, scoped ref TContext context)
|
||||||
|
|
@ -112,8 +122,20 @@ public unsafe partial class ImGui
|
||||||
|
|
||||||
public static bool InputText(
|
public static bool InputText(
|
||||||
ImU8String label, scoped ref string buf, int maxLength = ImU8String.AllocFreeBufferSize,
|
ImU8String label, scoped ref string buf, int maxLength = ImU8String.AllocFreeBufferSize,
|
||||||
ImGuiInputTextFlags flags = ImGuiInputTextFlags.None,
|
ImGuiInputTextFlags flags = ImGuiInputTextFlags.None, ImGuiInputTextCallbackDelegate? callback = null)
|
||||||
ImGuiInputTextCallbackDelegate? callback = null)
|
{
|
||||||
|
var t = new ImU8String(buf);
|
||||||
|
t.Reserve(maxLength + 1);
|
||||||
|
var r = InputText(label, t.Buffer[..(maxLength + 1)], flags, callback);
|
||||||
|
var i = t.Buffer.IndexOf((byte)0);
|
||||||
|
buf = Encoding.UTF8.GetString(i == -1 ? t.Buffer : t.Buffer[..i]);
|
||||||
|
t.Dispose();
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool InputText(
|
||||||
|
ImU8String label, scoped ref string buf, int maxLength, ImGuiInputTextFlags flags,
|
||||||
|
ImGuiInputTextCallbackPtrDelegate? callback)
|
||||||
{
|
{
|
||||||
var t = new ImU8String(buf);
|
var t = new ImU8String(buf);
|
||||||
t.Reserve(maxLength + 1);
|
t.Reserve(maxLength + 1);
|
||||||
|
|
@ -176,6 +198,32 @@ public unsafe partial class ImGui
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool InputTextEx(
|
||||||
|
ImU8String label, ImU8String hint, Span<byte> buf, Vector2 sizeArg,
|
||||||
|
ImGuiInputTextFlags flags, ImGuiInputTextCallbackPtrDelegate? callback)
|
||||||
|
{
|
||||||
|
fixed (byte* labelPtr = &label.GetPinnableNullTerminatedReference())
|
||||||
|
fixed (byte* hintPtr = &hint.GetPinnableNullTerminatedReference())
|
||||||
|
fixed (byte* bufPtr = buf)
|
||||||
|
#pragma warning disable CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type
|
||||||
|
{
|
||||||
|
var dataBuffer = PointerTuple.Create(&callback);
|
||||||
|
#pragma warning restore CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type
|
||||||
|
var r = ImGuiNative.InputTextEx(
|
||||||
|
labelPtr,
|
||||||
|
hintPtr,
|
||||||
|
bufPtr,
|
||||||
|
buf.Length,
|
||||||
|
sizeArg,
|
||||||
|
flags,
|
||||||
|
callback == null ? null : &InputTextCallbackPtrStatic,
|
||||||
|
callback == null ? null : &dataBuffer) != 0;
|
||||||
|
label.Dispose();
|
||||||
|
hint.Dispose();
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static bool InputTextEx<TContext>(
|
public static bool InputTextEx<TContext>(
|
||||||
ImU8String label, ImU8String hint, Span<byte> buf, Vector2 sizeArg, ImGuiInputTextFlags flags,
|
ImU8String label, ImU8String hint, Span<byte> buf, Vector2 sizeArg, ImGuiInputTextFlags flags,
|
||||||
ImGuiInputTextCallbackRefContextDelegate<TContext> callback, scoped ref TContext context)
|
ImGuiInputTextCallbackRefContextDelegate<TContext> callback, scoped ref TContext context)
|
||||||
|
|
@ -245,6 +293,19 @@ public unsafe partial class ImGui
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool InputTextEx(
|
||||||
|
ImU8String label, ImU8String hint, scoped ref string buf, int maxLength, Vector2 sizeArg,
|
||||||
|
ImGuiInputTextFlags flags, ImGuiInputTextCallbackPtrDelegate? callback)
|
||||||
|
{
|
||||||
|
var t = new ImU8String(buf);
|
||||||
|
t.Reserve(maxLength + 1);
|
||||||
|
var r = InputTextEx(label, hint, t.Buffer[..(maxLength + 1)], sizeArg, flags, callback);
|
||||||
|
var i = t.Buffer.IndexOf((byte)0);
|
||||||
|
buf = Encoding.UTF8.GetString(i == -1 ? t.Buffer : t.Buffer[..i]);
|
||||||
|
t.Dispose();
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool InputTextEx<TContext>(
|
public static bool InputTextEx<TContext>(
|
||||||
ImU8String label, ImU8String hint, scoped ref string buf, int maxLength, Vector2 sizeArg,
|
ImU8String label, ImU8String hint, scoped ref string buf, int maxLength, Vector2 sizeArg,
|
||||||
ImGuiInputTextFlags flags,
|
ImGuiInputTextFlags flags,
|
||||||
|
|
@ -284,6 +345,17 @@ public unsafe partial class ImGui
|
||||||
flags | (ImGuiInputTextFlags)ImGuiInputTextFlagsPrivate.Multiline,
|
flags | (ImGuiInputTextFlags)ImGuiInputTextFlagsPrivate.Multiline,
|
||||||
callback);
|
callback);
|
||||||
|
|
||||||
|
public static bool InputTextMultiline(
|
||||||
|
ImU8String label, Span<byte> buf, Vector2 size, ImGuiInputTextFlags flags,
|
||||||
|
ImGuiInputTextCallbackPtrDelegate? callback) =>
|
||||||
|
InputTextEx(
|
||||||
|
label,
|
||||||
|
default,
|
||||||
|
buf,
|
||||||
|
size,
|
||||||
|
flags | (ImGuiInputTextFlags)ImGuiInputTextFlagsPrivate.Multiline,
|
||||||
|
callback);
|
||||||
|
|
||||||
public static bool InputTextMultiline<TContext>(
|
public static bool InputTextMultiline<TContext>(
|
||||||
ImU8String label, Span<byte> buf, Vector2 size, ImGuiInputTextFlags flags,
|
ImU8String label, Span<byte> buf, Vector2 size, ImGuiInputTextFlags flags,
|
||||||
ImGuiInputTextCallbackRefContextDelegate<TContext> callback, scoped ref TContext context) =>
|
ImGuiInputTextCallbackRefContextDelegate<TContext> callback, scoped ref TContext context) =>
|
||||||
|
|
@ -322,6 +394,19 @@ public unsafe partial class ImGui
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool InputTextMultiline(
|
||||||
|
ImU8String label, scoped ref string buf, int maxLength, Vector2 size, ImGuiInputTextFlags flags,
|
||||||
|
ImGuiInputTextCallbackPtrDelegate? callback)
|
||||||
|
{
|
||||||
|
var t = new ImU8String(buf);
|
||||||
|
t.Reserve(maxLength + 1);
|
||||||
|
var r = InputTextMultiline(label, t.Buffer[..(maxLength + 1)], size, flags, callback);
|
||||||
|
var i = t.Buffer.IndexOf((byte)0);
|
||||||
|
buf = Encoding.UTF8.GetString(i == -1 ? t.Buffer : t.Buffer[..i]);
|
||||||
|
t.Dispose();
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool InputTextMultiline<TContext>(
|
public static bool InputTextMultiline<TContext>(
|
||||||
ImU8String label, scoped ref string buf, int maxLength, Vector2 size, ImGuiInputTextFlags flags,
|
ImU8String label, scoped ref string buf, int maxLength, Vector2 size, ImGuiInputTextFlags flags,
|
||||||
ImGuiInputTextCallbackRefContextDelegate<TContext> callback, scoped ref TContext context)
|
ImGuiInputTextCallbackRefContextDelegate<TContext> callback, scoped ref TContext context)
|
||||||
|
|
@ -357,6 +442,15 @@ public unsafe partial class ImGui
|
||||||
return InputTextEx(label, hint, buf, default, flags, callback);
|
return InputTextEx(label, hint, buf, default, flags, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool InputTextWithHint(
|
||||||
|
ImU8String label, ImU8String hint, Span<byte> buf, ImGuiInputTextFlags flags,
|
||||||
|
ImGuiInputTextCallbackPtrDelegate? callback)
|
||||||
|
{
|
||||||
|
if ((flags & (ImGuiInputTextFlags)ImGuiInputTextFlagsPrivate.Multiline) != ImGuiInputTextFlags.None)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(flags), flags, "Multiline must not be set");
|
||||||
|
return InputTextEx(label, hint, buf, default, flags, callback);
|
||||||
|
}
|
||||||
|
|
||||||
public static bool InputTextWithHint<TContext>(
|
public static bool InputTextWithHint<TContext>(
|
||||||
ImU8String label, ImU8String hint, Span<byte> buf, ImGuiInputTextFlags flags,
|
ImU8String label, ImU8String hint, Span<byte> buf, ImGuiInputTextFlags flags,
|
||||||
ImGuiInputTextCallbackRefContextDelegate<TContext> callback, scoped ref TContext context)
|
ImGuiInputTextCallbackRefContextDelegate<TContext> callback, scoped ref TContext context)
|
||||||
|
|
@ -389,6 +483,19 @@ public unsafe partial class ImGui
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool InputTextWithHint(
|
||||||
|
ImU8String label, ImU8String hint, scoped ref string buf, int maxLength, ImGuiInputTextFlags flags,
|
||||||
|
ImGuiInputTextCallbackPtrDelegate? callback)
|
||||||
|
{
|
||||||
|
var t = new ImU8String(buf);
|
||||||
|
t.Reserve(maxLength + 1);
|
||||||
|
var r = InputTextWithHint(label, hint, t.Buffer[..(maxLength + 1)], flags, callback);
|
||||||
|
var i = t.Buffer.IndexOf((byte)0);
|
||||||
|
buf = Encoding.UTF8.GetString(i == -1 ? t.Buffer : t.Buffer[..i]);
|
||||||
|
t.Dispose();
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool InputTextWithHint<TContext>(
|
public static bool InputTextWithHint<TContext>(
|
||||||
ImU8String label, ImU8String hint, scoped ref string buf, int maxLength, ImGuiInputTextFlags flags,
|
ImU8String label, ImU8String hint, scoped ref string buf, int maxLength, ImGuiInputTextFlags flags,
|
||||||
ImGuiInputTextCallbackRefContextDelegate<TContext> callback, scoped ref TContext context)
|
ImGuiInputTextCallbackRefContextDelegate<TContext> callback, scoped ref TContext context)
|
||||||
|
|
@ -447,6 +554,13 @@ public unsafe partial class ImGui
|
||||||
return dvps.Item1.Invoke(ref *data);
|
return dvps.Item1.Invoke(ref *data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvCdecl)])]
|
||||||
|
private static int InputTextCallbackPtrStatic(ImGuiInputTextCallbackData* data)
|
||||||
|
{
|
||||||
|
ref var dvps = ref PointerTuple.From<ImGuiInputTextCallbackPtrDelegate>(data->UserData);
|
||||||
|
return dvps.Item1.Invoke(data);
|
||||||
|
}
|
||||||
|
|
||||||
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvCdecl)])]
|
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvCdecl)])]
|
||||||
private static int InputTextCallbackRefContextStatic(ImGuiInputTextCallbackData* data)
|
private static int InputTextCallbackRefContextStatic(ImGuiInputTextCallbackData* data)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue