MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / ShowExampleAppSimpleOverlay

Function ShowExampleAppSimpleOverlay

Source/3rdParty/imgui/imgui_demo.cpp:9912–9960  ·  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

9910// Demonstrate creating a simple static window with no decoration
9911// + a context-menu to choose which corner of the screen to use.
9912static void ShowExampleAppSimpleOverlay(bool* p_open)
9913{
9914 static int location = 0;
9915 ImGuiIO& io = ImGui::GetIO();
9916 ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav;
9917 if (location >= 0)
9918 {
9919 const float PAD = 10.0f;
9920 const ImGuiViewport* viewport = ImGui::GetMainViewport();
9921 ImVec2 work_pos = viewport->WorkPos; // Use work area to avoid menu-bar/task-bar, if any!
9922 ImVec2 work_size = viewport->WorkSize;
9923 ImVec2 window_pos, window_pos_pivot;
9924 window_pos.x = (location & 1) ? (work_pos.x + work_size.x - PAD) : (work_pos.x + PAD);
9925 window_pos.y = (location & 2) ? (work_pos.y + work_size.y - PAD) : (work_pos.y + PAD);
9926 window_pos_pivot.x = (location & 1) ? 1.0f : 0.0f;
9927 window_pos_pivot.y = (location & 2) ? 1.0f : 0.0f;
9928 ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always, window_pos_pivot);
9929 window_flags |= ImGuiWindowFlags_NoMove;
9930 }
9931 else if (location == -2)
9932 {
9933 // Center window
9934 ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
9935 window_flags |= ImGuiWindowFlags_NoMove;
9936 }
9937 ImGui::SetNextWindowBgAlpha(0.35f); // Transparent background
9938 if (ImGui::Begin("Example: Simple overlay", p_open, window_flags))
9939 {
9940 IMGUI_DEMO_MARKER("Examples/Simple overlay"); // Scroll up to the beginning of this function to see overlay flags
9941 ImGui::Text("Simple overlay\n" "(right-click to change position)");
9942 ImGui::Separator();
9943 if (ImGui::IsMousePosValid())
9944 ImGui::Text("Mouse Position: (%.1f,%.1f)", io.MousePos.x, io.MousePos.y);
9945 else
9946 ImGui::Text("Mouse Position: <invalid>");
9947 if (ImGui::BeginPopupContextWindow())
9948 {
9949 if (ImGui::MenuItem("Custom", NULL, location == -1)) location = -1;
9950 if (ImGui::MenuItem("Center", NULL, location == -2)) location = -2;
9951 if (ImGui::MenuItem("Top-left", NULL, location == 0)) location = 0;
9952 if (ImGui::MenuItem("Top-right", NULL, location == 1)) location = 1;
9953 if (ImGui::MenuItem("Bottom-left", NULL, location == 2)) location = 2;
9954 if (ImGui::MenuItem("Bottom-right", NULL, location == 3)) location = 3;
9955 if (p_open && ImGui::MenuItem("Close")) *p_open = false;
9956 ImGui::EndPopup();
9957 }
9958 }
9959 ImGui::End();
9960}
9961
9962//-----------------------------------------------------------------------------
9963// [SECTION] Example App: Fullscreen window / ShowExampleAppFullscreen()

Callers 1

ShowDemoWindowMethod · 0.85

Calls 9

SetNextWindowPosFunction · 0.85
ImVec2Function · 0.85
SeparatorFunction · 0.85
BeginPopupContextWindowFunction · 0.85
MenuItemFunction · 0.85
EndFunction · 0.85
GetCenterMethod · 0.80
BeginFunction · 0.50
TextFunction · 0.50

Tested by

no test coverage detected