Skip to content

Commit dd02a18

Browse files
committed
Windows: Amend 6b0cf2e to facilitate working in viewport branch + handle safe area padding and ConfigWindowsMoveFromTitleBarOnly.
1 parent 6b0cf2e commit dd02a18

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

imgui.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ static void UpdateMouseInputs();
852852
static void UpdateMouseWheel();
853853
static void UpdateTabFocus();
854854
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);
856856
static void RenderWindowOuterBorders(ImGuiWindow* window);
857857
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);
858858
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)
50195019

50205020
// Handle resize for: Resize Grips, Borders, Gamepad
50215021
// 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)
50235023
{
50245024
ImGuiContext& g = *GImGui;
50255025
ImGuiWindowFlags flags = window->Flags;
@@ -5071,8 +5071,8 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s
50715071
// Resize from any of the four corners
50725072
// We don't use an incremental MouseDelta but rather compute an absolute target size based on mouse position
50735073
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);
50765076
corner_target = ImClamp(corner_target, clamp_min, clamp_max);
50775077
CalcResizePosSizeFromAnyCorner(window, corner_target, grip.CornerPosN, &pos_target, &size_target);
50785078
}
@@ -5099,8 +5099,8 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s
50995099
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
51005100
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
51015101
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);
51045104
border_target = ImClamp(border_target, clamp_min, clamp_max);
51055105
CalcResizePosSizeFromAnyCorner(window, border_target, border_posn, &pos_target, &size_target);
51065106
}
@@ -5123,7 +5123,7 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s
51235123
{
51245124
const float NAV_RESIZE_SPEED = 600.0f;
51255125
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);
51275127
g.NavWindowingToggleLayer = false;
51285128
g.NavDisableMouseHover = true;
51295129
resize_grip_col[0] = GetColorU32(ImGuiCol_ResizeGripActive);
@@ -5148,13 +5148,13 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s
51485148
return ret_auto_fit;
51495149
}
51505150

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)
51525152
{
51535153
ImGuiContext& g = *GImGui;
51545154
ImVec2 size_for_clamping = window->Size;
51555155
if (g.IO.ConfigWindowsMoveFromTitleBarOnly && !(window->Flags & ImGuiWindowFlags_NoTitleBar))
51565156
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);
51585158
}
51595159

51605160
static void ImGui::RenderWindowOuterBorders(ImGuiWindow* window)
@@ -5668,17 +5668,17 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
56685668
else if ((flags & ImGuiWindowFlags_Tooltip) != 0 && !window_pos_set_by_api && !window_is_child_tooltip)
56695669
window->Pos = FindBestWindowPosForPopup(window);
56705670

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+
56715677
// Clamp position/size so window stays visible within its viewport or monitor
56725678
// 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());
56745679
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);
56825682
window->Pos = ImFloor(window->Pos);
56835683

56845684
// 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)
57055705
const int resize_grip_count = g.IO.ConfigWindowsResizeFromEdges ? 2 : 1; // Allow resize from lower-left if we have the mouse cursor feedback for it.
57065706
const float resize_grip_draw_size = IM_FLOOR(ImMax(g.FontSize * 1.35f, window->WindowRounding + 1.0f + g.FontSize * 0.2f));
57075707
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))
57095709
use_current_size_for_scrollbar_x = use_current_size_for_scrollbar_y = true;
57105710
window->ResizeBorderHeld = (signed char)border_held;
57115711

0 commit comments

Comments
 (0)