Skip to content

Commit

Permalink
Merge pull request #62744 from AThousandShips/tree_h_scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored Jul 8, 2022
2 parents 99df193 + bed6589 commit ca18a02
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
29 changes: 23 additions & 6 deletions scene/gui/tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2967,6 +2967,15 @@ void Tree::_go_down() {
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) {
ERR_FAIL_COND(p_event.is_null());

Expand Down Expand Up @@ -3481,17 +3490,25 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {

} break;
case MouseButton::WHEEL_UP: {
double prev_value = v_scroll->get_value();
v_scroll->set_value(v_scroll->get_value() - v_scroll->get_page() * mb->get_factor() / 8);
if (v_scroll->get_value() != prev_value) {
if (_scroll(false, -mb->get_factor() / 8)) {
accept_event();
}

} break;
case MouseButton::WHEEL_DOWN: {
double prev_value = v_scroll->get_value();
v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * mb->get_factor() / 8);
if (v_scroll->get_value() != prev_value) {
if (_scroll(false, mb->get_factor() / 8)) {
accept_event();
}

} 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();
}

Expand Down
2 changes: 2 additions & 0 deletions scene/gui/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,8 @@ class Tree : public Control {
void _go_down();
void _go_up();

bool _scroll(bool p_horizontal, float p_pages);

protected:
static void _bind_methods();

Expand Down

0 comments on commit ca18a02

Please sign in to comment.