Module re_viewer_context::drag_and_drop
source · Expand description
Support for viewer-wide drag-and-drop of crate::Item
s.
§Theory of operation
§Setup
A DragAndDropManager
should be created at the start of the frame and made available to the
entire UI code.
§Initiating a drag
Any UI representation of an crate::Item
may initiate a drag.
crate::ViewerContext::handle_select_hover_drag_interactions
will handle that automatically
when passed true
for its draggable
argument.
§Reacting to a drag and accepting a drop
This part of the process is more involved and typically includes the following steps:
-
When hovered, the receiving UI element should check for a compatible payload using [
egui::DragAndDrop::payload
] and matching one or more variants of the returnedDragAndDropPayload
, if any. -
If an acceptable payload type is being dragged, the UI element should provide appropriate visual feedback. This includes:
- Calling
DragAndDropManager::set_feedback
with the appropriate feedback. - Drawing a frame around the target container with
re_ui::DesignTokens::drop_target_container_stroke
. - Optionally provide more feedback, e.g., where exactly the payload will be inserted within the container.
- Calling
-
If the mouse is released (using [
egui::PointerState::any_released
]), the payload must be actually transferred to the container and [egui::DragAndDrop::clear_payload
] must be called.
Structs§
- Helper to handle drag-and-drop operations.
- Helper class to count item types and display them in a human-readable way.