zng/drag_drop.rs
1#![cfg(feature = "drag_drop")]
2
3//! Drag&drop service, types and events.
4//!
5//! The example below defines a window that shows the current dragging data that has entered any of the app windows.
6//!
7//! ```
8//! use zng::prelude::*;
9//! # let _scope = APP.defaults();
10//! use zng::drag_drop::*;
11//!
12//! let data = var::<Vec<DragDropData>>(vec![]);
13//! # let _ =
14//! Window! {
15//! padding = 20;
16//! child = Container! {
17//! widget::border = 5, widget::BorderSides::dashed(colors::GRAY);
18//! widget::corner_radius = 15;
19//! child_align = Align::CENTER;
20//! on_drag_enter = hn!(data, |_| {
21//! data.set(DRAG_DROP.dragging_data().get());
22//! });
23//! on_drag_leave = hn!(data, |_| {
24//! data.set(vec![]);
25//! });
26//! on_drop = hn!(data, |args: &DropArgs| {
27//! data.set(args.data.clone());
28//! });
29//! child = Text!(data.map(|d| if d.is_empty() {
30//! Txt::from("drag over to inspect")
31//! } else {
32//! formatx!("{d:#?}")
33//! }));
34//! }
35//! }
36//! # ;
37//! ```
38//!
39//!
40//! # Limitations
41//!
42//! Drag&drop depends on the view-process backend, the default view-process (`zng-view`) is currently very limited:
43//!
44//! * No drag start from the app.
45//! * Only file path drops.
46//! * No support in Wayland, you can work around by calling `std::env::remove_var("WAYLAND_DISPLAY");` before `zng::env::init!()` in
47//! your main function, this enables XWayland that has support for the basic file path drop.
48//! * In X11 and macOS there is no cursor position notification on hover, just on drop, `DRAG_HOVERED_EVENT` and `DRAG_MOVE_EVENT`
49//! based event properties will only fire once for the widget that is about to receive a drop.
50//!
51//! # Full API
52//!
53//! See [`zng_ext_input::drag_drop`] and [`zng_wgt_input::drag_drop`] for the full drag&drop API.
54
55pub use zng_ext_input::drag_drop::{
56 DRAG_DROP, DRAG_END_EVENT, DRAG_HOVERED_EVENT, DRAG_MOVE_EVENT, DRAG_START_EVENT, DROP_EVENT, DragDropData, DragDropEffect,
57 DragEndArgs, DragHandle, DragHoveredArgs, DragMoveArgs, DragStartArgs, DropArgs, WeakDragHandle,
58};
59
60pub use zng_wgt_input::drag_drop::{
61 draggable, on_drag_end, on_drag_enter, on_drag_hovered, on_drag_leave, on_drag_start, on_drop, on_pre_drag_end, on_pre_drag_enter,
62 on_pre_drag_hovered, on_pre_drag_leave, on_pre_drag_start, on_pre_drop,
63};