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

ListBox multiple selection #1528

Closed
Czar-Ec opened this issue Jan 2, 2018 · 2 comments
Closed

ListBox multiple selection #1528

Czar-Ec opened this issue Jan 2, 2018 · 2 comments

Comments

@Czar-Ec
Copy link

Czar-Ec commented Jan 2, 2018

Hello, I have been reading the ListBox code and I have been looking up other examples of its use but I'm still getting confused about how it is used.

I want to be able to have a listbox's source array be programmatically filled and then to also be able to select more than one option from the listbox.

Is it possible you (or anyone) could show me an example if not, explain how to achieve this at least?

@Czar-Ec Czar-Ec changed the title ListBox ListBox multiple selection Jan 2, 2018
@ocornut
Copy link
Owner

ocornut commented Jan 3, 2018

To create a custom listbox you only need to do:

if (ListBoxHeader(...))
{
  // display your items here, using e.g. Selectable()
}
ListBoxFooter();

So the programmatic filling is up to you, as well as the selection state which is stored on your side (when calling Selectable() you specify yourself is the item is selected). In the demo windows under Widgets: Selectables there are a handful of examples with persistent selection, and I have just updated the imgui_demo.cpp code now to add a few extra examples.

So assuming you have a list says vector<MyObj*>.
You may want to store your selection state either inside each object e.g. bool IsSelected, either externally Vector<MyObj*> ListOfSelectedObjects;. There are pros and cons to each methods.

Note that ListBoxHeader()/ListboxFooter() are legacy names and I expect to rename them to BeginListBox()/EndListBox() at some point. This should not really affect you at all.

@ocornut
Copy link
Owner

ocornut commented Jan 7, 2018

Closing this as answered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants