summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNinni Pipping <ninni.pipping@gmail.com>2022-07-05 19:30:45 +0200
committerNinni <96648715+AThousandShips@users.noreply.github.com>2022-07-07 12:58:44 +0200
commitbed65894d3c87924676b562808fbfde491396e5c (patch)
treebecb8c6cc1b21dcf6fd21596ce1eab651f1d2b7b
parent95ddc8cccc2ad14ff8731b96f3764c88d202f9d3 (diff)
Horizontal scroll for Tree
-rw-r--r--scene/gui/tree.cpp29
-rw-r--r--scene/gui/tree.h2
2 files changed, 25 insertions, 6 deletions
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 32d348c121..4bb8208679 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -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());
@@ -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();
}
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index 65f7ab185c..1690e7ac57 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -610,6 +610,8 @@ private:
void _go_down();
void _go_up();
+ bool _scroll(bool p_horizontal, float p_pages);
+
protected:
static void _bind_methods();