MCPcopy Create free account
hub / github.com/danoon2/Boxedwine / ShowDemoWindowPopups

Function ShowDemoWindowPopups

lib/imgui/imgui_demo.cpp:2467–2695  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2465}
2466
2467static void ShowDemoWindowPopups()
2468{
2469 if (!ImGui::CollapsingHeader("Popups & Modal windows"))
2470 return;
2471
2472 // The properties of popups windows are:
2473 // - They block normal mouse hovering detection outside them. (*)
2474 // - Unless modal, they can be closed by clicking anywhere outside them, or by pressing ESCAPE.
2475 // - Their visibility state (~bool) is held internally by Dear ImGui instead of being held by the programmer as we are used to with regular Begin() calls.
2476 // User can manipulate the visibility state by calling OpenPopup().
2477 // (*) One can use IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup) to bypass it and detect hovering even when normally blocked by a popup.
2478 // Those three properties are connected. The library needs to hold their visibility state because it can close popups at any time.
2479
2480 // Typical use for regular windows:
2481 // bool my_tool_is_active = false; if (ImGui::Button("Open")) my_tool_is_active = true; [...] if (my_tool_is_active) Begin("My Tool", &my_tool_is_active) { [...] } End();
2482 // Typical use for popups:
2483 // if (ImGui::Button("Open")) ImGui::OpenPopup("MyPopup"); if (ImGui::BeginPopup("MyPopup") { [...] EndPopup(); }
2484
2485 // With popups we have to go through a library call (here OpenPopup) to manipulate the visibility state.
2486 // This may be a bit confusing at first but it should quickly make sense. Follow on the examples below.
2487
2488 if (ImGui::TreeNode("Popups"))
2489 {
2490 ImGui::TextWrapped("When a popup is active, it inhibits interacting with windows that are behind the popup. Clicking outside the popup closes it.");
2491
2492 static int selected_fish = -1;
2493 const char* names[] = { "Bream", "Haddock", "Mackerel", "Pollock", "Tilefish" };
2494 static bool toggles[] = { true, false, false, false, false };
2495
2496 // Simple selection popup
2497 // (If you want to show the current selection inside the Button itself, you may want to build a string using the "###" operator to preserve a constant ID with a variable label)
2498 if (ImGui::Button("Select.."))
2499 ImGui::OpenPopup("my_select_popup");
2500 ImGui::SameLine();
2501 ImGui::TextUnformatted(selected_fish == -1 ? "<None>" : names[selected_fish]);
2502 if (ImGui::BeginPopup("my_select_popup"))
2503 {
2504 ImGui::Text("Aquarium");
2505 ImGui::Separator();
2506 for (int i = 0; i < IM_ARRAYSIZE(names); i++)
2507 if (ImGui::Selectable(names[i]))
2508 selected_fish = i;
2509 ImGui::EndPopup();
2510 }
2511
2512 // Showing a menu with toggles
2513 if (ImGui::Button("Toggle.."))
2514 ImGui::OpenPopup("my_toggle_popup");
2515 if (ImGui::BeginPopup("my_toggle_popup"))
2516 {
2517 for (int i = 0; i < IM_ARRAYSIZE(names); i++)
2518 ImGui::MenuItem(names[i], "", &toggles[i]);
2519 if (ImGui::BeginMenu("Sub-menu"))
2520 {
2521 ImGui::MenuItem("Click me");
2522 ImGui::EndMenu();
2523 }
2524

Callers 1

ShowDemoWindowMethod · 0.85

Calls 2

ShowExampleMenuFileFunction · 0.85
ImVec2Class · 0.85

Tested by

no test coverage detected