Merge pull request #62744 from AThousandShips/tree_h_scroll

This commit is contained in:
Rémi Verschelde 2022-07-08 11:51:07 +02:00 committed by GitHub
commit ca18a02e00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 6 deletions

View File

@ -2967,6 +2967,15 @@ void Tree::_go_down() {
accept_event(); accept_event();
} }
bool Tree::_scroll(bool p_horizontal, float p_pages) {
ScrollBar *scroll = p_horizontal ? (ScrollBar *)h_scroll : (ScrollBar *)v_scroll;
double prev_value = scroll->get_value();
scroll->set_value(scroll->get_value() + scroll->get_page() * p_pages);
return scroll->get_value() != prev_value;
}
void Tree::gui_input(const Ref<InputEvent> &p_event) { void Tree::gui_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null()); ERR_FAIL_COND(p_event.is_null());
@ -3481,17 +3490,25 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {
} break; } break;
case MouseButton::WHEEL_UP: { case MouseButton::WHEEL_UP: {
double prev_value = v_scroll->get_value(); if (_scroll(false, -mb->get_factor() / 8)) {
v_scroll->set_value(v_scroll->get_value() - v_scroll->get_page() * mb->get_factor() / 8);
if (v_scroll->get_value() != prev_value) {
accept_event(); accept_event();
} }
} break; } break;
case MouseButton::WHEEL_DOWN: { case MouseButton::WHEEL_DOWN: {
double prev_value = v_scroll->get_value(); if (_scroll(false, mb->get_factor() / 8)) {
v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * mb->get_factor() / 8); accept_event();
if (v_scroll->get_value() != prev_value) { }
} break;
case MouseButton::WHEEL_LEFT: {
if (_scroll(true, -mb->get_factor() / 8)) {
accept_event();
}
} break;
case MouseButton::WHEEL_RIGHT: {
if (_scroll(true, mb->get_factor() / 8)) {
accept_event(); accept_event();
} }

View File

@ -610,6 +610,8 @@ private:
void _go_down(); void _go_down();
void _go_up(); void _go_up();
bool _scroll(bool p_horizontal, float p_pages);
protected: protected:
static void _bind_methods(); static void _bind_methods();