Demonstrate creating a simple static window with no decoration + a context-menu to choose which corner of the screen to use.
| 9692 | // Demonstrate creating a simple static window with no decoration |
| 9693 | // + a context-menu to choose which corner of the screen to use. |
| 9694 | static void ShowExampleAppSimpleOverlay(bool* p_open) |
| 9695 | { |
| 9696 | static int location = 0; |
| 9697 | ImGuiIO& io = ImGui::GetIO(); |
| 9698 | ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav; |
| 9699 | if (location >= 0) |
| 9700 | { |
| 9701 | const float PAD = 10.0f; |
| 9702 | const ImGuiViewport* viewport = ImGui::GetMainViewport(); |
| 9703 | ImVec2 work_pos = viewport->WorkPos; // Use work area to avoid menu-bar/task-bar, if any! |
| 9704 | ImVec2 work_size = viewport->WorkSize; |
| 9705 | ImVec2 window_pos, window_pos_pivot; |
| 9706 | window_pos.x = (location & 1) ? (work_pos.x + work_size.x - PAD) : (work_pos.x + PAD); |
| 9707 | window_pos.y = (location & 2) ? (work_pos.y + work_size.y - PAD) : (work_pos.y + PAD); |
| 9708 | window_pos_pivot.x = (location & 1) ? 1.0f : 0.0f; |
| 9709 | window_pos_pivot.y = (location & 2) ? 1.0f : 0.0f; |
| 9710 | ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always, window_pos_pivot); |
| 9711 | window_flags |= ImGuiWindowFlags_NoMove; |
| 9712 | } |
| 9713 | else if (location == -2) |
| 9714 | { |
| 9715 | // Center window |
| 9716 | ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Always, ImVec2(0.5f, 0.5f)); |
| 9717 | window_flags |= ImGuiWindowFlags_NoMove; |
| 9718 | } |
| 9719 | ImGui::SetNextWindowBgAlpha(0.35f); // Transparent background |
| 9720 | if (ImGui::Begin("Example: Simple overlay", p_open, window_flags)) |
| 9721 | { |
| 9722 | IMGUI_DEMO_MARKER("Examples/Simple Overlay"); |
| 9723 | ImGui::Text("Simple overlay\n" "(right-click to change position)"); |
| 9724 | ImGui::Separator(); |
| 9725 | if (ImGui::IsMousePosValid()) |
| 9726 | ImGui::Text("Mouse Position: (%.1f,%.1f)", io.MousePos.x, io.MousePos.y); |
| 9727 | else |
| 9728 | ImGui::Text("Mouse Position: <invalid>"); |
| 9729 | if (ImGui::BeginPopupContextWindow()) |
| 9730 | { |
| 9731 | if (ImGui::MenuItem("Custom", NULL, location == -1)) location = -1; |
| 9732 | if (ImGui::MenuItem("Center", NULL, location == -2)) location = -2; |
| 9733 | if (ImGui::MenuItem("Top-left", NULL, location == 0)) location = 0; |
| 9734 | if (ImGui::MenuItem("Top-right", NULL, location == 1)) location = 1; |
| 9735 | if (ImGui::MenuItem("Bottom-left", NULL, location == 2)) location = 2; |
| 9736 | if (ImGui::MenuItem("Bottom-right", NULL, location == 3)) location = 3; |
| 9737 | if (p_open && ImGui::MenuItem("Close")) *p_open = false; |
| 9738 | ImGui::EndPopup(); |
| 9739 | } |
| 9740 | } |
| 9741 | ImGui::End(); |
| 9742 | } |
| 9743 | |
| 9744 | //----------------------------------------------------------------------------- |
| 9745 | // [SECTION] Example App: Fullscreen window / ShowExampleAppFullscreen() |
no test coverage detected