freya_elements/events/
file.rs

1use std::path::PathBuf;
2
3use crate::{
4    events::ErasedEventData,
5    impl_event,
6};
7impl_event! [
8    FileData;
9
10    /// The `filedrop` event fires when the user drops a file over the element.
11    ///
12    /// Event Data: [`FileData`](crate::events::FileData)
13    ///
14    /// ### Example
15    ///
16    /// ```rust, no_run
17    /// # use freya::prelude::*;
18    /// fn app() -> Element {
19    ///     rsx!(
20    ///         rect {
21    ///             width: "100%",
22    ///             height: "100%",
23    ///             background: "black",
24    ///             onfiledrop: |e| println!("File dropped: {e:?}")
25    ///         }
26    ///     )
27    /// }
28    /// ```
29    onfiledrop
30
31    /// The `onglobalfilehover` event fires when the user hovers a file over the window.
32    ///
33    /// Event Data: [`FileData`](crate::events::FileData)
34    ///
35    /// ### Example
36    ///
37    /// ```rust, no_run
38    /// # use freya::prelude::*;
39    /// fn app() -> Element {
40    ///     rsx!(
41    ///         rect {
42    ///             width: "100%",
43    ///             height: "100%",
44    ///             background: "black",
45    ///             onglobalfilehover: |e| println!("File hover: {e:?}")
46    ///         }
47    ///     )
48    /// }
49    /// ```
50    onglobalfilehover
51
52    /// The `onglobalfilehovercancelled` event fires when the user cancels the hovering of a file over the window. It's the opposite of [`onglobalfilehover`](crate::events::onglobalfilehover()).
53    ///
54    /// Event Data: [`FileData`](crate::events::FileData)
55    ///
56    /// ### Example
57    ///
58    /// ```rust, no_run
59    /// # use freya::prelude::*;
60    /// fn app() -> Element {
61    ///     rsx!(
62    ///         rect {
63    ///             width: "100%",
64    ///             height: "100%",
65    ///             background: "black",
66    ///             onglobalfilehovercancelled: |e| println!("File hover cancelled: {e:?}")
67    ///         }
68    ///     )
69    /// }
70    /// ```
71    onglobalfilehovercancelled
72];
73
74/// Data of a File event.
75#[derive(Debug, Clone, PartialEq)]
76pub struct FileData {
77    pub file_path: Option<PathBuf>,
78}
79
80impl From<&ErasedEventData> for FileData {
81    fn from(val: &ErasedEventData) -> Self {
82        val.downcast::<FileData>().cloned().unwrap()
83    }
84}