|
@@ -584,13 +584,12 @@ static void ShowDemoWindowWidgets()
|
|
|
|
|
|
{
|
|
|
// Using the _simplified_ one-liner Combo() api here
|
|
|
- // See "Combo" section for examples of how to use the more complete BeginCombo()/EndCombo() api.
|
|
|
+ // See "Combo" section for examples of how to use the more flexible BeginCombo()/EndCombo() api.
|
|
|
const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIIIIII", "JJJJ", "KKKKKKK" };
|
|
|
static int item_current = 0;
|
|
|
ImGui::Combo("combo", &item_current, items, IM_ARRAYSIZE(items));
|
|
|
ImGui::SameLine(); HelpMarker(
|
|
|
- "Refer to the \"Combo\" section below for an explanation of the full BeginCombo/EndCombo API, "
|
|
|
- "and demonstration of various flags.\n");
|
|
|
+ "Using the simplified one-liner Combo API here.\nRefer to the \"Combo\" section below for an explanation of how to use the more flexible and general BeginCombo/EndCombo API.");
|
|
|
}
|
|
|
|
|
|
{
|
|
@@ -689,14 +688,13 @@ static void ShowDemoWindowWidgets()
|
|
|
}
|
|
|
|
|
|
{
|
|
|
- // List box
|
|
|
+ // Using the _simplified_ one-liner ListBox() api here
|
|
|
+ // See "List boxes" section for examples of how to use the more flexible BeginListBox()/EndListBox() api.
|
|
|
const char* items[] = { "Apple", "Banana", "Cherry", "Kiwi", "Mango", "Orange", "Pineapple", "Strawberry", "Watermelon" };
|
|
|
static int item_current = 1;
|
|
|
- ImGui::ListBox("listbox\n(single select)", &item_current, items, IM_ARRAYSIZE(items), 4);
|
|
|
-
|
|
|
- //static int listbox_item_current2 = 2;
|
|
|
- //ImGui::SetNextItemWidth(-FLT_MIN);
|
|
|
- //ImGui::ListBox("##listbox2", &listbox_item_current2, listbox_items, IM_ARRAYSIZE(listbox_items), 4);
|
|
|
+ ImGui::ListBox("listbox", &item_current, items, IM_ARRAYSIZE(items), 4);
|
|
|
+ ImGui::SameLine(); HelpMarker(
|
|
|
+ "Using the simplified one-liner ListBox API here.\nRefer to the \"List boxes\" section below for an explanation of how to use the more flexible and general BeginListBox/EndListBox API.");
|
|
|
}
|
|
|
|
|
|
ImGui::TreePop();
|
|
@@ -1009,7 +1007,7 @@ static void ShowDemoWindowWidgets()
|
|
|
// (your selection data could be an index, a pointer to the object, an id for the object, a flag intrusively
|
|
|
// stored in the object itself, etc.)
|
|
|
const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIII", "JJJJ", "KKKK", "LLLLLLL", "MMMM", "OOOOOOO" };
|
|
|
- static int item_current_idx = 0; // Here our selection data is an index.
|
|
|
+ static int item_current_idx = 0; // Here we store our selection data as an index.
|
|
|
const char* combo_label = items[item_current_idx]; // Label to preview before opening the combo (technically it could be anything)
|
|
|
if (ImGui::BeginCombo("combo 1", combo_label, flags))
|
|
|
{
|
|
@@ -1042,6 +1040,48 @@ static void ShowDemoWindowWidgets()
|
|
|
ImGui::TreePop();
|
|
|
}
|
|
|
|
|
|
+ if (ImGui::TreeNode("List boxes"))
|
|
|
+ {
|
|
|
+ // Using the generic BeginListBox() API, you have full control over how to display the combo contents.
|
|
|
+ // (your selection data could be an index, a pointer to the object, an id for the object, a flag intrusively
|
|
|
+ // stored in the object itself, etc.)
|
|
|
+ const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIII", "JJJJ", "KKKK", "LLLLLLL", "MMMM", "OOOOOOO" };
|
|
|
+ static int item_current_idx = 0; // Here we store our selection data as an index.
|
|
|
+ if (ImGui::BeginListBox("listbox 1"))
|
|
|
+ {
|
|
|
+ for (int n = 0; n < IM_ARRAYSIZE(items); n++)
|
|
|
+ {
|
|
|
+ const bool is_selected = (item_current_idx == n);
|
|
|
+ if (ImGui::Selectable(items[n], is_selected))
|
|
|
+ item_current_idx = n;
|
|
|
+
|
|
|
+ // Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
|
|
|
+ if (is_selected)
|
|
|
+ ImGui::SetItemDefaultFocus();
|
|
|
+ }
|
|
|
+ ImGui::EndListBox();
|
|
|
+ }
|
|
|
+
|
|
|
+ // Custom size: use all width, 5 items tall
|
|
|
+ ImGui::Text("Full-width:");
|
|
|
+ if (ImGui::BeginListBox("##listbox 2", ImVec2(-FLT_MIN, 5 * ImGui::GetTextLineHeightWithSpacing())))
|
|
|
+ {
|
|
|
+ for (int n = 0; n < IM_ARRAYSIZE(items); n++)
|
|
|
+ {
|
|
|
+ const bool is_selected = (item_current_idx == n);
|
|
|
+ if (ImGui::Selectable(items[n], is_selected))
|
|
|
+ item_current_idx = n;
|
|
|
+
|
|
|
+ // Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
|
|
|
+ if (is_selected)
|
|
|
+ ImGui::SetItemDefaultFocus();
|
|
|
+ }
|
|
|
+ ImGui::EndListBox();
|
|
|
+ }
|
|
|
+
|
|
|
+ ImGui::TreePop();
|
|
|
+ }
|
|
|
+
|
|
|
if (ImGui::TreeNode("Selectables"))
|
|
|
{
|
|
|
// Selectable() has 2 overloads:
|
|
@@ -2557,11 +2597,11 @@ static void ShowDemoWindowLayout()
|
|
|
ImGui::Button("LEVERAGE\nBUZZWORD", size);
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
- if (ImGui::ListBoxHeader("List", size))
|
|
|
+ if (ImGui::BeginListBox("List", size))
|
|
|
{
|
|
|
ImGui::Selectable("Selected", true);
|
|
|
ImGui::Selectable("Not Selected", false);
|
|
|
- ImGui::ListBoxFooter();
|
|
|
+ ImGui::EndListBox();
|
|
|
}
|
|
|
|
|
|
ImGui::TreePop();
|