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