Skip to main content

Module dnd

Module dnd 

Source
Expand description

Carrying an item from where it is to where it should go.

§The library never moves anything

A drop reports an intent — “this item goes before that one”, “into that folder” — and stops. The host applies it to the data it owns and hands back a new order; the list shows the reorder on the frame that new order arrives, and not before. A host that refuses the move keeps the order that still holds, which is the same rule every other component in this library follows for values, sorts and selections.

§What GPUI provides, and what is added here

GPUI owns the gesture: gpui::StatefulInteractiveElement::on_drag turns a press plus two pixels of travel into a drag, keeps the payload in the application, paints one drag view at the pointer, routes gpui::InteractiveElement::on_drag_move to every registered element and gpui::InteractiveElement::on_drop to whatever the pointer is over on release, and lets a target refuse a payload through gpui::InteractiveElement::can_drop.

What GPUI does not have, and this module adds: a vocabulary for where a drop lands (DropPosition), one payload type every surface in the library agrees on (DragItem), the speed the gesture was moving at as well as where it was (DropIntent::velocity), a published record of the drag so a test can read what is being carried and where it would land, escape as a cancel, a ghost that follows the pointer on a spring instead of snapping to it, and the make-way slide that opens the slot the drop would land in.

§What a drag publishes

While a drag is in flight the semantic tree carries one extra node, with the id DRAG_NODE_ID and the role Role::Drag:

  • text — the label of the item being carried;
  • value — the item’s id and where it would land, as "<item id> before:<anchor>", "after:<anchor>", "into:<anchor>", or "<item id> none" when the pointer is over nothing that offers a slot;
  • invalid — set when the target under the pointer refuses the payload.

The node exists only while the drag does, so a test reads it from an ordinary snapshot and never has to sleep.

§Reduced motion

The ghost is direct manipulation, not decoration: it is the thing the hand is holding, so it keeps following the pointer under reduced motion. What it loses is the spring — it tracks the pointer exactly instead of trailing it. The make-way slides are decoration, so they settle instantly and the slot is simply open from the first frame.

Structs§

ActiveDrag
The drag as anything outside the module can see it.
DragItem
What a drag is carrying.
DropIntent
One drop, as it is reported to the host.
MakeWay
An element painted beside where layout put it.
StagedDrag
A drag placed by hand rather than by a pointer.

Enums§

DropAxis
Which way a target’s slots are laid out.
DropPosition
Where a dropped item goes, expressed against something already there.

Constants§

DRAG_NODE_ID
The semantic id of the node a drag publishes while it is in flight.
FILE_KIND
The payload kind an external file drop carries.
ROW_KIND
The payload kind a row, node, or tab carries.

Functions§

active
The drag in flight, if there is one.
cancel
Abandons a drag in flight. A cancelled drag reports nothing.
draggable
Makes element the handle of a drag carrying item.
install
Installs the drag session and the key that cancels a drag.
stage
Places the drag system in a fixed state, for a capture or a review that has to show a drag in flight.
staged_ghost
The ghost of a staged drag, for a scene that places it itself.