1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// Copyright 2023-2023 CrabNebula Ltd.
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
//!Start a drag operation out of a window on macOS, Windows and Linux (via GTK).
//!
//! Tested for [tao](https://github.com/tauri-apps/tao) (latest),
//! [winit](https://github.com/rust-windowing/winit) (latest),
//! [wry](https://github.com/tauri-apps/wry) (v0.24) and
//! [tauri](https://github.com/tauri-apps/tauri) (v1) windows.
//!
//! Due to the GTK-based implementation, winit currently cannot leverage this crate on Linux yet.
//!
//! - Add the `drag` dependency:
//!
//! `$ cargo add drag`
//!
//! - Use the `drag::start_drag` function. It takes a `&T: raw_window_handle::HasWindowHandle` type on macOS and Windows, and a `>k::ApplicationWindow` on Linux:
//!
//! - tao:
//! ```rust,no_run
//! let event_loop = tao::event_loop::EventLoop::new();
//! let window = tao::window::WindowBuilder::new().build(&event_loop).unwrap();
//!
//! let item = drag::DragItem::Files(vec![std::fs::canonicalize("./examples/icon.png").unwrap()]);
//! let preview_icon = drag::Image::File("./examples/icon.png".into());
//!
//! drag::start_drag(
//! #[cfg(target_os = "linux")]
//! {
//! use tao::platform::unix::WindowExtUnix;
//! window.gtk_window()
//! },
//! #[cfg(not(target_os = "linux"))]
//! &window,
//! item,
//! preview_icon,
//! |result, cursor_position| {
//! println!("drag result: {result:?}");
//! },
//! drag::Options::default(),
//! );
//! ```
//!
//! - wry:
//! ```rust,no_run
//! let event_loop = tao::event_loop::EventLoop::new();
//! let window = tao::window::WindowBuilder::new().build(&event_loop).unwrap();
//! let webview = wry::WebViewBuilder::new().build(&window).unwrap();
//!
//! let item = drag::DragItem::Files(vec![std::fs::canonicalize("./examples/icon.png").unwrap()]);
//! let preview_icon = drag::Image::File("./examples/icon.png".into());
//!
//! drag::start_drag(
//! #[cfg(target_os = "linux")]
//! {
//! use tao::platform::unix::WindowExtUnix;
//! window.gtk_window()
//! },
//! #[cfg(not(target_os = "linux"))]
//! &window,
//! item,
//! preview_icon,
//! |result, cursor_position| {
//! println!("drag result: {result:?}");
//! },
//! drag::Options::default(),
//! );
//! ```
//!
//! - winit:
//! ```rust,ignore
//! let window = ...winit window;
//!
//! let item = drag::DragItem::Files(vec![std::fs::canonicalize("./examples/icon.png").unwrap()]);
//! let preview_icon = drag::Image::File("./examples/icon.png".into());
//!
//! # #[cfg(not(target_os = "linux"))]
//! let _ = drag::start_drag(&window, item, preview_icon, |result, cursor_position| {
//! println!("drag result: {result:?}");
//! }, Default::default());
//! ```
use PathBuf;
pub use start_drag;
pub type Result<T> = Result;
pub type DataProvider = ;
/// Item to be dragged.
/// An image definition.
/// Logical position of the cursor.
///
/// - **Windows**: Currently the win32 API for logical position reports physical position as well, due to the complicated nature of potential multiple monitor with different scaling there's no trivial solution to be incorporated.