1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-09-24 03:28:33 +02:00

Inputs: modulate wheel lock timer for small amount of wheeling. Slightly lower timer. (#3795)

This commit is contained in:
ocornut 2022-11-15 12:25:15 +01:00
parent 03d3343e21
commit a582d92c31
2 changed files with 11 additions and 8 deletions

View File

@ -119,7 +119,7 @@ Other Changes:
systems while letting early adopters adopters toy with internals.
(#456, #2637, #2620, #2891, #3370, #3724, #4828, #5108, #5242, #5641)
- Scrolling: Tweak mouse-wheel locked window timer so it is shorter but also gets reset
whenever scrolling again (#2604).
whenever scrolling again. Modulate for small (sub-pixel) amounts. (#2604)
- Scrolling: Mitigated issue where multi-axis mouse-wheel inputs (usually from touch pad
events) are incorrectly locking scrolling in a parent window. (#4559, #3795, #2604)
- Scrolling: Exposed SetNextWindowScroll() in public API. Useful to remove a scrolling

View File

@ -954,7 +954,7 @@ static const float NAV_WINDOWING_LIST_APPEAR_DELAY = 0.15f; // Time
// Window resizing from edges (when io.ConfigWindowsResizeFromEdges = true and ImGuiBackendFlags_HasMouseCursors is set in io.BackendFlags by backend)
static const float WINDOWS_HOVER_PADDING = 4.0f; // Extend outside window for hovering/resizing (maxxed with TouchPadding) and inside windows for borders. Affect FindHoveredWindow().
static const float WINDOWS_RESIZE_FROM_EDGES_FEEDBACK_TIMER = 0.04f; // Reduce visual noise by only highlighting the border after a certain time.
static const float WINDOWS_MOUSE_WHEEL_SCROLL_LOCK_TIMER = 0.80f; // Lock scrolled window (so it doesn't pick child windows that are scrolling through) for a certain time, unless mouse moved.
static const float WINDOWS_MOUSE_WHEEL_SCROLL_LOCK_TIMER = 0.70f; // Lock scrolled window (so it doesn't pick child windows that are scrolling through) for a certain time, unless mouse moved.
//-------------------------------------------------------------------------
// [SECTION] FORWARD DECLARATIONS
@ -4338,10 +4338,13 @@ static void ImGui::UpdateMouseInputs()
}
}
static void LockWheelingWindow(ImGuiWindow* window)
static void LockWheelingWindow(ImGuiWindow* window, float wheel_amount)
{
ImGuiContext& g = *GImGui;
g.WheelingWindowReleaseTimer = window ? WINDOWS_MOUSE_WHEEL_SCROLL_LOCK_TIMER : 0.0f;
if (window)
g.WheelingWindowReleaseTimer = ImMin(g.WheelingWindowReleaseTimer + ImAbs(wheel_amount) * WINDOWS_MOUSE_WHEEL_SCROLL_LOCK_TIMER, WINDOWS_MOUSE_WHEEL_SCROLL_LOCK_TIMER);
else
g.WheelingWindowReleaseTimer = NULL;
if (g.WheelingWindow == window)
return;
IMGUI_DEBUG_LOG_IO("LockWheelingWindow() \"%s\"\n", window ? window->Name : "NULL");
@ -4360,7 +4363,7 @@ void ImGui::UpdateMouseWheel()
if (IsMousePosValid() && ImLengthSqr(g.IO.MousePos - g.WheelingWindowRefMousePos) > g.IO.MouseDragThreshold * g.IO.MouseDragThreshold)
g.WheelingWindowReleaseTimer = 0.0f;
if (g.WheelingWindowReleaseTimer <= 0.0f)
LockWheelingWindow(NULL);
LockWheelingWindow(NULL, 0.0f);
}
ImVec2 wheel;
@ -4378,7 +4381,7 @@ void ImGui::UpdateMouseWheel()
// FIXME-OBSOLETE: This is an old feature, it still works but pretty much nobody is using it and may be best redesigned.
if (wheel.y != 0.0f && g.IO.KeyCtrl && g.IO.FontAllowUserScaling)
{
LockWheelingWindow(mouse_window);
LockWheelingWindow(mouse_window, wheel.y);
ImGuiWindow* window = mouse_window;
const float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f);
const float scale = new_font_scale / window->FontWindowScale;
@ -4417,7 +4420,7 @@ void ImGui::UpdateMouseWheel()
window = window->ParentWindow;
if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs))
{
LockWheelingWindow(mouse_window);
LockWheelingWindow(mouse_window, wheel.y);
float max_step = window->InnerRect.GetHeight() * 0.67f;
float scroll_step = ImFloor(ImMin(5 * window->CalcFontSize(), max_step));
SetScrollY(window, window->Scroll.y - wheel.y * scroll_step);
@ -4432,7 +4435,7 @@ void ImGui::UpdateMouseWheel()
window = window->ParentWindow;
if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs))
{
LockWheelingWindow(mouse_window);
LockWheelingWindow(mouse_window, wheel.x);
float max_step = window->InnerRect.GetWidth() * 0.67f;
float scroll_step = ImFloor(ImMin(2 * window->CalcFontSize(), max_step));
SetScrollX(window, window->Scroll.x - wheel.x * scroll_step);