mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-06 04:58:47 +02:00
Viewports Added ImGui::GetMainViewport() as a way to get the bounds and work area of the host display. (#3789, #1542)
Viewports: Backport a few constructs from 'docking' branch. Viewports: Added ImGuiViewportFlags_IsPlatformWindow, ImGuiViewportFlags_IsPlatformMonitor, ImGuiViewportFlags_OwnedByApp (none of them were in docking branch yet). ImGuiViewportFlags_IsPlatformMonitor is merely there to convey future intent, not yet used. Reduce uses of io.DisplaySize. MainMenuBar: Backport work area handling code from 'docking' branch. Metrics: Backported "Viewports" debug visualizer from 'docking' branch. Demo: Rework 'Examples->Fullscreen Window'. Demo: 'Simple Overlay' demo now moves under main menu-bar (if any) using GetMainViewport()'s work area.
This commit is contained in:
@ -253,6 +253,7 @@ void ImGui::ShowDemoWindow(bool* p_open)
|
||||
// Examples Apps (accessible from the "Examples" menu)
|
||||
static bool show_app_main_menu_bar = false;
|
||||
static bool show_app_documents = false;
|
||||
|
||||
static bool show_app_console = false;
|
||||
static bool show_app_log = false;
|
||||
static bool show_app_layout = false;
|
||||
@ -320,7 +321,8 @@ void ImGui::ShowDemoWindow(bool* p_open)
|
||||
|
||||
// We specify a default position/size in case there's no data in the .ini file.
|
||||
// We only do it to make the demo applications a little more welcoming, but typically this isn't required.
|
||||
ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiCond_FirstUseEver);
|
||||
const ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
||||
ImGui::SetNextWindowPos(ImVec2(main_viewport->WorkPos.x + 650, main_viewport->WorkPos.y + 20), ImGuiCond_FirstUseEver);
|
||||
ImGui::SetNextWindowSize(ImVec2(550, 680), ImGuiCond_FirstUseEver);
|
||||
|
||||
// Main body of the Demo window starts here.
|
||||
@ -3231,7 +3233,7 @@ static void ShowDemoWindowPopups()
|
||||
ImGui::OpenPopup("Delete?");
|
||||
|
||||
// Always center this window when appearing
|
||||
ImVec2 center(ImGui::GetIO().DisplaySize.x * 0.5f, ImGui::GetIO().DisplaySize.y * 0.5f);
|
||||
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
|
||||
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
|
||||
|
||||
if (ImGui::BeginPopupModal("Delete?", NULL, ImGuiWindowFlags_AlwaysAutoResize))
|
||||
@ -6983,16 +6985,22 @@ static void ShowExampleAppConstrainedResize(bool* p_open)
|
||||
// + a context-menu to choose which corner of the screen to use.
|
||||
static void ShowExampleAppSimpleOverlay(bool* p_open)
|
||||
{
|
||||
const float DISTANCE = 10.0f;
|
||||
const float PAD = 10.0f;
|
||||
static int corner = 0;
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav;
|
||||
if (corner != -1)
|
||||
{
|
||||
window_flags |= ImGuiWindowFlags_NoMove;
|
||||
ImVec2 window_pos = ImVec2((corner & 1) ? io.DisplaySize.x - DISTANCE : DISTANCE, (corner & 2) ? io.DisplaySize.y - DISTANCE : DISTANCE);
|
||||
ImVec2 window_pos_pivot = ImVec2((corner & 1) ? 1.0f : 0.0f, (corner & 2) ? 1.0f : 0.0f);
|
||||
const ImGuiViewport* viewport = ImGui::GetMainViewport();
|
||||
ImVec2 work_pos = viewport->WorkPos; // Use work area to avoid menu-bar/task-bar, if any!
|
||||
ImVec2 work_size = viewport->WorkSize;
|
||||
ImVec2 window_pos, window_pos_pivot;
|
||||
window_pos.x = (corner & 1) ? (work_pos.x + work_size.x - PAD) : (work_pos.x + PAD);
|
||||
window_pos.y = (corner & 2) ? (work_pos.y + work_size.y - PAD) : (work_pos.y + PAD);
|
||||
window_pos_pivot.x = (corner & 1) ? 1.0f : 0.0f;
|
||||
window_pos_pivot.y = (corner & 2) ? 1.0f : 0.0f;
|
||||
ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always, window_pos_pivot);
|
||||
window_flags |= ImGuiWindowFlags_NoMove;
|
||||
}
|
||||
ImGui::SetNextWindowBgAlpha(0.35f); // Transparent background
|
||||
if (ImGui::Begin("Example: Simple overlay", p_open, window_flags))
|
||||
@ -7024,12 +7032,21 @@ static void ShowExampleAppSimpleOverlay(bool* p_open)
|
||||
// Demonstrate creating a window covering the entire screen/viewport
|
||||
static void ShowExampleAppFullscreen(bool* p_open)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
static bool use_work_area = true;
|
||||
static ImGuiWindowFlags flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings;
|
||||
ImGui::SetNextWindowPos(ImVec2(0, 0));
|
||||
ImGui::SetNextWindowSize(io.DisplaySize);
|
||||
|
||||
// We demonstrate using the full viewport area or the work area (without menu-bars, task-bars etc.)
|
||||
// Based on your use case you may want one of the other.
|
||||
const ImGuiViewport* viewport = ImGui::GetMainViewport();
|
||||
ImGui::SetNextWindowPos(use_work_area ? viewport->WorkPos : viewport->Pos);
|
||||
ImGui::SetNextWindowSize(use_work_area ? viewport->WorkSize : viewport->Size);
|
||||
|
||||
if (ImGui::Begin("Example: Fullscreen window", p_open, flags))
|
||||
{
|
||||
ImGui::Checkbox("Use work area instead of main area", &use_work_area);
|
||||
ImGui::SameLine();
|
||||
HelpMarker("Main Area = entire viewport,\nWork Area = entire viewport minus sections used by the main menu bars, task bars etc.\n\nEnable the main-menu bar in Examples menu to see the difference.");
|
||||
|
||||
ImGui::CheckboxFlags("ImGuiWindowFlags_NoBackground", &flags, ImGuiWindowFlags_NoBackground);
|
||||
ImGui::CheckboxFlags("ImGuiWindowFlags_NoDecoration", &flags, ImGuiWindowFlags_NoDecoration);
|
||||
ImGui::Indent();
|
||||
@ -7037,6 +7054,9 @@ static void ShowExampleAppFullscreen(bool* p_open)
|
||||
ImGui::CheckboxFlags("ImGuiWindowFlags_NoCollapse", &flags, ImGuiWindowFlags_NoCollapse);
|
||||
ImGui::CheckboxFlags("ImGuiWindowFlags_NoScrollbar", &flags, ImGuiWindowFlags_NoScrollbar);
|
||||
ImGui::Unindent();
|
||||
|
||||
if (p_open && ImGui::Button("Close this window"))
|
||||
*p_open = false;
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
@ -7050,16 +7070,19 @@ static void ShowExampleAppFullscreen(bool* p_open)
|
||||
// Read FAQ section "How can I have multiple widgets with the same label?" for details.
|
||||
static void ShowExampleAppWindowTitles(bool*)
|
||||
{
|
||||
const ImGuiViewport* viewport = ImGui::GetMainViewport();
|
||||
const ImVec2 base_pos = viewport->Pos;
|
||||
|
||||
// By default, Windows are uniquely identified by their title.
|
||||
// You can use the "##" and "###" markers to manipulate the display/ID.
|
||||
|
||||
// Using "##" to display same title but have unique identifier.
|
||||
ImGui::SetNextWindowPos(ImVec2(100, 100), ImGuiCond_FirstUseEver);
|
||||
ImGui::SetNextWindowPos(ImVec2(base_pos.x + 100, base_pos.y + 100), ImGuiCond_FirstUseEver);
|
||||
ImGui::Begin("Same title as another window##1");
|
||||
ImGui::Text("This is window 1.\nMy title is the same as window 2, but my identifier is unique.");
|
||||
ImGui::End();
|
||||
|
||||
ImGui::SetNextWindowPos(ImVec2(100, 200), ImGuiCond_FirstUseEver);
|
||||
ImGui::SetNextWindowPos(ImVec2(base_pos.x + 100, base_pos.y + 200), ImGuiCond_FirstUseEver);
|
||||
ImGui::Begin("Same title as another window##2");
|
||||
ImGui::Text("This is window 2.\nMy title is the same as window 1, but my identifier is unique.");
|
||||
ImGui::End();
|
||||
@ -7067,7 +7090,7 @@ static void ShowExampleAppWindowTitles(bool*)
|
||||
// Using "###" to display a changing title but keep a static identifier "AnimatedTitle"
|
||||
char buf[128];
|
||||
sprintf(buf, "Animated title %c %d###AnimatedTitle", "|/-\\"[(int)(ImGui::GetTime() / 0.25f) & 3], ImGui::GetFrameCount());
|
||||
ImGui::SetNextWindowPos(ImVec2(100, 300), ImGuiCond_FirstUseEver);
|
||||
ImGui::SetNextWindowPos(ImVec2(base_pos.x + 100, base_pos.y + 300), ImGuiCond_FirstUseEver);
|
||||
ImGui::Begin(buf);
|
||||
ImGui::Text("This window has a changing title.");
|
||||
ImGui::End();
|
||||
|
Reference in New Issue
Block a user