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

Question about layouts #263

Closed
MrSapps opened this issue Jul 7, 2015 · 6 comments
Closed

Question about layouts #263

MrSapps opened this issue Jul 7, 2015 · 6 comments

Comments

@MrSapps
Copy link

MrSapps commented Jul 7, 2015

So I've got the following UI:

imguilayout

Using ImGui::CollapsingHeader, ImGui::InputText, ImGui::ListBox and ImGui::Button. How can I make the input text and listbox take the full width of the window like the button? For the button I used:

if (ImGui::Button("Play", ImVec2(ImGui::GetWindowWidth(), 20)))

Also is there some way to make the list box use up all of the vertical space?

I'm aiming for something like this:

target

@ocornut
Copy link
Owner

ocornut commented Jul 7, 2015

Use PushItemWidth(-1) for left alignment.
Pass a label starting with "##" to your listbox so it is invisible.

@MrSapps
Copy link
Author

MrSapps commented Jul 7, 2015

Nice thanks 👍 any idea about increasing the listbox height? Seems there isn't a PushItemHeight?

Edit: Or rather how do I know how many items it would take so it fills the dialog up to the button.

@ocornut
Copy link
Owner

ocornut commented Jul 7, 2015

PushItemWidth() is a separate thing because it pertain to many widgets (although this system will be revampd).
There is a height_in_items parameter to ListBox() but no explicit size to it at the moment.

You can create a more custom Listbox by calling its inner functions yourself, basically you want to call BeginChildFrame() / EndChildFrame() and stick a bunch of Selectable() inside. This is roughly was ListBox() does. I could perhaps add a variant of ListBox() with an explicit size. edit ListBox high-level helpers are poorly designed I think.

If you pass (0.0f, -100f) size to BeginChildFrame() it'll leave 100 of vertical space. You may want to use (0.0f, -ImGui::GetItemsLineHeightWithSpacing) here.

ocornut added a commit that referenced this issue Jul 7, 2015
@ocornut
Copy link
Owner

ocornut commented Jul 7, 2015

NB: i fixed a bug where ListBoxHeader() wouldn't take those negative sizes like other functions did.

            if (ImGui::ListBoxHeader("test", ImVec2(0, -20)))
            {
                ImGui::Selectable("aaa");
                ImGui::Selectable("aabb");
                ImGui::ListBoxFooter();
            }

Although the difference between ListBoxHeader() and BeginChildFrame() is only that the earlier has a label so if you don't need one you can use BeginChildFrame() anyway.

@ocornut
Copy link
Owner

ocornut commented Jul 10, 2015

@paulsapps Did you get that working?

@MrSapps
Copy link
Author

MrSapps commented Jul 11, 2015

I didn't try the auto sizing of the listbox by creating my own yet, but I'm certain it will work with the info you've provided :) thanks!

@ocornut ocornut closed this as completed Jul 11, 2015
ocornut added a commit that referenced this issue Nov 7, 2023
…eginChildFrame(). (#1666, #1496, #1395, #1710, #462, #503, #263)

Effectively allows us to avoid extending BeginChildFrame() api to mimic BeginChild() new parameters.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants