diff options
author | Julian Eisel <julian@blender.org> | 2021-10-27 15:48:00 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2021-10-27 15:56:57 +0300 |
commit | 1832e11f39a36681533c148de9300b290a8c309c (patch) | |
tree | e32c59f22eafc0428d190a6a903420832bfc386d /source/blender/editors/interface/tree_view.cc | |
parent | 8507336e76902604a2128b23a4d8e52094031ab0 (diff) |
UI: Support dragging tree-view items
Adds the needed bits to the UI tree-view API to support dragging
tree-view items. This isn't used yet, but will be in the following
commit for asset catalogs.
There will probably be some further tweaks to the design at some point,
for now this should work well enough for our use-cases.
Diffstat (limited to 'source/blender/editors/interface/tree_view.cc')
-rw-r--r-- | source/blender/editors/interface/tree_view.cc | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/source/blender/editors/interface/tree_view.cc b/source/blender/editors/interface/tree_view.cc index 04d7a066b36..c08fa51d5a5 100644 --- a/source/blender/editors/interface/tree_view.cc +++ b/source/blender/editors/interface/tree_view.cc @@ -29,6 +29,7 @@ #include "UI_interface.h" +#include "WM_api.h" #include "WM_types.h" #include "UI_tree_view.hh" @@ -354,6 +355,13 @@ void AbstractTreeViewItem::is_active(IsActiveFn is_active_fn) is_active_fn_ = is_active_fn; } +std::unique_ptr<AbstractTreeViewItemDragController> AbstractTreeViewItem::create_drag_controller() + const +{ + /* There's no drag controller (and hence no drag support) by default. */ + return nullptr; +} + std::unique_ptr<AbstractTreeViewItemDropController> AbstractTreeViewItem::create_drop_controller() const { @@ -686,6 +694,29 @@ bool UI_tree_view_item_matches(const uiTreeViewItemHandle *a_handle, return a.matches_including_parents(b); } +/** + * Attempt to start dragging the tree-item \a item_. This will not work if the tree item doesn't + * support dragging, i.e. it won't create a drag-controller upon request. + * \return True if dragging started successfully, otherwise false. + */ +bool UI_tree_view_item_drag_start(bContext *C, uiTreeViewItemHandle *item_) +{ + const AbstractTreeViewItem &item = reinterpret_cast<const AbstractTreeViewItem &>(*item_); + const std::unique_ptr<AbstractTreeViewItemDragController> drag_controller = + item.create_drag_controller(); + if (!drag_controller) { + return false; + } + + WM_event_start_drag(C, + ICON_NONE, + drag_controller->get_drag_type(), + drag_controller->create_drag_data(), + 0, + WM_DRAG_FREE_DATA); + return true; +} + bool UI_tree_view_item_can_drop(const uiTreeViewItemHandle *item_, const wmDrag *drag, const char **r_disabled_hint) |