MCPcopy Create free account
hub / github.com/cinder/Cinder / DemoWindowWidgetsComboBoxes

Function DemoWindowWidgetsComboBoxes

src/imgui/imgui_demo.cpp:1285–1376  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1283//-----------------------------------------------------------------------------
1284
1285static void DemoWindowWidgetsComboBoxes()
1286{
1287 IMGUI_DEMO_MARKER("Widgets/Combo");
1288 if (ImGui::TreeNode("Combo"))
1289 {
1290 // Combo Boxes are also called "Dropdown" in other systems
1291 // Expose flags as checkbox for the demo
1292 static ImGuiComboFlags flags = 0;
1293 ImGui::CheckboxFlags("ImGuiComboFlags_PopupAlignLeft", &flags, ImGuiComboFlags_PopupAlignLeft);
1294 ImGui::SameLine(); HelpMarker("Only makes a difference if the popup is larger than the combo");
1295 if (ImGui::CheckboxFlags("ImGuiComboFlags_NoArrowButton", &flags, ImGuiComboFlags_NoArrowButton))
1296 flags &= ~ImGuiComboFlags_NoPreview; // Clear incompatible flags
1297 if (ImGui::CheckboxFlags("ImGuiComboFlags_NoPreview", &flags, ImGuiComboFlags_NoPreview))
1298 flags &= ~(ImGuiComboFlags_NoArrowButton | ImGuiComboFlags_WidthFitPreview); // Clear incompatible flags
1299 if (ImGui::CheckboxFlags("ImGuiComboFlags_WidthFitPreview", &flags, ImGuiComboFlags_WidthFitPreview))
1300 flags &= ~ImGuiComboFlags_NoPreview;
1301
1302 // Override default popup height
1303 if (ImGui::CheckboxFlags("ImGuiComboFlags_HeightSmall", &flags, ImGuiComboFlags_HeightSmall))
1304 flags &= ~(ImGuiComboFlags_HeightMask_ & ~ImGuiComboFlags_HeightSmall);
1305 if (ImGui::CheckboxFlags("ImGuiComboFlags_HeightRegular", &flags, ImGuiComboFlags_HeightRegular))
1306 flags &= ~(ImGuiComboFlags_HeightMask_ & ~ImGuiComboFlags_HeightRegular);
1307 if (ImGui::CheckboxFlags("ImGuiComboFlags_HeightLargest", &flags, ImGuiComboFlags_HeightLargest))
1308 flags &= ~(ImGuiComboFlags_HeightMask_ & ~ImGuiComboFlags_HeightLargest);
1309
1310 // Using the generic BeginCombo() API, you have full control over how to display the combo contents.
1311 // (your selection data could be an index, a pointer to the object, an id for the object, a flag intrusively
1312 // stored in the object itself, etc.)
1313 const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIII", "JJJJ", "KKKK", "LLLLLLL", "MMMM", "OOOOOOO" };
1314 static int item_selected_idx = 0; // Here we store our selection data as an index.
1315
1316 // Pass in the preview value visible before opening the combo (it could technically be different contents or not pulled from items[])
1317 const char* combo_preview_value = items[item_selected_idx];
1318 if (ImGui::BeginCombo("combo 1", combo_preview_value, flags))
1319 {
1320 for (int n = 0; n < IM_ARRAYSIZE(items); n++)
1321 {
1322 const bool is_selected = (item_selected_idx == n);
1323 if (ImGui::Selectable(items[n], is_selected))
1324 item_selected_idx = n;
1325
1326 // Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
1327 if (is_selected)
1328 ImGui::SetItemDefaultFocus();
1329 }
1330 ImGui::EndCombo();
1331 }
1332
1333 // Show case embedding a filter using a simple trick: displaying the filter inside combo contents.
1334 // See https://github.com/ocornut/imgui/issues/718 for advanced/esoteric alternatives.
1335 if (ImGui::BeginCombo("combo 2 (w/ filter)", combo_preview_value, flags))
1336 {
1337 static ImGuiTextFilter filter;
1338 if (ImGui::IsWindowAppearing())
1339 {
1340 ImGui::SetKeyboardFocusHere();
1341 filter.Clear();
1342 }

Callers 1

DemoWindowWidgetsFunction · 0.85

Calls 5

HelpMarkerFunction · 0.85
ComboFunction · 0.85
PassFilterMethod · 0.80
ClearMethod · 0.45
DrawMethod · 0.45

Tested by

no test coverage detected