From 268f83e07f2fe7fd9330aae433ce4fd019c91b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82?= Date: Wed, 26 Oct 2022 19:43:50 +0200 Subject: [PATCH] Fix scrolling behaviour with low page value (cherry picked from commit 1608bea18809dcb4e744ee936f8de8f5660adfbe) --- scene/gui/scroll_bar.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp index 9687b20cab3..602df4f73c8 100644 --- a/scene/gui/scroll_bar.cpp +++ b/scene/gui/scroll_bar.cpp @@ -54,12 +54,14 @@ void ScrollBar::_gui_input(Ref p_event) { accept_event(); if (b->get_button_index() == BUTTON_WHEEL_DOWN && b->is_pressed()) { - set_value(get_value() + get_page() / 4.0); + double change = get_page() != 0.0 ? get_page() / 4.0 : (get_max() - get_min()) / 16.0; + set_value(get_value() + MAX(change, get_step())); accept_event(); } if (b->get_button_index() == BUTTON_WHEEL_UP && b->is_pressed()) { - set_value(get_value() - get_page() / 4.0); + double change = get_page() != 0.0 ? get_page() / 4.0 : (get_max() - get_min()) / 16.0; + set_value(get_value() - MAX(change, get_step())); accept_event(); } @@ -98,7 +100,8 @@ void ScrollBar::_gui_input(Ref p_event) { if (scrolling) { target_scroll = CLAMP(target_scroll - get_page(), get_min(), get_max() - get_page()); } else { - target_scroll = CLAMP(get_value() - get_page(), get_min(), get_max() - get_page()); + double change = get_page() != 0.0 ? get_page() : (get_max() - get_min()) / 16.0; + target_scroll = CLAMP(get_value() - change, get_min(), get_max() - get_page()); } if (smooth_scroll_enabled) { @@ -121,7 +124,8 @@ void ScrollBar::_gui_input(Ref p_event) { if (scrolling) { target_scroll = CLAMP(target_scroll + get_page(), get_min(), get_max() - get_page()); } else { - target_scroll = CLAMP(get_value() + get_page(), get_min(), get_max() - get_page()); + double change = get_page() != 0.0 ? get_page() : (get_max() - get_min()) / 16.0; + target_scroll = CLAMP(get_value() + change, get_min(), get_max() - get_page()); } if (smooth_scroll_enabled) {