Expand description
Drag&drop service, types and events.
The example below defines a window that shows the current dragging data that has entered any of the app windows.
use zng::prelude::*;
use zng::drag_drop::*;
let data = var::<Vec<DragDropData>>(vec![]);
Window! {
padding = 20;
child = Container! {
widget::border = 5, widget::BorderSides::dashed(colors::GRAY);
widget::corner_radius = 15;
child_align = Align::CENTER;
on_drag_enter = hn!(data, |_| {
data.set(DRAG_DROP.dragging_data().get());
});
on_drag_leave = hn!(data, |_| {
data.set(vec![]);
});
on_drop = hn!(data, |args: &DropArgs| {
data.set(args.data.clone());
});
child = Text!(data.map(|d| if d.is_empty() {
Txt::from("drag over to inspect")
} else {
formatx!("{d:#?}")
}));
}
}
§Limitations
Drag&drop depends on the view-process backend, the default view-process (zng-view
) is currently very limited:
- No drag start from the app.
- Only file path drops.
- No support in Wayland, you can work around by calling
std::env::remove_var("WAYLAND_DISPLAY");
beforezng::env::init!()
in your main function, this enables XWayland that has support for the basic file path drop. - In X11 and macOS there is no cursor position notification on hover, just on drop,
DRAG_HOVERED_EVENT
andDRAG_MOVE_EVENT
based event properties will only fire once for the widget that is about to receive a drop.
§Full API
See zng_ext_input::drag_drop
and zng_wgt_input::drag_drop
for the full drag&drop API.
Structs§
- Drag & drop service.
- Drag&drop drop effect on the data source.
- Arguments for
DRAG_END_EVENT
. - Represents dragging data.
- Arguments for
DRAG_HOVERED_EVENT
. DRAG_MOVE_EVENT
arguments.- Arguments for
DRAG_START_EVENT
. - Arguments for
DROP_EVENT
. - Weak
DragHandle
.
Enums§
- Drag&drop data payload.
Statics§
- Drag&drop gesture started from the draggable widget has ended.
- Drag&drop enter or exit a drop target widget.
- Drag&drop is dragging over the target widget.
- Drag&drop started dragging a draggable widget.
- Drag&drop action finished over some drop target widget.
Functions§
P
If this widget can be dragged in a drag&drop operation.P
Draggable widget stopped dragging.P
Dragging cursor entered the widget area and the widget is enabled.P
Dragging cursor entered or exited the widget area and the widget is enabled.P
Dragging cursor exited the widget area and the widget is enabled.P
Draggable widget started dragging.P
Dragging cursor dropped data in the widget area and the widget is enabled.P
Previewon_drag_end
event.P
Previewon_drag_enter
event.P
Previewon_drag_hovered
event.P
Previewon_drag_leave
event.P
Previewon_drag_start
event.P
Previewon_drop
event.