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| {
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_EVENTandDRAG_MOVE_EVENTbased 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 - Drag & drop service.
- Drag
Drop Effect - Drag&drop drop effect on the data source.
- Drag
EndArgs - Arguments for
DRAG_END_EVENT. - Drag
Handle - Represents dragging data.
- Drag
Hovered Args - Arguments for
DRAG_HOVERED_EVENT. - Drag
Move Args DRAG_MOVE_EVENTarguments.- Drag
Start Args - Arguments for
DRAG_START_EVENT. - Drop
Args - Arguments for
DROP_EVENT. - Weak
Drag Handle - Weak
DragHandle.
Enums§
- Drag
Drop Data - Drag&drop data payload.
Statics§
- DRAG_
END_ EVENT - Drag&drop gesture started from the draggable widget has ended.
- DRAG_
HOVERED_ EVENT - Drag&drop enter or exit a drop target widget.
- DRAG_
MOVE_ EVENT - Drag&drop is dragging over the target widget.
- DRAG_
START_ EVENT - Drag&drop started dragging a draggable widget.
- DROP_
EVENT - Drag&drop action finished over some drop target widget.
Functions§
- draggable
PIf this widget can be dragged in a drag&drop operation.- on_
drag_ end PDraggable widget stopped dragging.- on_
drag_ enter PDragging cursor entered the widget area and the widget is enabled.- on_
drag_ hovered PDragging cursor entered or exited the widget area and the widget is enabled.- on_
drag_ leave PDragging cursor exited the widget area and the widget is enabled.- on_
drag_ start PDraggable widget started dragging.- on_drop
PDragging cursor dropped data in the widget area and the widget is enabled.- on_
pre_ drag_ end PPreviewon_drag_endevent.- on_
pre_ drag_ enter PPreviewon_drag_enterevent.- on_
pre_ drag_ hovered PPreviewon_drag_hoveredevent.- on_
pre_ drag_ leave PPreviewon_drag_leaveevent.- on_
pre_ drag_ start PPreviewon_drag_startevent.- on_
pre_ drop PPreviewon_dropevent.