Demonstrate creating a simple static window with no decoration + a context-menu to choose which corner of the screen to use.
| 7084 | // Demonstrate creating a simple static window with no decoration |
| 7085 | // + a context-menu to choose which corner of the screen to use. |
| 7086 | static 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() |
no test coverage detected