diff --git a/imgui.cpp b/imgui.cpp index 1db845f..a5c5660 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -525,6 +525,7 @@ MousePosPrev = ImVec2(-1,-1); MouseDoubleClickTime = 0.30f; MouseDoubleClickMaxDist = 6.0f; + DisplayVisibleMin = DisplayVisibleMax = ImVec2(0.0f, 0.0f); UserData = NULL; // User functions @@ -2474,7 +2475,6 @@ if (first_begin_of_the_frame) { window->DrawList->Clear(); - window->DrawList->PushTextureID(g.Font->ContainerAtlas->TexID); window->Visible = true; // New windows appears in front @@ -2490,13 +2490,22 @@ window->Pos = window->PosFloat = parent_window->DC.CursorPos; window->SizeFull = size; } + } - // Outer clipping rectangle - if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_ComboBox)) - PushClipRect(parent_window->ClipRectStack.back()); - else - PushClipRect(ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y)); + // Setup texture + window->DrawList->PushTextureID(g.Font->ContainerAtlas->TexID); + // Setup outer clipping rectangle + if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_ComboBox)) + PushClipRect(parent_window->ClipRectStack.back()); + else if (g.IO.DisplayVisibleMin.x != g.IO.DisplayVisibleMax.x && g.IO.DisplayVisibleMin.y != g.IO.DisplayVisibleMax.y) + PushClipRect(ImVec4(g.IO.DisplayVisibleMin.x, g.IO.DisplayVisibleMin.y, g.IO.DisplayVisibleMax.x, g.IO.DisplayVisibleMax.y)); + else + PushClipRect(ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y)); + + // Setup and draw window + if (first_begin_of_the_frame) + { // Seed ID stack with our window pointer window->IDStack.resize(0); ImGui::PushID(window); @@ -2531,11 +2540,14 @@ // Clamp into view if (!(window->Flags & ImGuiWindowFlags_ChildWindow) && !(window->Flags & ImGuiWindowFlags_Tooltip)) { + // FIXME: Parameterize padding. const ImVec2 pad = ImVec2(window->FontSize()*2.0f, window->FontSize()*2.0f); // FIXME: Parametrize of clarify this behavior. if (g.IO.DisplaySize.x > 0.0f && g.IO.DisplaySize.y > 0.0f) // Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized window when initializing or minimizing. { - window->PosFloat = ImMax(window->PosFloat + window->Size, pad) - window->Size; - window->PosFloat = ImMin(window->PosFloat, ImVec2(g.IO.DisplaySize.x, g.IO.DisplaySize.y) - pad); + ImVec2 clip_min = pad; + ImVec2 clip_max = g.IO.DisplaySize - pad; + window->PosFloat = ImMax(window->PosFloat + window->Size, clip_min) - window->Size; + window->PosFloat = ImMin(window->PosFloat, clip_max); } window->SizeFull = ImMax(window->SizeFull, style.WindowMinSize); } @@ -2783,17 +2795,6 @@ PopClipRect(); } } - else - { - // Short path when we do multiple Begin in the same frame. - window->DrawList->PushTextureID(g.Font->ContainerAtlas->TexID); - - // Outer clipping rectangle - if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_ComboBox)) - PushClipRect(parent_window->ClipRectStack.back()); - else - PushClipRect(ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y)); - } // Inner clipping rectangle // We set this up after processing the resize grip so that our clip rectangle doesn't lag by a frame @@ -3647,7 +3648,7 @@ if (!ItemAdd(bb, &id)) return false; - bool hovered, held; + bool hovered, held; bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true); return pressed; diff --git a/imgui.cpp b/imgui.cpp index 1db845f..a5c5660 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -525,6 +525,7 @@ MousePosPrev = ImVec2(-1,-1); MouseDoubleClickTime = 0.30f; MouseDoubleClickMaxDist = 6.0f; + DisplayVisibleMin = DisplayVisibleMax = ImVec2(0.0f, 0.0f); UserData = NULL; // User functions @@ -2474,7 +2475,6 @@ if (first_begin_of_the_frame) { window->DrawList->Clear(); - window->DrawList->PushTextureID(g.Font->ContainerAtlas->TexID); window->Visible = true; // New windows appears in front @@ -2490,13 +2490,22 @@ window->Pos = window->PosFloat = parent_window->DC.CursorPos; window->SizeFull = size; } + } - // Outer clipping rectangle - if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_ComboBox)) - PushClipRect(parent_window->ClipRectStack.back()); - else - PushClipRect(ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y)); + // Setup texture + window->DrawList->PushTextureID(g.Font->ContainerAtlas->TexID); + // Setup outer clipping rectangle + if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_ComboBox)) + PushClipRect(parent_window->ClipRectStack.back()); + else if (g.IO.DisplayVisibleMin.x != g.IO.DisplayVisibleMax.x && g.IO.DisplayVisibleMin.y != g.IO.DisplayVisibleMax.y) + PushClipRect(ImVec4(g.IO.DisplayVisibleMin.x, g.IO.DisplayVisibleMin.y, g.IO.DisplayVisibleMax.x, g.IO.DisplayVisibleMax.y)); + else + PushClipRect(ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y)); + + // Setup and draw window + if (first_begin_of_the_frame) + { // Seed ID stack with our window pointer window->IDStack.resize(0); ImGui::PushID(window); @@ -2531,11 +2540,14 @@ // Clamp into view if (!(window->Flags & ImGuiWindowFlags_ChildWindow) && !(window->Flags & ImGuiWindowFlags_Tooltip)) { + // FIXME: Parameterize padding. const ImVec2 pad = ImVec2(window->FontSize()*2.0f, window->FontSize()*2.0f); // FIXME: Parametrize of clarify this behavior. if (g.IO.DisplaySize.x > 0.0f && g.IO.DisplaySize.y > 0.0f) // Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized window when initializing or minimizing. { - window->PosFloat = ImMax(window->PosFloat + window->Size, pad) - window->Size; - window->PosFloat = ImMin(window->PosFloat, ImVec2(g.IO.DisplaySize.x, g.IO.DisplaySize.y) - pad); + ImVec2 clip_min = pad; + ImVec2 clip_max = g.IO.DisplaySize - pad; + window->PosFloat = ImMax(window->PosFloat + window->Size, clip_min) - window->Size; + window->PosFloat = ImMin(window->PosFloat, clip_max); } window->SizeFull = ImMax(window->SizeFull, style.WindowMinSize); } @@ -2783,17 +2795,6 @@ PopClipRect(); } } - else - { - // Short path when we do multiple Begin in the same frame. - window->DrawList->PushTextureID(g.Font->ContainerAtlas->TexID); - - // Outer clipping rectangle - if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_ComboBox)) - PushClipRect(parent_window->ClipRectStack.back()); - else - PushClipRect(ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y)); - } // Inner clipping rectangle // We set this up after processing the resize grip so that our clip rectangle doesn't lag by a frame @@ -3647,7 +3648,7 @@ if (!ItemAdd(bb, &id)) return false; - bool hovered, held; + bool hovered, held; bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true); return pressed; diff --git a/imgui.h b/imgui.h index 4e7256d..2d9eb9a 100644 --- a/imgui.h +++ b/imgui.h @@ -501,6 +501,8 @@ ImFontAtlas* Fonts; // // Load and assemble one or more fonts into a single tightly packed texture. Output to Fonts array. float FontGlobalScale; // = 1.0f // Global scale all fonts bool FontAllowUserScaling; // = false // Allow user scaling text of individual window with CTRL+Wheel. + ImVec2 DisplayVisibleMin; // (0.0f,0.0f) // If you use DisplaySize as a virtual space larger than your screen, set DisplayVisibleMin/Max to the visible area. + ImVec2 DisplayVisibleMax; // (0.0f,0.0f) // If the values are the same, we defaults to Min=(0.0f) and Max=DisplaySize //------------------------------------------------------------------ // User Functions