UIDragDrop.h file
Drag and drop.
ui.DragSource(asset); // any small trivially-copyable value ui.DragSource(asset, { .Preview = [=](UI& ui) { ui.Image(ThumbOf(asset)); ui.Label(NameOf(asset)); } }); ui.DropTarget<AssetID>([=](const AssetID& dropped) { Assign(dropped); }); ui.DropTarget<AssetID>([=](const AssetID& dropped, const DropEvent& at) { ... }); ui.DropTarget<AssetID>(onDrop, { .OnOver = [=](const AssetID& a, const DropEvent& at) { Preview(a, at); }, .OnLeave = [=] { EndPreview(); } });
Declared inside the element, like any other reaction. Targets are typed: an element is only a target while a value of its type is being dragged.
- A press that moves past a small threshold starts the drag.
- The target under the pointer gets the
:dropstyle state. - Releasing over a target delivers the value. Releasing elsewhere, Escape, or the pointer leaving the window cancels.
- OnOver hears every move of a matching drag over the target; OnLeave, the drag leaving it or being cancelled over it. A drop is the drop handler's, with no OnLeave.
- A drag suppresses the click on the pressed element.
- The cursor shows whether the element under it would accept the drop.
- Preview is shown beside the pointer. List, tree, table, and tile rows provide their own.
Rows of a list, tree, or table are reordered by giving the view an OnMove:
ui.Tree(source, { .OnMove = [=](std::span<const ItemID> items, ItemID onto, GGDropPlace place) { ... } });
The view only reports the move; the owner of the data performs it.
Namespaces
- namespace GGUI
Classes
- struct GGUI::DropEvent
- A drag over, or dropped on, a target.
- struct GGUI::DragSourceProps
- Properties of ui.DragSource.
-
template<typename T>class GGUI::DropOverFn
- A drop target's hover callback:
[=](const T& value, const DropEvent& at) { ... }. -
template<typename T>struct GGUI::DropTargetProps
- Properties of ui.DropTarget for values of type
T. - struct GGUI::DragBridge
- Lets a host route a drag between documents (windows). Called from the source document while it handles input.
- struct GGUI::ItemMove
- Rows a view reports moved (its OnMove).
- class GGUI::ItemMoveFn
- Row-move callback:
[=](std::span<const ItemID> items, ItemID onto, GGDropPlace place) { ... }.