Module drag_drop

Module drag_drop 

Source
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"); before zng::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 and DRAG_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
Drag & drop service.
DragDropEffect
Drag&drop drop effect on the data source.
DragEndArgs
Arguments for DRAG_END_EVENT.
DragHandle
Represents dragging data.
DragHoveredArgs
Arguments for DRAG_HOVERED_EVENT.
DragMoveArgs
DRAG_MOVE_EVENT arguments.
DragStartArgs
Arguments for DRAG_START_EVENT.
DropArgs
Arguments for DROP_EVENT.
WeakDragHandle
Weak DragHandle.

Enums§

DragDropData
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
P If this widget can be dragged in a drag&drop operation.
on_drag_end
P Draggable widget stopped dragging.
on_drag_enter
P Dragging cursor entered the widget area and the widget is enabled.
on_drag_hovered
P Dragging cursor entered or exited the widget area and the widget is enabled.
on_drag_leave
P Dragging cursor exited the widget area and the widget is enabled.
on_drag_start
P Draggable widget started dragging.
on_drop
P Dragging cursor dropped data in the widget area and the widget is enabled.
on_pre_drag_end
P Preview on_drag_end event.
on_pre_drag_enter
P Preview on_drag_enter event.
on_pre_drag_hovered
P Preview on_drag_hovered event.
on_pre_drag_leave
P Preview on_drag_leave event.
on_pre_drag_start
P Preview on_drag_start event.
on_pre_drop
P Preview on_drop event.