-
-
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
Different InputText() behavior with Selectable() and TreeNode() #7077
Comments
Hello, You can only running the If instead you do bool open = ImGui::TreeNodeEx("TreeNode", 0, "TreeNode");
if (ImGui::IsItemClicked())
stringBuffer = option;
if (open)
{
//...
ImGui::TreePop();
} It should work. Please note that replacing the underlying contents of an |
Unfortunately that didn't work. My code example wasn't very accurate, because I'm already doing something similar (calling IsItemClicked() regardless of whether TreeNodeEx() returns true or false). I just created this as a reproducible test:
|
OK. It's an unfortunate side effect of the changes made for #4714. The same thing which is exactly desirable for #4714 is not a desirable in your case. The hacky/undocumented workaround is: ImGuiContext* ctx = ImGui::GetCurrentContext();
ctx->InputTextDeactivatedState.ID = 0; Unfortunately I would bundle that with the one million other hanging issues related to modifying the |
Thanks, the workaround works. This issue can be closed, unless you want to keep it open to track the InputText() issues. |
Version/Branch of Dear ImGui:
Version: 1.90
Back-end/Renderer/Compiler/OS
Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp
Compiler: gcc 11.4.0
Operating System: Mint Linux 21
My Issue/Question:
My goal: I want to click on an item and replace the contents of a string buffer, and have that update reflected in the next call to InputText(). (The string buffer's contents are changing, but the address of the buffer stays the same.)
What's happening: It works as expected when using Selectable(). In the first half of that video, I can modify the contents of the string buffer using the InputText(), then I click one of the Selectable()s (in the History tab), then the string buffer's contents gets replaced, and then InputText() (the URL textbox) has lost focus but displays the new string contents.
Something like this:
But when using TreeNodeEx(), it doesn't work as expected. When I click a TreeNodeEx() (in the Collections tab), I can see it replacing the contents of the string buffer using the debugger, but then as soon as that InputText() is called it replaces the contents of the string buffer with the old value, and InputText() still loses focus.
Note that if I click a TreeNodeEx() twice it will correctly update the string that InputText() displays after the second click.
Screenshots/Video
2023-11-29.21-25-18.mp4
Edit: I just realized that the IDs of the different widgets is probably important here, so I updated the code example to show that I'm actually using TreeNodeEx() and passing in a unique pointer per node as the id, not just some text
The text was updated successfully, but these errors were encountered: