Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scrolling behavior with zero/low page value #67910

Merged
merged 1 commit into from
Mar 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions scene/gui/scroll_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ void ScrollBar::gui_input(const Ref<InputEvent> &p_event) {
accept_event();

if (b->get_button_index() == MouseButton::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() == MouseButton::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();
}

Expand Down Expand Up @@ -99,7 +101,8 @@ void ScrollBar::gui_input(const Ref<InputEvent> &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) {
Expand All @@ -122,7 +125,8 @@ void ScrollBar::gui_input(const Ref<InputEvent> &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) {
Expand Down