@@ -852,7 +852,7 @@ static void UpdateMouseInputs();
852
852
static void UpdateMouseWheel();
853
853
static void UpdateTabFocus();
854
854
static void UpdateDebugToolItemPicker();
855
- static bool UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4]);
855
+ static bool UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4], const ImRect& visibility_rect );
856
856
static void RenderWindowOuterBorders(ImGuiWindow* window);
857
857
static void RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar_rect, bool title_bar_is_highlight, int resize_grip_count, const ImU32 resize_grip_col[4], float resize_grip_draw_size);
858
858
static void RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& title_bar_rect, const char* name, bool* p_open);
@@ -5019,7 +5019,7 @@ ImGuiID ImGui::GetWindowResizeID(ImGuiWindow* window, int n)
5019
5019
5020
5020
// Handle resize for: Resize Grips, Borders, Gamepad
5021
5021
// Return true when using auto-fit (double click on resize grip)
5022
- static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4])
5022
+ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4], const ImRect& visibility_rect )
5023
5023
{
5024
5024
ImGuiContext& g = *GImGui;
5025
5025
ImGuiWindowFlags flags = window->Flags;
@@ -5071,8 +5071,8 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s
5071
5071
// Resize from any of the four corners
5072
5072
// We don't use an incremental MouseDelta but rather compute an absolute target size based on mouse position
5073
5073
ImVec2 corner_target = g.IO.MousePos - g.ActiveIdClickOffset + ImLerp(grip.InnerDir * grip_hover_outer_size, grip.InnerDir * -grip_hover_inner_size, grip.CornerPosN); // Corner of the window corresponding to our corner grip
5074
- ImVec2 clamp_min = ImVec2(grip.CornerPosN.x == 1 ? g.Style.DisplayWindowPadding. x : -FLT_MAX, grip.CornerPosN.y == 1 ? g.Style.DisplayWindowPadding .y : -FLT_MAX);
5075
- ImVec2 clamp_max = ImVec2(grip.CornerPosN.x == 0 ? g.IO.DisplaySize.x - g.Style.DisplayWindowPadding.x : FLT_MAX, grip.CornerPosN.y == 0 ? g.IO.DisplaySize.y - g.Style.DisplayWindowPadding.y : FLT_MAX);
5074
+ ImVec2 clamp_min = ImVec2(grip.CornerPosN.x == 1.0f ? visibility_rect.Min. x : -FLT_MAX, grip.CornerPosN.y == 1.0f ? visibility_rect.Min .y : -FLT_MAX);
5075
+ ImVec2 clamp_max = ImVec2(grip.CornerPosN.x == 0.0f ? visibility_rect.Max.x : + FLT_MAX, grip.CornerPosN.y == 0.0f ? visibility_rect.Max.y : + FLT_MAX);
5076
5076
corner_target = ImClamp(corner_target, clamp_min, clamp_max);
5077
5077
CalcResizePosSizeFromAnyCorner(window, corner_target, grip.CornerPosN, &pos_target, &size_target);
5078
5078
}
@@ -5099,8 +5099,8 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s
5099
5099
if (border_n == 1) { border_posn = ImVec2(1, 0); border_target.x = (g.IO.MousePos.x - g.ActiveIdClickOffset.x + WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS); } // Right
5100
5100
if (border_n == 2) { border_posn = ImVec2(0, 1); border_target.y = (g.IO.MousePos.y - g.ActiveIdClickOffset.y + WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS); } // Bottom
5101
5101
if (border_n == 3) { border_posn = ImVec2(0, 0); border_target.x = (g.IO.MousePos.x - g.ActiveIdClickOffset.x + WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS); } // Left
5102
- ImVec2 clamp_min = ImVec2(border_n == 1 ? g.Style.DisplayWindowPadding. x : -FLT_MAX, border_n == 2 ? g.Style.DisplayWindowPadding .y : -FLT_MAX);
5103
- ImVec2 clamp_max = ImVec2(border_n == 3 ? g.IO.DisplaySize.x - g.Style.DisplayWindowPadding.x : FLT_MAX, border_n == 0 ? g.IO.DisplaySize.y - g.Style.DisplayWindowPadding.y : FLT_MAX);
5102
+ ImVec2 clamp_min = ImVec2(border_n == 1 ? visibility_rect.Min. x : -FLT_MAX, border_n == 2 ? visibility_rect.Min .y : -FLT_MAX);
5103
+ ImVec2 clamp_max = ImVec2(border_n == 3 ? visibility_rect.Max.x : + FLT_MAX, border_n == 0 ? visibility_rect.Max.y : + FLT_MAX);
5104
5104
border_target = ImClamp(border_target, clamp_min, clamp_max);
5105
5105
CalcResizePosSizeFromAnyCorner(window, border_target, border_posn, &pos_target, &size_target);
5106
5106
}
@@ -5123,7 +5123,7 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s
5123
5123
{
5124
5124
const float NAV_RESIZE_SPEED = 600.0f;
5125
5125
nav_resize_delta *= ImFloor(NAV_RESIZE_SPEED * g.IO.DeltaTime * ImMin(g.IO.DisplayFramebufferScale.x, g.IO.DisplayFramebufferScale.y));
5126
- nav_resize_delta = ImClamp (nav_resize_delta, g.Style.DisplayWindowPadding - window->Pos - window->Size, ImVec2(FLT_MAX, FLT_MAX) );
5126
+ nav_resize_delta = ImMax (nav_resize_delta, visibility_rect.Min - window->Pos - window->Size);
5127
5127
g.NavWindowingToggleLayer = false;
5128
5128
g.NavDisableMouseHover = true;
5129
5129
resize_grip_col[0] = GetColorU32(ImGuiCol_ResizeGripActive);
@@ -5148,13 +5148,13 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s
5148
5148
return ret_auto_fit;
5149
5149
}
5150
5150
5151
- static inline void ClampWindowRect(ImGuiWindow* window, const ImRect& viewport_rect, const ImVec2& padding )
5151
+ static inline void ClampWindowRect(ImGuiWindow* window, const ImRect& visibility_rect )
5152
5152
{
5153
5153
ImGuiContext& g = *GImGui;
5154
5154
ImVec2 size_for_clamping = window->Size;
5155
5155
if (g.IO.ConfigWindowsMoveFromTitleBarOnly && !(window->Flags & ImGuiWindowFlags_NoTitleBar))
5156
5156
size_for_clamping.y = window->TitleBarHeight();
5157
- window->Pos = ImClamp(window->Pos, viewport_rect .Min + padding - size_for_clamping, viewport_rect .Max - padding );
5157
+ window->Pos = ImClamp(window->Pos, visibility_rect .Min - size_for_clamping, visibility_rect .Max);
5158
5158
}
5159
5159
5160
5160
static void ImGui::RenderWindowOuterBorders(ImGuiWindow* window)
@@ -5668,17 +5668,17 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
5668
5668
else if ((flags & ImGuiWindowFlags_Tooltip) != 0 && !window_pos_set_by_api && !window_is_child_tooltip)
5669
5669
window->Pos = FindBestWindowPosForPopup(window);
5670
5670
5671
+ // Calculate the range of allowed position for that window (to be movable and visible past safe area padding)
5672
+ // When clamping to stay visible, we will enforce that window->Pos stays inside of visibility_rect.
5673
+ ImRect viewport_rect(GetViewportRect());
5674
+ ImVec2 visibility_padding = ImMax(style.DisplayWindowPadding, style.DisplaySafeAreaPadding);
5675
+ ImRect visibility_rect(viewport_rect.Min + visibility_padding, viewport_rect.Max - visibility_padding);
5676
+
5671
5677
// Clamp position/size so window stays visible within its viewport or monitor
5672
5678
// Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized window when initializing or minimizing.
5673
- ImRect viewport_rect(GetViewportRect());
5674
5679
if (!window_pos_set_by_api && !(flags & ImGuiWindowFlags_ChildWindow) && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0)
5675
- {
5676
- ImVec2 clamp_padding = ImMax(style.DisplayWindowPadding, style.DisplaySafeAreaPadding);
5677
- if (viewport_rect.GetWidth() > 0 && viewport_rect.GetHeight() > 0.0f)
5678
- {
5679
- ClampWindowRect(window, viewport_rect, clamp_padding);
5680
- }
5681
- }
5680
+ if (viewport_rect.GetWidth() > 0.0f && viewport_rect.GetHeight() > 0.0f)
5681
+ ClampWindowRect(window, visibility_rect);
5682
5682
window->Pos = ImFloor(window->Pos);
5683
5683
5684
5684
// Lock window rounding for the frame (so that altering them doesn't cause inconsistencies)
@@ -5705,7 +5705,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
5705
5705
const int resize_grip_count = g.IO.ConfigWindowsResizeFromEdges ? 2 : 1; // Allow resize from lower-left if we have the mouse cursor feedback for it.
5706
5706
const float resize_grip_draw_size = IM_FLOOR(ImMax(g.FontSize * 1.35f, window->WindowRounding + 1.0f + g.FontSize * 0.2f));
5707
5707
if (!window->Collapsed)
5708
- if (UpdateWindowManualResize(window, size_auto_fit, &border_held, resize_grip_count, &resize_grip_col[0]))
5708
+ if (UpdateWindowManualResize(window, size_auto_fit, &border_held, resize_grip_count, &resize_grip_col[0], visibility_rect ))
5709
5709
use_current_size_for_scrollbar_x = use_current_size_for_scrollbar_y = true;
5710
5710
window->ResizeBorderHeld = (signed char)border_held;
5711
5711
0 commit comments