MCPcopy Create free account
hub / github.com/AlexandreRouma/SDRPlusPlus / ShowDemoWindowPopups

Function ShowDemoWindowPopups

core/src/imgui/imgui_demo.cpp:3093–3375  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3091}
3092
3093static void ShowDemoWindowPopups()
3094{
3095 if (!ImGui::CollapsingHeader("Popups & Modal windows"))
3096 return;
3097
3098 // The properties of popups windows are:
3099 // - They block normal mouse hovering detection outside them. (*)
3100 // - Unless modal, they can be closed by clicking anywhere outside them, or by pressing ESCAPE.
3101 // - Their visibility state (~bool) is held internally by Dear ImGui instead of being held by the programmer as
3102 // we are used to with regular Begin() calls. User can manipulate the visibility state by calling OpenPopup().
3103 // (*) One can use IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup) to bypass it and detect hovering even
3104 // when normally blocked by a popup.
3105 // Those three properties are connected. The library needs to hold their visibility state BECAUSE it can close
3106 // popups at any time.
3107
3108 // Typical use for regular windows:
3109 // 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();
3110 // Typical use for popups:
3111 // if (ImGui::Button("Open")) ImGui::OpenPopup("MyPopup"); if (ImGui::BeginPopup("MyPopup") { [...] EndPopup(); }
3112
3113 // With popups we have to go through a library call (here OpenPopup) to manipulate the visibility state.
3114 // This may be a bit confusing at first but it should quickly make sense. Follow on the examples below.
3115
3116 if (ImGui::TreeNode("Popups"))
3117 {
3118 ImGui::TextWrapped(
3119 "When a popup is active, it inhibits interacting with windows that are behind the popup. "
3120 "Clicking outside the popup closes it.");
3121
3122 static int selected_fish = -1;
3123 const char* names[] = { "Bream", "Haddock", "Mackerel", "Pollock", "Tilefish" };
3124 static bool toggles[] = { true, false, false, false, false };
3125
3126 // Simple selection popup (if you want to show the current selection inside the Button itself,
3127 // you may want to build a string using the "###" operator to preserve a constant ID with a variable label)
3128 if (ImGui::Button("Select.."))
3129 ImGui::OpenPopup("my_select_popup");
3130 ImGui::SameLine();
3131 ImGui::TextUnformatted(selected_fish == -1 ? "<None>" : names[selected_fish]);
3132 if (ImGui::BeginPopup("my_select_popup"))
3133 {
3134 ImGui::Text("Aquarium");
3135 ImGui::Separator();
3136 for (int i = 0; i < IM_ARRAYSIZE(names); i++)
3137 if (ImGui::Selectable(names[i]))
3138 selected_fish = i;
3139 ImGui::EndPopup();
3140 }
3141
3142 // Showing a menu with toggles
3143 if (ImGui::Button("Toggle.."))
3144 ImGui::OpenPopup("my_toggle_popup");
3145 if (ImGui::BeginPopup("my_toggle_popup"))
3146 {
3147 for (int i = 0; i < IM_ARRAYSIZE(names); i++)
3148 ImGui::MenuItem(names[i], "", &toggles[i]);
3149 if (ImGui::BeginMenu("Sub-menu"))
3150 {

Callers 1

ShowDemoWindowMethod · 0.85

Calls 6

ShowExampleMenuFileFunction · 0.85
HelpMarkerFunction · 0.85
DragFloatFunction · 0.85
sprintfFunction · 0.85
ImVec2Function · 0.85
GetCenterMethod · 0.80

Tested by

no test coverage detected