From 70d450d086157abd78a9cb0c4365645ace0c3488 Mon Sep 17 00:00:00 2001 From: Fredia Huya-Kouadio Date: Mon, 15 Jul 2024 23:23:44 -0700 Subject: [PATCH] Fix issue causing input lock when drag scrolling a `Tree` element on touchscreen devices Prior to this fix, scrolling via mouse drag on touchscreen devices, and drag&drop operation on a `TreeItem` element would conflict with each other preventing the drag scroll from being released when the mouse button is released. The issue is addressed by disabling drag&drop when drag scrolling is ongoing. --- scene/gui/tree.cpp | 18 ++++++++++++++++++ scene/gui/tree.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index b0dfdacad0d..46fcdcf7f6c 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -5440,6 +5440,24 @@ int Tree::get_drop_section_at_position(const Point2 &p_pos) const { return -100; } +bool Tree::can_drop_data(const Point2 &p_point, const Variant &p_data) const { + if (drag_touching) { + // Disable data drag & drop when touch dragging. + return false; + } + + return Control::can_drop_data(p_point, p_data); +} + +Variant Tree::get_drag_data(const Point2 &p_point) { + if (drag_touching) { + // Disable data drag & drop when touch dragging. + return Variant(); + } + + return Control::get_drag_data(p_point); +} + TreeItem *Tree::get_item_at_position(const Point2 &p_pos) const { if (root) { Point2 pos = p_pos; diff --git a/scene/gui/tree.h b/scene/gui/tree.h index e9c93c6e035..3200459b5ae 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -698,6 +698,8 @@ public: virtual String get_tooltip(const Point2 &p_pos) const override; + virtual bool can_drop_data(const Point2 &p_point, const Variant &p_data) const override; + virtual Variant get_drag_data(const Point2 &p_point) override; TreeItem *get_item_at_position(const Point2 &p_pos) const; int get_column_at_position(const Point2 &p_pos) const; int get_drop_section_at_position(const Point2 &p_pos) const;