Windows: fixed single-axis auto-sizing (via double-clicking a border) to take account of remaining scrollbar on the other axis. (#9060)

Potentially now should apply same logic to the other resizing path also described in #9060
This commit is contained in:
ocornut
2025-11-10 19:36:16 +01:00
parent 86daa8930e
commit 7537ba2b44
3 changed files with 15 additions and 10 deletions

View File

@@ -71,6 +71,8 @@ Other Changes:
- Windows: io.ConfigWindowsMoveFromTitleBarOnly is latched during Begin(), - Windows: io.ConfigWindowsMoveFromTitleBarOnly is latched during Begin(),
effectively allowing to change the value on a per-window basis (although effectively allowing to change the value on a per-window basis (although
there is a better internal mechanism for it). there is a better internal mechanism for it).
- Windows: fixed single-axis auto-sizing (via double-clicking a border) to
take account of remaining scrollbar on the other axis. (#9060)
- Disabled: fixed a bug when a previously enabled item that got nav focus - Disabled: fixed a bug when a previously enabled item that got nav focus
and then turns disabled could still be activated using keyboard. (#9036) and then turns disabled could still be activated using keyboard. (#9036)
- InputText: when buffer is not resizable, trying to paste contents that - InputText: when buffer is not resizable, trying to paste contents that

View File

@@ -1338,7 +1338,7 @@ static void UpdateFontsEndFrame();
static void UpdateTexturesNewFrame(); static void UpdateTexturesNewFrame();
static void UpdateTexturesEndFrame(); static void UpdateTexturesEndFrame();
static void UpdateSettings(); static void UpdateSettings();
static int UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_hovered, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4], const ImRect& visibility_rect); static int UpdateWindowManualResize(ImGuiWindow* window, int* border_hovered, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4], const ImRect& visibility_rect);
static void RenderWindowOuterBorders(ImGuiWindow* window); static void RenderWindowOuterBorders(ImGuiWindow* window);
static void RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar_rect, bool title_bar_is_highlight, bool handle_borders_and_resize_grips, int resize_grip_count, const ImU32 resize_grip_col[4], float resize_grip_draw_size); static void RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar_rect, bool title_bar_is_highlight, bool handle_borders_and_resize_grips, int resize_grip_count, const ImU32 resize_grip_col[4], float resize_grip_draw_size);
static void RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& title_bar_rect, const char* name, bool* p_open); static void RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& title_bar_rect, const char* name, bool* p_open);
@@ -6625,14 +6625,16 @@ static void CalcWindowContentSizes(ImGuiWindow* window, ImVec2* content_size_cur
content_size_ideal->y = (window->ContentSizeExplicit.y != 0.0f) ? window->ContentSizeExplicit.y : ImTrunc64(ImMax(window->DC.CursorMaxPos.y, window->DC.IdealMaxPos.y) - window->DC.CursorStartPos.y); content_size_ideal->y = (window->ContentSizeExplicit.y != 0.0f) ? window->ContentSizeExplicit.y : ImTrunc64(ImMax(window->DC.CursorMaxPos.y, window->DC.IdealMaxPos.y) - window->DC.CursorStartPos.y);
} }
static ImVec2 CalcWindowAutoFitSize(ImGuiWindow* window, const ImVec2& size_contents) static ImVec2 CalcWindowAutoFitSize(ImGuiWindow* window, const ImVec2& size_contents, int axis_mask)
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
ImGuiStyle& style = g.Style; ImGuiStyle& style = g.Style;
const float decoration_w_without_scrollbars = window->DecoOuterSizeX1 + window->DecoOuterSizeX2 - window->ScrollbarSizes.x; const float decoration_w_without_scrollbars = window->DecoOuterSizeX1 + window->DecoOuterSizeX2 - window->ScrollbarSizes.x;
const float decoration_h_without_scrollbars = window->DecoOuterSizeY1 + window->DecoOuterSizeY2 - window->ScrollbarSizes.y; const float decoration_h_without_scrollbars = window->DecoOuterSizeY1 + window->DecoOuterSizeY2 - window->ScrollbarSizes.y;
ImVec2 size_pad = window->WindowPadding * 2.0f; ImVec2 size_pad = window->WindowPadding * 2.0f;
ImVec2 size_desired = size_contents + size_pad + ImVec2(decoration_w_without_scrollbars, decoration_h_without_scrollbars); ImVec2 size_desired;
size_desired[ImGuiAxis_X] = (axis_mask & 1) ? size_contents.x + size_pad.x + decoration_w_without_scrollbars : window->Size.x;
size_desired[ImGuiAxis_Y] = (axis_mask & 2) ? size_contents.y + size_pad.y + decoration_h_without_scrollbars : window->Size.y;
// Determine maximum window size // Determine maximum window size
// Child windows are layed within their parent (unless they are also popups/menus) and thus have no restriction // Child windows are layed within their parent (unless they are also popups/menus) and thus have no restriction
@@ -6674,7 +6676,7 @@ ImVec2 ImGui::CalcWindowNextAutoFitSize(ImGuiWindow* window)
ImVec2 size_contents_current; ImVec2 size_contents_current;
ImVec2 size_contents_ideal; ImVec2 size_contents_ideal;
CalcWindowContentSizes(window, &size_contents_current, &size_contents_ideal); CalcWindowContentSizes(window, &size_contents_current, &size_contents_ideal);
ImVec2 size_auto_fit = CalcWindowAutoFitSize(window, size_contents_ideal); ImVec2 size_auto_fit = CalcWindowAutoFitSize(window, size_contents_ideal, ~0);
ImVec2 size_final = CalcWindowSizeAfterConstraint(window, size_auto_fit); ImVec2 size_final = CalcWindowSizeAfterConstraint(window, size_auto_fit);
return size_final; return size_final;
} }
@@ -6780,7 +6782,7 @@ ImGuiID ImGui::GetWindowResizeBorderID(ImGuiWindow* window, ImGuiDir dir)
// Handle resize for: Resize Grips, Borders, Gamepad // Handle resize for: Resize Grips, Borders, Gamepad
// Return true when using auto-fit (double-click on resize grip) // Return true when using auto-fit (double-click on resize grip)
static int ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_hovered, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4], const ImRect& visibility_rect) static int ImGui::UpdateWindowManualResize(ImGuiWindow* window, int* border_hovered, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4], const ImRect& visibility_rect)
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
ImGuiWindowFlags flags = window->Flags; ImGuiWindowFlags flags = window->Flags;
@@ -6830,6 +6832,7 @@ static int ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& si
if (held && g.IO.MouseDoubleClicked[0]) if (held && g.IO.MouseDoubleClicked[0])
{ {
// Auto-fit when double-clicking // Auto-fit when double-clicking
ImVec2 size_auto_fit = CalcWindowAutoFitSize(window, window->ContentSizeIdeal, ~0);
size_target = CalcWindowSizeAfterConstraint(window, size_auto_fit); size_target = CalcWindowSizeAfterConstraint(window, size_auto_fit);
ret_auto_fit_mask = 0x03; // Both axes ret_auto_fit_mask = 0x03; // Both axes
ClearActiveID(); ClearActiveID();
@@ -6876,10 +6879,10 @@ static int ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& si
if (held && g.IO.MouseDoubleClicked[0]) if (held && g.IO.MouseDoubleClicked[0])
{ {
// Double-clicking bottom or right border auto-fit on this axis // Double-clicking bottom or right border auto-fit on this axis
// FIXME: CalcWindowAutoFitSize() doesn't take into account that only one side may be auto-fit when calculating scrollbars.
// FIXME: Support top and right borders: rework CalcResizePosSizeFromAnyCorner() to be reusable in both cases. // FIXME: Support top and right borders: rework CalcResizePosSizeFromAnyCorner() to be reusable in both cases.
if (border_n == 1 || border_n == 3) // Right and bottom border if (border_n == 1 || border_n == 3) // Right and bottom border
{ {
ImVec2 size_auto_fit = CalcWindowAutoFitSize(window, window->ContentSizeIdeal, 1 << axis);
size_target[axis] = CalcWindowSizeAfterConstraint(window, size_auto_fit)[axis]; size_target[axis] = CalcWindowSizeAfterConstraint(window, size_auto_fit)[axis];
ret_auto_fit_mask |= (1 << axis); ret_auto_fit_mask |= (1 << axis);
hovered = held = false; // So border doesn't show highlighted at new position hovered = held = false; // So border doesn't show highlighted at new position
@@ -7575,7 +7578,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
window->ScrollbarSizes = ImVec2(0.0f, 0.0f); window->ScrollbarSizes = ImVec2(0.0f, 0.0f);
// Calculate auto-fit size, handle automatic resize // Calculate auto-fit size, handle automatic resize
const ImVec2 size_auto_fit = CalcWindowAutoFitSize(window, window->ContentSizeIdeal); const ImVec2 size_auto_fit = CalcWindowAutoFitSize(window, window->ContentSizeIdeal, ~0);
if ((flags & ImGuiWindowFlags_AlwaysAutoResize) && !window->Collapsed) if ((flags & ImGuiWindowFlags_AlwaysAutoResize) && !window->Collapsed)
{ {
// Using SetNextWindowSize() overrides ImGuiWindowFlags_AlwaysAutoResize, so it can be used on tooltips/popups, etc. // Using SetNextWindowSize() overrides ImGuiWindowFlags_AlwaysAutoResize, so it can be used on tooltips/popups, etc.
@@ -7708,7 +7711,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
const float resize_grip_draw_size = IM_TRUNC(ImMax(g.FontSize * 1.10f, window->WindowRounding + 1.0f + g.FontSize * 0.2f)); const float resize_grip_draw_size = IM_TRUNC(ImMax(g.FontSize * 1.10f, window->WindowRounding + 1.0f + g.FontSize * 0.2f));
if (handle_borders_and_resize_grips && !window->Collapsed) if (handle_borders_and_resize_grips && !window->Collapsed)
if (int auto_fit_mask = UpdateWindowManualResize(window, size_auto_fit, &border_hovered, &border_held, resize_grip_count, &resize_grip_col[0], visibility_rect)) if (int auto_fit_mask = UpdateWindowManualResize(window, &border_hovered, &border_held, resize_grip_count, &resize_grip_col[0], visibility_rect))
{ {
if (auto_fit_mask & (1 << ImGuiAxis_X)) if (auto_fit_mask & (1 << ImGuiAxis_X))
use_current_size_for_scrollbar_x = true; use_current_size_for_scrollbar_x = true;
@@ -7958,7 +7961,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
g.TooltipPreviousWindow = window; g.TooltipPreviousWindow = window;
// Set default BgClickFlags // Set default BgClickFlags
// This is set at the end of this function, so UpdateManualResize()/ClampWindowPos() may use last-frame value if overriden by user code. // This is set at the end of this function, so UpdateWindowManualResize()/ClampWindowPos() may use last-frame value if overriden by user code.
// FIXME: The general intent is that we will later expose config options to default to enable scrolling + select scrolling mouse button. // FIXME: The general intent is that we will later expose config options to default to enable scrolling + select scrolling mouse button.
window->BgClickFlags = (flags & ImGuiWindowFlags_ChildWindow) ? parent_window->BgClickFlags : (g.IO.ConfigWindowsMoveFromTitleBarOnly ? ImGuiWindowBgClickFlags_None : ImGuiWindowBgClickFlags_Move); window->BgClickFlags = (flags & ImGuiWindowFlags_ChildWindow) ? parent_window->BgClickFlags : (g.IO.ConfigWindowsMoveFromTitleBarOnly ? ImGuiWindowBgClickFlags_None : ImGuiWindowBgClickFlags_Move);

View File

@@ -29,7 +29,7 @@
// Library Version // Library Version
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345') // (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345')
#define IMGUI_VERSION "1.92.5 WIP" #define IMGUI_VERSION "1.92.5 WIP"
#define IMGUI_VERSION_NUM 19244 #define IMGUI_VERSION_NUM 19245
#define IMGUI_HAS_TABLE // Added BeginTable() - from IMGUI_VERSION_NUM >= 18000 #define IMGUI_HAS_TABLE // Added BeginTable() - from IMGUI_VERSION_NUM >= 18000
#define IMGUI_HAS_TEXTURES // Added ImGuiBackendFlags_RendererHasTextures - from IMGUI_VERSION_NUM >= 19198 #define IMGUI_HAS_TEXTURES // Added ImGuiBackendFlags_RendererHasTextures - from IMGUI_VERSION_NUM >= 19198