actondev / s7-imgui

Using s7 scheme alongside Dear ImGui to (interactively) build (cross platform) GUI apps.
40 stars 4 forks source link

input text & *buffer modification "bug" (as seen on video) #5

Closed actondev closed 4 years ago

actondev commented 4 years ago

As seen on https://youtu.be/MgHsl0u26MY?t=1086

From ImGui

// Edit a string of text
// - buf_size account for the zero-terminator, so a buf_size of 6 can hold "Hello" but not "Hello!".
//   This is so we can easily call InputText() on static arrays using ARRAYSIZE() and to match
//   Note that in std::string world, capacity() would omit 1 byte used by the zero-terminator.
// - When active, hold on a privately held copy of the text (and apply back to 'buf'). So changing 'buf' while the InputText is active has no effect.
// - If you want to use ImGui::InputText() with std::string, see misc/cpp/imgui_stdlib.h
// (FIXME: Rather confusing and messy function, among the worse part of our codebase, expecting to rewrite a V2 at some point.. Partly because we are
//  doing UTF8 > U16 > UTF8 conversions on the go to easily interface with stb_textedit. Ideally should stay in UTF-8 all the time. See https://github.com/nothings/stb/issues/188)
bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_size, const ImVec2& size_arg, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* callback_user_data)
{  

Focus on this

When active, hold on a privately held copy of the text (and apply back to 'buf'). So changing 'buf' while the InputText is active has no effect.

So, the problem was the text editor was active while I was modifying the *buffer (of type char*). So ImGui was holding its own char* buffer.

And indeed, if you "unfocus" the text editor, the modifications work as expected