MCPcopy Create free account
hub / github.com/BlitterStudio/amiberry / ShowExampleAppSimpleOverlay

Function ShowExampleAppSimpleOverlay

external/imgui/imgui_demo.cpp:10027–10075  ·  view source on GitHub ↗

Demonstrate creating a simple static window with no decoration + a context-menu to choose which corner of the screen to use.

Source from the content-addressed store, hash-verified

10025// Demonstrate creating a simple static window with no decoration
10026// + a context-menu to choose which corner of the screen to use.
10027static void ShowExampleAppSimpleOverlay(bool* p_open)
10028{
10029 static int location = 0;
10030 ImGuiIO& io = ImGui::GetIO();
10031 ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav;
10032 if (location >= 0)
10033 {
10034 const float PAD = 10.0f;
10035 const ImGuiViewport* viewport = ImGui::GetMainViewport();
10036 ImVec2 work_pos = viewport->WorkPos; // Use work area to avoid menu-bar/task-bar, if any!
10037 ImVec2 work_size = viewport->WorkSize;
10038 ImVec2 window_pos, window_pos_pivot;
10039 window_pos.x = (location & 1) ? (work_pos.x + work_size.x - PAD) : (work_pos.x + PAD);
10040 window_pos.y = (location & 2) ? (work_pos.y + work_size.y - PAD) : (work_pos.y + PAD);
10041 window_pos_pivot.x = (location & 1) ? 1.0f : 0.0f;
10042 window_pos_pivot.y = (location & 2) ? 1.0f : 0.0f;
10043 ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always, window_pos_pivot);
10044 window_flags |= ImGuiWindowFlags_NoMove;
10045 }
10046 else if (location == -2)
10047 {
10048 // Center window
10049 ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
10050 window_flags |= ImGuiWindowFlags_NoMove;
10051 }
10052 ImGui::SetNextWindowBgAlpha(0.35f); // Transparent background
10053 if (ImGui::Begin("Example: Simple overlay", p_open, window_flags))
10054 {
10055 IMGUI_DEMO_MARKER("Examples/Simple overlay"); // Scroll up to the beginning of this function to see overlay flags
10056 ImGui::Text("Simple overlay\n" "(right-click to change position)");
10057 ImGui::Separator();
10058 if (ImGui::IsMousePosValid())
10059 ImGui::Text("Mouse Position: (%.1f,%.1f)", io.MousePos.x, io.MousePos.y);
10060 else
10061 ImGui::Text("Mouse Position: <invalid>");
10062 if (ImGui::BeginPopupContextWindow())
10063 {
10064 if (ImGui::MenuItem("Custom", NULL, location == -1)) location = -1;
10065 if (ImGui::MenuItem("Center", NULL, location == -2)) location = -2;
10066 if (ImGui::MenuItem("Top-left", NULL, location == 0)) location = 0;
10067 if (ImGui::MenuItem("Top-right", NULL, location == 1)) location = 1;
10068 if (ImGui::MenuItem("Bottom-left", NULL, location == 2)) location = 2;
10069 if (ImGui::MenuItem("Bottom-right", NULL, location == 3)) location = 3;
10070 if (p_open && ImGui::MenuItem("Close")) *p_open = false;
10071 ImGui::EndPopup();
10072 }
10073 }
10074 ImGui::End();
10075}
10076
10077//-----------------------------------------------------------------------------
10078// [SECTION] Example App: Fullscreen window / ShowExampleAppFullscreen()

Callers 1

ShowDemoWindowMethod · 0.85

Calls 2

ImVec2Function · 0.85
GetCenterMethod · 0.80

Tested by

no test coverage detected