Skip to content
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

ImGui::InputText - Passing in first argument as empty string ("") makes the text box constantly lose focus #7246

Closed
dontna opened this issue Jan 20, 2024 · 3 comments
Labels
label/id and id stack implicit identifiers, pushid(), id stack

Comments

@dontna
Copy link

dontna commented Jan 20, 2024

Version/Branch of Dear ImGui:

Version 1.90.1, Branch: master

Back-ends:

imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp

Compiler, OS:

Arch Linux + G++

Full config/build information:

No response

Details:

If you pass in an empty string into the first argument of ImGui::InputText whenever it gets rendered it will unfocus, and you cannot type anything.

ImGui::InputText("", coolTextField, sizeof(coolTextField);

Everything compiles completely fine, you only see the issue once you run the compiled binary.

It can be an annoyance if you don't want any text to display next to the box, my hacky workaround was to pass in a "\t" like so:

ImGui::InputText("\t", coolTextField, sizeof(coolTextField));

Apologies in advance if I did something wrong, or this has been posted. I did look but I couldn't find anything myself.

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

// Here's some code anyone can copy and paste to reproduce your issue
ImGui::Begin("InputText Bug: Empty label unfocus");
char coolTextField[32];
ImGui::InputText("", coolTextField, sizeof(coolTextField));
ImGui::End();
@ocornut
Copy link
Owner

ocornut commented Jan 20, 2024

This is an invalid ID as it will conflict with the parent window ID.

You can use "##anything" as an ID.

This is answered in the first "Usage" section of the FAQ, with 5 items listed in bold in the index:
https://github.com/ocornut/imgui/blob/master/docs/FAQ.md#q-how-can-i-have-widgets-with-an-empty-label

@ocornut ocornut closed this as completed Jan 20, 2024
@ocornut
Copy link
Owner

ocornut commented Jan 20, 2024

In addition, and this is VERY IMPORTANT.
We DO detect this case and assert against it.
If I try to run your code I get this message:

image

That you didn't get the message means your asserts are not working or disabled. It is going to be really problematic using Dear ImGui if you don't have asserts enabled.

@ocornut ocornut added the label/id and id stack implicit identifiers, pushid(), id stack label Jan 20, 2024
@dontna
Copy link
Author

dontna commented Jan 22, 2024

Ahh I'm sorry for that, I completely missed it in the FAQ; that's my bad.

Also you're also correct, I checked and my assert's were disabled.

I messed up, my apologies; I'll be more careful next time!

Thank you for your response anyway!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
label/id and id stack implicit identifiers, pushid(), id stack
Projects
None yet
Development

No branches or pull requests

2 participants