Skip to content

Commit 1ed6432

Browse files
committed
Add similar manual overloads for InputTextMultiline.
1 parent a2ecece commit 1ed6432

3 files changed

Lines changed: 64 additions & 107 deletions

File tree

src/CodeGenerator/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ class Program
103103

104104
private static readonly HashSet<string> s_skippedFunctions = new HashSet<string>()
105105
{
106-
"igInputText"
106+
"igInputText",
107+
"igInputTextMultiline"
107108
};
108109

109110
static void Main(string[] args)

src/ImGui.NET/Generated/ImGui.gen.cs

Lines changed: 0 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -3465,112 +3465,6 @@ public static void EndPopup()
34653465
{
34663466
ImGuiNative.igEndPopup();
34673467
}
3468-
public static bool InputTextMultiline(string label, string buf, uint buf_size)
3469-
{
3470-
int label_byteCount = Encoding.UTF8.GetByteCount(label);
3471-
byte* native_label = stackalloc byte[label_byteCount + 1];
3472-
fixed (char* label_ptr = label)
3473-
{
3474-
int native_label_offset = Encoding.UTF8.GetBytes(label_ptr, label.Length, native_label, label_byteCount);
3475-
native_label[native_label_offset] = 0;
3476-
}
3477-
int buf_byteCount = Encoding.UTF8.GetByteCount(buf);
3478-
byte* native_buf = stackalloc byte[buf_byteCount + 1];
3479-
fixed (char* buf_ptr = buf)
3480-
{
3481-
int native_buf_offset = Encoding.UTF8.GetBytes(buf_ptr, buf.Length, native_buf, buf_byteCount);
3482-
native_buf[native_buf_offset] = 0;
3483-
}
3484-
Vector2 size = new Vector2();
3485-
ImGuiInputTextFlags flags = 0;
3486-
ImGuiInputTextCallback callback = null;
3487-
void* user_data = null;
3488-
byte ret = ImGuiNative.igInputTextMultiline(native_label, native_buf, buf_size, size, flags, callback, user_data);
3489-
return ret != 0;
3490-
}
3491-
public static bool InputTextMultiline(string label, string buf, uint buf_size, Vector2 size)
3492-
{
3493-
int label_byteCount = Encoding.UTF8.GetByteCount(label);
3494-
byte* native_label = stackalloc byte[label_byteCount + 1];
3495-
fixed (char* label_ptr = label)
3496-
{
3497-
int native_label_offset = Encoding.UTF8.GetBytes(label_ptr, label.Length, native_label, label_byteCount);
3498-
native_label[native_label_offset] = 0;
3499-
}
3500-
int buf_byteCount = Encoding.UTF8.GetByteCount(buf);
3501-
byte* native_buf = stackalloc byte[buf_byteCount + 1];
3502-
fixed (char* buf_ptr = buf)
3503-
{
3504-
int native_buf_offset = Encoding.UTF8.GetBytes(buf_ptr, buf.Length, native_buf, buf_byteCount);
3505-
native_buf[native_buf_offset] = 0;
3506-
}
3507-
ImGuiInputTextFlags flags = 0;
3508-
ImGuiInputTextCallback callback = null;
3509-
void* user_data = null;
3510-
byte ret = ImGuiNative.igInputTextMultiline(native_label, native_buf, buf_size, size, flags, callback, user_data);
3511-
return ret != 0;
3512-
}
3513-
public static bool InputTextMultiline(string label, string buf, uint buf_size, Vector2 size, ImGuiInputTextFlags flags)
3514-
{
3515-
int label_byteCount = Encoding.UTF8.GetByteCount(label);
3516-
byte* native_label = stackalloc byte[label_byteCount + 1];
3517-
fixed (char* label_ptr = label)
3518-
{
3519-
int native_label_offset = Encoding.UTF8.GetBytes(label_ptr, label.Length, native_label, label_byteCount);
3520-
native_label[native_label_offset] = 0;
3521-
}
3522-
int buf_byteCount = Encoding.UTF8.GetByteCount(buf);
3523-
byte* native_buf = stackalloc byte[buf_byteCount + 1];
3524-
fixed (char* buf_ptr = buf)
3525-
{
3526-
int native_buf_offset = Encoding.UTF8.GetBytes(buf_ptr, buf.Length, native_buf, buf_byteCount);
3527-
native_buf[native_buf_offset] = 0;
3528-
}
3529-
ImGuiInputTextCallback callback = null;
3530-
void* user_data = null;
3531-
byte ret = ImGuiNative.igInputTextMultiline(native_label, native_buf, buf_size, size, flags, callback, user_data);
3532-
return ret != 0;
3533-
}
3534-
public static bool InputTextMultiline(string label, string buf, uint buf_size, Vector2 size, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback)
3535-
{
3536-
int label_byteCount = Encoding.UTF8.GetByteCount(label);
3537-
byte* native_label = stackalloc byte[label_byteCount + 1];
3538-
fixed (char* label_ptr = label)
3539-
{
3540-
int native_label_offset = Encoding.UTF8.GetBytes(label_ptr, label.Length, native_label, label_byteCount);
3541-
native_label[native_label_offset] = 0;
3542-
}
3543-
int buf_byteCount = Encoding.UTF8.GetByteCount(buf);
3544-
byte* native_buf = stackalloc byte[buf_byteCount + 1];
3545-
fixed (char* buf_ptr = buf)
3546-
{
3547-
int native_buf_offset = Encoding.UTF8.GetBytes(buf_ptr, buf.Length, native_buf, buf_byteCount);
3548-
native_buf[native_buf_offset] = 0;
3549-
}
3550-
void* user_data = null;
3551-
byte ret = ImGuiNative.igInputTextMultiline(native_label, native_buf, buf_size, size, flags, callback, user_data);
3552-
return ret != 0;
3553-
}
3554-
public static bool InputTextMultiline(string label, string buf, uint buf_size, Vector2 size, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, IntPtr user_data)
3555-
{
3556-
int label_byteCount = Encoding.UTF8.GetByteCount(label);
3557-
byte* native_label = stackalloc byte[label_byteCount + 1];
3558-
fixed (char* label_ptr = label)
3559-
{
3560-
int native_label_offset = Encoding.UTF8.GetBytes(label_ptr, label.Length, native_label, label_byteCount);
3561-
native_label[native_label_offset] = 0;
3562-
}
3563-
int buf_byteCount = Encoding.UTF8.GetByteCount(buf);
3564-
byte* native_buf = stackalloc byte[buf_byteCount + 1];
3565-
fixed (char* buf_ptr = buf)
3566-
{
3567-
int native_buf_offset = Encoding.UTF8.GetBytes(buf_ptr, buf.Length, native_buf, buf_byteCount);
3568-
native_buf[native_buf_offset] = 0;
3569-
}
3570-
void* native_user_data = (void*)user_data.ToPointer();
3571-
byte ret = ImGuiNative.igInputTextMultiline(native_label, native_buf, buf_size, size, flags, callback, native_user_data);
3572-
return ret != 0;
3573-
}
35743468
public static bool Selectable(string label)
35753469
{
35763470
int label_byteCount = Encoding.UTF8.GetByteCount(label);

src/ImGui.NET/ImGui.Manual.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Numerics;
23
using System.Text;
34

45
namespace ImGuiNET
@@ -110,6 +111,67 @@ public static bool InputText(
110111
return result != 0;
111112
}
112113

114+
public static bool InputTextMultiline(
115+
string label,
116+
ref string input,
117+
uint maxLength,
118+
Vector2 size) => InputTextMultiline(label, ref input, maxLength, size, 0, null, IntPtr.Zero);
119+
120+
public static bool InputTextMultiline(
121+
string label,
122+
ref string input,
123+
uint maxLength,
124+
Vector2 size,
125+
ImGuiInputTextFlags flags) => InputTextMultiline(label, ref input, maxLength, size, flags, null, IntPtr.Zero);
126+
127+
public static bool InputTextMultiline(
128+
string label,
129+
ref string input,
130+
uint maxLength,
131+
Vector2 size,
132+
ImGuiInputTextFlags flags,
133+
ImGuiInputTextCallback callback) => InputTextMultiline(label, ref input, maxLength, size, flags, callback, IntPtr.Zero);
134+
135+
public static bool InputTextMultiline(
136+
string label,
137+
ref string input,
138+
uint maxLength,
139+
Vector2 size,
140+
ImGuiInputTextFlags flags,
141+
ImGuiInputTextCallback callback,
142+
IntPtr user_data)
143+
{
144+
int labelByteCount = Encoding.UTF8.GetByteCount(label);
145+
byte* labelBytes = stackalloc byte[labelByteCount];
146+
fixed (char* labelPtr = label)
147+
{
148+
Encoding.UTF8.GetBytes(labelPtr, label.Length, labelBytes, labelByteCount);
149+
}
150+
151+
int bytesNeeded = Encoding.UTF8.GetByteCount(input);
152+
int stackBufSize = Math.Max((int)maxLength, bytesNeeded);
153+
byte* bufBytes = stackalloc byte[stackBufSize];
154+
fixed (char* u16Ptr = input)
155+
{
156+
Encoding.UTF8.GetBytes(u16Ptr, input.Length, bufBytes, stackBufSize);
157+
}
158+
159+
byte result = ImGuiNative.igInputTextMultiline(
160+
labelBytes,
161+
bufBytes,
162+
(uint)stackBufSize,
163+
size,
164+
flags,
165+
callback,
166+
user_data.ToPointer());
167+
if (!Util.AreStringsEqual(input, bufBytes))
168+
{
169+
input = Util.StringFromPtr(bufBytes);
170+
}
171+
172+
return result != 0;
173+
}
174+
113175
public static bool InputText(
114176
string label,
115177
IntPtr buf,

0 commit comments

Comments
 (0)