From 1ed6432be0b72db35af649cacaba4550ca7143b3 Mon Sep 17 00:00:00 2001 From: Eric Mellino Date: Sun, 28 Oct 2018 20:01:53 -0700 Subject: [PATCH] Add similar manual overloads for InputTextMultiline. --- src/CodeGenerator/Program.cs | 3 +- src/ImGui.NET/Generated/ImGui.gen.cs | 106 --------------------------- src/ImGui.NET/ImGui.Manual.cs | 62 ++++++++++++++++ 3 files changed, 64 insertions(+), 107 deletions(-) diff --git a/src/CodeGenerator/Program.cs b/src/CodeGenerator/Program.cs index 4614f7f..13f919b 100644 --- a/src/CodeGenerator/Program.cs +++ b/src/CodeGenerator/Program.cs @@ -103,7 +103,8 @@ namespace CodeGenerator private static readonly HashSet s_skippedFunctions = new HashSet() { - "igInputText" + "igInputText", + "igInputTextMultiline" }; static void Main(string[] args) diff --git a/src/ImGui.NET/Generated/ImGui.gen.cs b/src/ImGui.NET/Generated/ImGui.gen.cs index 475fa45..0c14df9 100644 --- a/src/ImGui.NET/Generated/ImGui.gen.cs +++ b/src/ImGui.NET/Generated/ImGui.gen.cs @@ -3465,112 +3465,6 @@ namespace ImGuiNET { ImGuiNative.igEndPopup(); } - public static bool InputTextMultiline(string label, string buf, uint buf_size) - { - int label_byteCount = Encoding.UTF8.GetByteCount(label); - byte* native_label = stackalloc byte[label_byteCount + 1]; - fixed (char* label_ptr = label) - { - int native_label_offset = Encoding.UTF8.GetBytes(label_ptr, label.Length, native_label, label_byteCount); - native_label[native_label_offset] = 0; - } - int buf_byteCount = Encoding.UTF8.GetByteCount(buf); - byte* native_buf = stackalloc byte[buf_byteCount + 1]; - fixed (char* buf_ptr = buf) - { - int native_buf_offset = Encoding.UTF8.GetBytes(buf_ptr, buf.Length, native_buf, buf_byteCount); - native_buf[native_buf_offset] = 0; - } - Vector2 size = new Vector2(); - ImGuiInputTextFlags flags = 0; - ImGuiInputTextCallback callback = null; - void* user_data = null; - byte ret = ImGuiNative.igInputTextMultiline(native_label, native_buf, buf_size, size, flags, callback, user_data); - return ret != 0; - } - public static bool InputTextMultiline(string label, string buf, uint buf_size, Vector2 size) - { - int label_byteCount = Encoding.UTF8.GetByteCount(label); - byte* native_label = stackalloc byte[label_byteCount + 1]; - fixed (char* label_ptr = label) - { - int native_label_offset = Encoding.UTF8.GetBytes(label_ptr, label.Length, native_label, label_byteCount); - native_label[native_label_offset] = 0; - } - int buf_byteCount = Encoding.UTF8.GetByteCount(buf); - byte* native_buf = stackalloc byte[buf_byteCount + 1]; - fixed (char* buf_ptr = buf) - { - int native_buf_offset = Encoding.UTF8.GetBytes(buf_ptr, buf.Length, native_buf, buf_byteCount); - native_buf[native_buf_offset] = 0; - } - ImGuiInputTextFlags flags = 0; - ImGuiInputTextCallback callback = null; - void* user_data = null; - byte ret = ImGuiNative.igInputTextMultiline(native_label, native_buf, buf_size, size, flags, callback, user_data); - return ret != 0; - } - public static bool InputTextMultiline(string label, string buf, uint buf_size, Vector2 size, ImGuiInputTextFlags flags) - { - int label_byteCount = Encoding.UTF8.GetByteCount(label); - byte* native_label = stackalloc byte[label_byteCount + 1]; - fixed (char* label_ptr = label) - { - int native_label_offset = Encoding.UTF8.GetBytes(label_ptr, label.Length, native_label, label_byteCount); - native_label[native_label_offset] = 0; - } - int buf_byteCount = Encoding.UTF8.GetByteCount(buf); - byte* native_buf = stackalloc byte[buf_byteCount + 1]; - fixed (char* buf_ptr = buf) - { - int native_buf_offset = Encoding.UTF8.GetBytes(buf_ptr, buf.Length, native_buf, buf_byteCount); - native_buf[native_buf_offset] = 0; - } - ImGuiInputTextCallback callback = null; - void* user_data = null; - byte ret = ImGuiNative.igInputTextMultiline(native_label, native_buf, buf_size, size, flags, callback, user_data); - return ret != 0; - } - public static bool InputTextMultiline(string label, string buf, uint buf_size, Vector2 size, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback) - { - int label_byteCount = Encoding.UTF8.GetByteCount(label); - byte* native_label = stackalloc byte[label_byteCount + 1]; - fixed (char* label_ptr = label) - { - int native_label_offset = Encoding.UTF8.GetBytes(label_ptr, label.Length, native_label, label_byteCount); - native_label[native_label_offset] = 0; - } - int buf_byteCount = Encoding.UTF8.GetByteCount(buf); - byte* native_buf = stackalloc byte[buf_byteCount + 1]; - fixed (char* buf_ptr = buf) - { - int native_buf_offset = Encoding.UTF8.GetBytes(buf_ptr, buf.Length, native_buf, buf_byteCount); - native_buf[native_buf_offset] = 0; - } - void* user_data = null; - byte ret = ImGuiNative.igInputTextMultiline(native_label, native_buf, buf_size, size, flags, callback, user_data); - return ret != 0; - } - public static bool InputTextMultiline(string label, string buf, uint buf_size, Vector2 size, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, IntPtr user_data) - { - int label_byteCount = Encoding.UTF8.GetByteCount(label); - byte* native_label = stackalloc byte[label_byteCount + 1]; - fixed (char* label_ptr = label) - { - int native_label_offset = Encoding.UTF8.GetBytes(label_ptr, label.Length, native_label, label_byteCount); - native_label[native_label_offset] = 0; - } - int buf_byteCount = Encoding.UTF8.GetByteCount(buf); - byte* native_buf = stackalloc byte[buf_byteCount + 1]; - fixed (char* buf_ptr = buf) - { - int native_buf_offset = Encoding.UTF8.GetBytes(buf_ptr, buf.Length, native_buf, buf_byteCount); - native_buf[native_buf_offset] = 0; - } - void* native_user_data = (void*)user_data.ToPointer(); - byte ret = ImGuiNative.igInputTextMultiline(native_label, native_buf, buf_size, size, flags, callback, native_user_data); - return ret != 0; - } public static bool Selectable(string label) { int label_byteCount = Encoding.UTF8.GetByteCount(label); diff --git a/src/ImGui.NET/ImGui.Manual.cs b/src/ImGui.NET/ImGui.Manual.cs index b113505..edadfc9 100644 --- a/src/ImGui.NET/ImGui.Manual.cs +++ b/src/ImGui.NET/ImGui.Manual.cs @@ -1,4 +1,5 @@ using System; +using System.Numerics; using System.Text; namespace ImGuiNET @@ -110,6 +111,67 @@ namespace ImGuiNET return result != 0; } + public static bool InputTextMultiline( + string label, + ref string input, + uint maxLength, + Vector2 size) => InputTextMultiline(label, ref input, maxLength, size, 0, null, IntPtr.Zero); + + public static bool InputTextMultiline( + string label, + ref string input, + uint maxLength, + Vector2 size, + ImGuiInputTextFlags flags) => InputTextMultiline(label, ref input, maxLength, size, flags, null, IntPtr.Zero); + + public static bool InputTextMultiline( + string label, + ref string input, + uint maxLength, + Vector2 size, + ImGuiInputTextFlags flags, + ImGuiInputTextCallback callback) => InputTextMultiline(label, ref input, maxLength, size, flags, callback, IntPtr.Zero); + + public static bool InputTextMultiline( + string label, + ref string input, + uint maxLength, + Vector2 size, + ImGuiInputTextFlags flags, + ImGuiInputTextCallback callback, + IntPtr user_data) + { + int labelByteCount = Encoding.UTF8.GetByteCount(label); + byte* labelBytes = stackalloc byte[labelByteCount]; + fixed (char* labelPtr = label) + { + Encoding.UTF8.GetBytes(labelPtr, label.Length, labelBytes, labelByteCount); + } + + int bytesNeeded = Encoding.UTF8.GetByteCount(input); + int stackBufSize = Math.Max((int)maxLength, bytesNeeded); + byte* bufBytes = stackalloc byte[stackBufSize]; + fixed (char* u16Ptr = input) + { + Encoding.UTF8.GetBytes(u16Ptr, input.Length, bufBytes, stackBufSize); + } + + byte result = ImGuiNative.igInputTextMultiline( + labelBytes, + bufBytes, + (uint)stackBufSize, + size, + flags, + callback, + user_data.ToPointer()); + if (!Util.AreStringsEqual(input, bufBytes)) + { + input = Util.StringFromPtr(bufBytes); + } + + return result != 0; + } + public static bool InputText( string label, IntPtr buf,