MCPcopy Create free account
hub / github.com/Raais/ImStudio / ShowExampleAppSimpleOverlay

Function ShowExampleAppSimpleOverlay

src/third-party/imgui/imgui_demo.cpp:7269–7310  ·  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

7267// Demonstrate creating a simple static window with no decoration
7268// + a context-menu to choose which corner of the screen to use.
7269static void ShowExampleAppSimpleOverlay(bool* p_open)
7270{
7271 static int corner = 0;
7272 ImGuiIO& io = ImGui::GetIO();
7273 ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav;
7274 if (corner != -1)
7275 {
7276 const float PAD = 10.0f;
7277 const ImGuiViewport* viewport = ImGui::GetMainViewport();
7278 ImVec2 work_pos = viewport->WorkPos; // Use work area to avoid menu-bar/task-bar, if any!
7279 ImVec2 work_size = viewport->WorkSize;
7280 ImVec2 window_pos, window_pos_pivot;
7281 window_pos.x = (corner & 1) ? (work_pos.x + work_size.x - PAD) : (work_pos.x + PAD);
7282 window_pos.y = (corner & 2) ? (work_pos.y + work_size.y - PAD) : (work_pos.y + PAD);
7283 window_pos_pivot.x = (corner & 1) ? 1.0f : 0.0f;
7284 window_pos_pivot.y = (corner & 2) ? 1.0f : 0.0f;
7285 ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always, window_pos_pivot);
7286 window_flags |= ImGuiWindowFlags_NoMove;
7287 }
7288 ImGui::SetNextWindowBgAlpha(0.35f); // Transparent background
7289 if (ImGui::Begin("Example: Simple overlay", p_open, window_flags))
7290 {
7291 IMGUI_DEMO_MARKER("Examples/Simple Overlay");
7292 ImGui::Text("Simple overlay\n" "in the corner of the screen.\n" "(right-click to change position)");
7293 ImGui::Separator();
7294 if (ImGui::IsMousePosValid())
7295 ImGui::Text("Mouse Position: (%.1f,%.1f)", io.MousePos.x, io.MousePos.y);
7296 else
7297 ImGui::Text("Mouse Position: <invalid>");
7298 if (ImGui::BeginPopupContextWindow())
7299 {
7300 if (ImGui::MenuItem("Custom", NULL, corner == -1)) corner = -1;
7301 if (ImGui::MenuItem("Top-left", NULL, corner == 0)) corner = 0;
7302 if (ImGui::MenuItem("Top-right", NULL, corner == 1)) corner = 1;
7303 if (ImGui::MenuItem("Bottom-left", NULL, corner == 2)) corner = 2;
7304 if (ImGui::MenuItem("Bottom-right", NULL, corner == 3)) corner = 3;
7305 if (p_open && ImGui::MenuItem("Close")) *p_open = false;
7306 ImGui::EndPopup();
7307 }
7308 }
7309 ImGui::End();
7310}
7311
7312//-----------------------------------------------------------------------------
7313// [SECTION] Example App: Fullscreen window / ShowExampleAppFullscreen()

Callers 1

ShowDemoWindowMethod · 0.85

Calls 1

BeginPopupContextWindowFunction · 0.85

Tested by

no test coverage detected