From 8306e32495448c21dc37973fa6dfc546d1a067d1 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 28 Jan 2026 15:14:15 +0100 Subject: [PATCH] Nav: fixed speed scale for resizing/moving with keyboard/gamepad. (#323) Fix 04157da29. --- docs/CHANGELOG.txt | 4 ++++ imgui.cpp | 4 ++-- imgui_internal.h | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index ceba9c0a7..1207595d2 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -172,6 +172,10 @@ Other Changes: - Fixed remote/shortcut InputText() not teleporting mouse cursor when nav cursor is visible and `io.ConfigNavMoveSetMousePos` is enabled. - Fixed a looping/wrapping issue when done in menu layer. (#9178) + - Fixed speed scale for resizing/moving with keyboard/gamepad. We incorrectly + used io.DisplayFramebufferScale (very old code), effectively making those + actions faster on macOS/iOS retina screens. + (changed this to use a style scale factor that's not fully formalized yet) - Scrollbar: fixed a codepath leading to a divide-by-zero (which would not be noticeable by user but detected by sanitizers). (#9089) [@judicaelclair] - InvisibleButton: allow calling with size (0,0) to fit to available content diff --git a/imgui.cpp b/imgui.cpp index 7f8710cd9..4813c1bf1 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -7006,7 +7006,7 @@ static int ImGui::UpdateWindowManualResize(ImGuiWindow* window, int* border_hove if (nav_resize_dir.x != 0.0f || nav_resize_dir.y != 0.0f) { const float NAV_RESIZE_SPEED = 600.0f; - const float resize_step = NAV_RESIZE_SPEED * g.IO.DeltaTime * ImMin(g.IO.DisplayFramebufferScale.x, g.IO.DisplayFramebufferScale.y); + const float resize_step = NAV_RESIZE_SPEED * g.IO.DeltaTime * GetScale(); g.NavWindowingAccumDeltaSize += nav_resize_dir * resize_step; g.NavWindowingAccumDeltaSize = ImMax(g.NavWindowingAccumDeltaSize, clamp_rect.Min - window->Pos - window->Size); // We need Pos+Size >= clmap_rect.Min, so Size >= clmap_rect.Min - Pos, so size_delta >= clmap_rect.Min - window->Pos - window->Size g.NavWindowingToggleLayer = false; @@ -14521,7 +14521,7 @@ static void ImGui::NavUpdateWindowing() if (nav_move_dir.x != 0.0f || nav_move_dir.y != 0.0f) { const float NAV_MOVE_SPEED = 800.0f; - const float move_step = NAV_MOVE_SPEED * io.DeltaTime * ImMin(io.DisplayFramebufferScale.x, io.DisplayFramebufferScale.y); + const float move_step = NAV_MOVE_SPEED * io.DeltaTime * GetScale(); g.NavWindowingAccumDeltaPos += nav_move_dir * move_step; g.NavHighlightItemUnderNav = true; ImVec2 accum_floored = ImTrunc(g.NavWindowingAccumDeltaPos); diff --git a/imgui_internal.h b/imgui_internal.h index ad7a1479f..c17873ca4 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -3150,6 +3150,7 @@ namespace ImGui // - You are calling ImGui functions after ImGui::EndFrame()/ImGui::Render() and before the next ImGui::NewFrame(), which is also illegal. IMGUI_API ImGuiIO& GetIO(ImGuiContext* ctx); IMGUI_API ImGuiPlatformIO& GetPlatformIO(ImGuiContext* ctx); + inline float GetScale() { ImGuiContext& g = *GImGui; return g.Style._MainScale; } // FIXME-DPI: I don't want to formalize this just yet. Because reasons. Please don't use. inline ImGuiWindow* GetCurrentWindowRead() { ImGuiContext& g = *GImGui; return g.CurrentWindow; } inline ImGuiWindow* GetCurrentWindow() { ImGuiContext& g = *GImGui; g.CurrentWindow->WriteAccessed = true; return g.CurrentWindow; } IMGUI_API ImGuiWindow* FindWindowByID(ImGuiID id);