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.
This commit is contained in:
2021-10-27 14:48:00 +02:00
parent 8507336e76
commit 1832e11f39
4 changed files with 79 additions and 9 deletions

View File

@@ -49,6 +49,7 @@ namespace blender::ui {
class AbstractTreeView;
class AbstractTreeViewItem;
class AbstractTreeViewItemDropController;
class AbstractTreeViewItemDragController;
/* ---------------------------------------------------------------------- */
/** \name Tree-View Item Container
@@ -273,6 +274,11 @@ class AbstractTreeViewItem : public TreeViewItemContainer {
*/
virtual bool matches(const AbstractTreeViewItem &other) const;
/**
* If an item wants to support being dragged, it has to return a drag controller here.
* That is an object implementing #AbstractTreeViewItemDragController.
*/
virtual std::unique_ptr<AbstractTreeViewItemDragController> create_drag_controller() const;
/**
* If an item wants to support dropping data into it, it has to return a drop controller here.
* That is an object implementing #AbstractTreeViewItemDropController.
@@ -347,6 +353,18 @@ class AbstractTreeViewItem : public TreeViewItemContainer {
/** \name Drag 'n Drop
* \{ */
/**
* Class to enable dragging a tree-item. An item can return a drop controller for itself via a
* custom implementation of #AbstractTreeViewItem::create_drag_controller().
*/
class AbstractTreeViewItemDragController {
public:
virtual ~AbstractTreeViewItemDragController() = default;
virtual int get_drag_type() const = 0;
virtual void *create_drag_data() const = 0;
};
/**
* Class to customize the drop behavior of a tree-item, plus the behavior when dragging over this
* item. An item can return a drop controller for itself via a custom implementation of