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

Function ShowExampleAppSimpleOverlay

core/src/imgui/imgui_demo.cpp:7086–7126  ·  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

7084// Demonstrate creating a simple static window with no decoration
7085// + a context-menu to choose which corner of the screen to use.
7086static void ShowExampleAppSimpleOverlay(bool* p_open)
7087{
7088 const float PAD = 10.0f;
7089 static int corner = 0;
7090 ImGuiIO& io = ImGui::GetIO();
7091 ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav;
7092 if (corner != -1)
7093 {
7094 const ImGuiViewport* viewport = ImGui::GetMainViewport();
7095 ImVec2 work_pos = viewport->WorkPos; // Use work area to avoid menu-bar/task-bar, if any!
7096 ImVec2 work_size = viewport->WorkSize;
7097 ImVec2 window_pos, window_pos_pivot;
7098 window_pos.x = (corner & 1) ? (work_pos.x + work_size.x - PAD) : (work_pos.x + PAD);
7099 window_pos.y = (corner & 2) ? (work_pos.y + work_size.y - PAD) : (work_pos.y + PAD);
7100 window_pos_pivot.x = (corner & 1) ? 1.0f : 0.0f;
7101 window_pos_pivot.y = (corner & 2) ? 1.0f : 0.0f;
7102 ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always, window_pos_pivot);
7103 window_flags |= ImGuiWindowFlags_NoMove;
7104 }
7105 ImGui::SetNextWindowBgAlpha(0.35f); // Transparent background
7106 if (ImGui::Begin("Example: Simple overlay", p_open, window_flags))
7107 {
7108 ImGui::Text("Simple overlay\n" "in the corner of the screen.\n" "(right-click to change position)");
7109 ImGui::Separator();
7110 if (ImGui::IsMousePosValid())
7111 ImGui::Text("Mouse Position: (%.1f,%.1f)", io.MousePos.x, io.MousePos.y);
7112 else
7113 ImGui::Text("Mouse Position: <invalid>");
7114 if (ImGui::BeginPopupContextWindow())
7115 {
7116 if (ImGui::MenuItem("Custom", NULL, corner == -1)) corner = -1;
7117 if (ImGui::MenuItem("Top-left", NULL, corner == 0)) corner = 0;
7118 if (ImGui::MenuItem("Top-right", NULL, corner == 1)) corner = 1;
7119 if (ImGui::MenuItem("Bottom-left", NULL, corner == 2)) corner = 2;
7120 if (ImGui::MenuItem("Bottom-right", NULL, corner == 3)) corner = 3;
7121 if (p_open && ImGui::MenuItem("Close")) *p_open = false;
7122 ImGui::EndPopup();
7123 }
7124 }
7125 ImGui::End();
7126}
7127
7128//-----------------------------------------------------------------------------
7129// [SECTION] Example App: Fullscreen window / ShowExampleAppFullscreen()

Callers 1

ShowDemoWindowMethod · 0.85

Calls 3

BeginFunction · 0.85
BeginPopupContextWindowFunction · 0.85
EndFunction · 0.85

Tested by

no test coverage detected