Skip to content

Commit e8240fd

Browse files
committed
Merge pull request #105516 from tehKaiN/unify_scrollbar_scrollcontainer_scroll_delta
Unify ScrollBar/ScrollContainer scroll delta
2 parents 240cf0d + b6b3b0e commit e8240fd

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

scene/gui/scroll_bar.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ void ScrollBar::gui_input(const Ref<InputEvent> &p_event) {
5050
accept_event();
5151

5252
if (b->get_button_index() == MouseButton::WHEEL_DOWN && b->is_pressed()) {
53-
double change = get_page() != 0.0 ? get_page() / 4.0 : (get_max() - get_min()) / 16.0;
53+
double change = ((get_page() != 0.0) ? get_page() / PAGE_DIVISOR : (get_max() - get_min()) / 16.0) * b->get_factor();
5454
scroll(MAX(change, get_step()));
5555
accept_event();
5656
}
5757

5858
if (b->get_button_index() == MouseButton::WHEEL_UP && b->is_pressed()) {
59-
double change = get_page() != 0.0 ? get_page() / 4.0 : (get_max() - get_min()) / 16.0;
59+
double change = ((get_page() != 0.0) ? get_page() / PAGE_DIVISOR : (get_max() - get_min()) / 16.0) * b->get_factor();
6060
scroll(-MAX(change, get_step()));
6161
accept_event();
6262
}

scene/gui/scroll_bar.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ class ScrollBar : public Range {
110110
static void _bind_methods();
111111

112112
public:
113+
static inline const int PAGE_DIVISOR = 8;
114+
113115
void scroll(double p_amount);
114116
void scroll_to(double p_position);
115117

scene/gui/scroll_container.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,19 @@ void ScrollContainer::gui_input(const Ref<InputEvent> &p_gui_input) {
129129
if (mb->get_button_index() == MouseButton::WHEEL_UP) {
130130
// By default, the vertical orientation takes precedence. This is an exception.
131131
if ((h_scroll_enabled && mb->is_shift_pressed()) || v_scroll_hidden) {
132-
h_scroll->scroll(-h_scroll->get_page() / 8 * mb->get_factor());
132+
h_scroll->scroll(-h_scroll->get_page() / ScrollBar::PAGE_DIVISOR * mb->get_factor());
133133
scroll_value_modified = true;
134134
} else if (v_scroll_enabled) {
135-
v_scroll->scroll(-v_scroll->get_page() / 8 * mb->get_factor());
135+
v_scroll->scroll(-v_scroll->get_page() / ScrollBar::PAGE_DIVISOR * mb->get_factor());
136136
scroll_value_modified = true;
137137
}
138138
}
139139
if (mb->get_button_index() == MouseButton::WHEEL_DOWN) {
140140
if ((h_scroll_enabled && mb->is_shift_pressed()) || v_scroll_hidden) {
141-
h_scroll->scroll(h_scroll->get_page() / 8 * mb->get_factor());
141+
h_scroll->scroll(h_scroll->get_page() / ScrollBar::PAGE_DIVISOR * mb->get_factor());
142142
scroll_value_modified = true;
143143
} else if (v_scroll_enabled) {
144-
v_scroll->scroll(v_scroll->get_page() / 8 * mb->get_factor());
144+
v_scroll->scroll(v_scroll->get_page() / ScrollBar::PAGE_DIVISOR * mb->get_factor());
145145
scroll_value_modified = true;
146146
}
147147
}
@@ -150,19 +150,19 @@ void ScrollContainer::gui_input(const Ref<InputEvent> &p_gui_input) {
150150
if (mb->get_button_index() == MouseButton::WHEEL_LEFT) {
151151
// By default, the horizontal orientation takes precedence. This is an exception.
152152
if ((v_scroll_enabled && mb->is_shift_pressed()) || h_scroll_hidden) {
153-
v_scroll->scroll(-v_scroll->get_page() / 8 * mb->get_factor());
153+
v_scroll->scroll(-v_scroll->get_page() / ScrollBar::PAGE_DIVISOR * mb->get_factor());
154154
scroll_value_modified = true;
155155
} else if (h_scroll_enabled) {
156-
h_scroll->scroll(-h_scroll->get_page() / 8 * mb->get_factor());
156+
h_scroll->scroll(-h_scroll->get_page() / ScrollBar::PAGE_DIVISOR * mb->get_factor());
157157
scroll_value_modified = true;
158158
}
159159
}
160160
if (mb->get_button_index() == MouseButton::WHEEL_RIGHT) {
161161
if ((v_scroll_enabled && mb->is_shift_pressed()) || h_scroll_hidden) {
162-
v_scroll->scroll(v_scroll->get_page() / 8 * mb->get_factor());
162+
v_scroll->scroll(v_scroll->get_page() / ScrollBar::PAGE_DIVISOR * mb->get_factor());
163163
scroll_value_modified = true;
164164
} else if (h_scroll_enabled) {
165-
h_scroll->scroll(h_scroll->get_page() / 8 * mb->get_factor());
165+
h_scroll->scroll(h_scroll->get_page() / ScrollBar::PAGE_DIVISOR * mb->get_factor());
166166
scroll_value_modified = true;
167167
}
168168
}
@@ -250,10 +250,10 @@ void ScrollContainer::gui_input(const Ref<InputEvent> &p_gui_input) {
250250
Ref<InputEventPanGesture> pan_gesture = p_gui_input;
251251
if (pan_gesture.is_valid()) {
252252
if (h_scroll_enabled) {
253-
h_scroll->scroll(h_scroll->get_page() * pan_gesture->get_delta().x / 8);
253+
h_scroll->scroll(h_scroll->get_page() * pan_gesture->get_delta().x / ScrollBar::PAGE_DIVISOR);
254254
}
255255
if (v_scroll_enabled) {
256-
v_scroll->scroll(v_scroll->get_page() * pan_gesture->get_delta().y / 8);
256+
v_scroll->scroll(v_scroll->get_page() * pan_gesture->get_delta().y / ScrollBar::PAGE_DIVISOR);
257257
}
258258

259259
if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll) {
@@ -411,19 +411,19 @@ void ScrollContainer::_accessibility_action_scroll_set(const Variant &p_data) {
411411
}
412412

413413
void ScrollContainer::_accessibility_action_scroll_up(const Variant &p_data) {
414-
v_scroll->set_value(v_scroll->get_value() - v_scroll->get_page() / 8);
414+
v_scroll->set_value(v_scroll->get_value() - v_scroll->get_page() / ScrollBar::PAGE_DIVISOR);
415415
}
416416

417417
void ScrollContainer::_accessibility_action_scroll_down(const Variant &p_data) {
418-
v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() / 8);
418+
v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() / ScrollBar::PAGE_DIVISOR);
419419
}
420420

421421
void ScrollContainer::_accessibility_action_scroll_left(const Variant &p_data) {
422-
h_scroll->set_value(h_scroll->get_value() - h_scroll->get_page() / 8);
422+
h_scroll->set_value(h_scroll->get_value() - h_scroll->get_page() / ScrollBar::PAGE_DIVISOR);
423423
}
424424

425425
void ScrollContainer::_accessibility_action_scroll_right(const Variant &p_data) {
426-
h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() / 8);
426+
h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() / ScrollBar::PAGE_DIVISOR);
427427
}
428428

429429
void ScrollContainer::_notification(int p_what) {

0 commit comments

Comments
 (0)