ImGui.NET
ImGui.NET copied to clipboard
Implement CallbackHistory InsertChars / DeleteChars
Sample CPP uses
else if (data->EventFlag == ImGuiInputTextFlags_CallbackHistory)
{
if (data->EventKey == ImGuiKey_UpArrow)
{
data->DeleteChars(0, data->BufTextLen);
data->InsertChars(0, "Pressed Up!");
data->SelectAll();
}
else if (data->EventKey == ImGuiKey_DownArrow)
{
data->DeleteChars(0, data->BufTextLen);
data->InsertChars(0, "Pressed Down!");
data->SelectAll();
}
}
It kind of works by doing:
Marshal.Copy(System.Text.Encoding.UTF8.GetBytes(historyStr), 0, (IntPtr)data->Buf, historyStr.Length);
data->BufTextLen = historyStr.Length;
data->BufSize = historyStr.Length;
data->BufDirty = 1;
data->CursorPos = data->SelectionStart = data->SelectionEnd = historyStr.Length;
but this is ugly and a weird hacky way of doing it.
What's the specific suggestion here? There are indeed some patterns in the native library that end up just plain awkward in the wrapped C# as you've noted. Could this just be solved by an additional wrapper function on top of it (potentially in your own codebase)? There is ImGui.Manual.cs, but usually it's for straightforward type translations that are just too tricky to represent with the code generator. We could include this there with a sufficient design.
@Subtixx I've been having issues with getting a string from input text. Do you mind sharing your full solution?