-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Combination of ImGuiInputTextFlags_{EnterReturnsTrue,EscapeClearsAll,CallbackEdit} #8273
Comments
You can use
I have confirmed now that |
This is now fixed with 00f12b9. Basic test case: {
static char buf[128];
ImGui::InputTextWithHint("Buf", "Hint", buf, 128,
ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_EscapeClearsAll | ImGuiInputTextFlags_CallbackEdit,
[](ImGuiInputTextCallbackData* data)
{
IMGUI_DEBUG_LOG("Callback %d!\n", data->EventFlag);
return 0;
}
);
if (ImGui::IsItemEdited())
IMGUI_DEBUG_LOG("IsItemEdited()\n");
} |
As suggested by ocornut in the resolution of: ocornut/imgui#8273
Thanks a lot for fixing! |
Version/Branch of Dear ImGui:
Version 1.91.6, Branch: docking
Back-ends:
imgui_impl_opengl3.cpp + imgui_impl_sdl2.cpp
Compiler, OS:
Linux + gcc
Full config/build information:
Details:
The ImGui::InputText() function is behaving unexpected (to me). It might be a bug.
I'm passing the flags
ImGuiInputTextFlags_EnterReturnsTrue
andImGuiInputTextFlags_EscapeClearsAll
toImGui::InputTextWithHint()
(actually I'm using the overload inimgui_stdlib
which operates on astd::string
, though I checked the code and I don't believe that's relevant). Because I'm passingEnterReturnsTrue
(I need to know when theEnter
key was pressed) the return-value no longer signals when some edit was made. Therefor I'm also passingImGuiInputTextFlags_CallbackEdit
and a custom callback function.My expectation was that this callback would trigger on all edits. That's mostly true, except when ESC is pressed to clear the input. I checked that without
EnterReturnsTrue
, the function does returntrue
on ESC (soCallbackEdit
is not a 100% replacement for this return value).Some background info:
I'm using this to implement a console interface. I'm calling
ImGui::InputTextWithHint()
withImGui::PushStyleColor(ImGuiCol_Text, 0)
to disable drawing. Soon after I do draw the text myself with custom syntax highlighting (and with some hacks usingimgui_internal.h
to also draw the cursor). Because syntax highlighting involves non-trivial parsing, I prefer to not have to do that on every frame. Therefor I'd like to know if some edit was made. I was hoping to useImGuiInputTextFlags_CallbackEdit
for that.The workaround I'm using now is: make a copy of the string before calling
InputText()
and then check if the string was changed. This works, and it's not super expensive, but it would be nice if this can be avoided. (But it's fine for me to give this issue lower priority).Thanks.
Screenshots/Video:
No response
Minimal, Complete and Verifiable Example code:
No response
The text was updated successfully, but these errors were encountered: