1use std::sync::Arc;
6
7use crate::ViewCtx;
8
9pub struct DragSourceResponse<R> {
11 pub inner: R,
13 pub response: egui::Response,
15 pub drag_started: bool,
17}
18
19impl<R> DragSourceResponse<R> {
20 pub fn on_drag_start<Msg>(self, ctx: &mut ViewCtx<'_, Msg>, msg: Msg) -> Self {
22 if self.drag_started {
23 ctx.emit(msg);
24 }
25 self
26 }
27
28 pub fn map<U>(self, f: impl FnOnce(R) -> U) -> DragSourceResponse<U> {
30 DragSourceResponse {
31 inner: f(self.inner),
32 response: self.response,
33 drag_started: self.drag_started,
34 }
35 }
36}
37
38pub struct DropZoneResponse<P, R> {
40 pub inner: R,
42 pub response: egui::Response,
44 pub payload: Option<Arc<P>>,
46 pub is_being_dragged_over: bool,
48}
49
50impl<P, R> DropZoneResponse<P, R> {
51 pub fn on_drop<Msg, F>(self, ctx: &mut ViewCtx<'_, Msg>, f: F) -> Self
53 where
54 F: FnOnce(Arc<P>) -> Msg,
55 {
56 if let Some(ref payload) = self.payload {
57 ctx.emit(f(Arc::clone(payload)));
58 }
59 self
60 }
61
62 pub fn on_hover<Msg>(self, ctx: &mut ViewCtx<'_, Msg>, msg: Msg) -> Self {
64 if self.is_being_dragged_over {
65 ctx.emit(msg);
66 }
67 self
68 }
69
70 pub fn map<U>(self, f: impl FnOnce(R) -> U) -> DropZoneResponse<P, U> {
72 DropZoneResponse {
73 inner: f(self.inner),
74 response: self.response,
75 payload: self.payload,
76 is_being_dragged_over: self.is_being_dragged_over,
77 }
78 }
79}