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

Showing text inputs without a label? #6984

Closed
JC3 opened this issue Nov 4, 2023 · 4 comments
Closed

Showing text inputs without a label? #6984

JC3 opened this issue Nov 4, 2023 · 4 comments
Labels
label/id and id stack implicit identifiers, pushid(), id stack

Comments

@JC3
Copy link

JC3 commented Nov 4, 2023

I'm rendering my own labels as text on the left side of text inputs.

How do I set a text input to not have a label?

I noticed that if I pass the same label (e.g. "") to every input text, then all the inputs duplicate eachother. It seems they have to have unique labels.

I couldn't find a text input flag to hide the label.

@PathogenDavid
Copy link
Contributor

Please read the FAQ entry on widget IDs.

To remove the blank space typically used for the labels, use ImGui::PushItemWidth(-FLT_MIN);. This setting applies to the current window, so it must be called after ImGui::Begin. (Also don't forget to call ImGui::PopItemWidth() as well.)


Since based on your other questions you seem to be using Python: As far as I'm aware, Python's standard library does not have an equivalent to FLT_MIN (everything on sys.float_info is for doubles since Python's float uses double precision.) You can create your own constant, the value should be 1.175494351e-38F. (Really it just needs to be a tiny number, but using -FLT_MIN for this purpose is idiomatic Dear ImGui usage.)

@ocornut
Copy link
Owner

ocornut commented Nov 4, 2023

You may use -1 instead of -FLT_MIN but it’ll create a slight 1 px asymetry on window paddings.

@JC3
Copy link
Author

JC3 commented Nov 4, 2023

Thank you very much! I will try all this on Monday.

@ocornut
Copy link
Owner

ocornut commented Nov 4, 2023

Closing as answered.

How do I set a text input to not have a label?

For future reference, even though this is answered in the FAQ in "How can I have widgets with an empty label?", the general answer is to prefix your identifier with "##" , e..g "##MyInputText", as everything after "##" is hidden.

It seems they have to have unique labels.

This is covered in more details in the FAQ section. Most often when you have a loop submitting items you'll want to call ImGui::PushID()/PopID().

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

3 participants