freya_elements/
events.rs

1pub mod file;
2pub mod keyboard;
3pub mod mouse;
4pub mod pointer;
5pub mod touch;
6pub mod wheel;
7
8use std::any::Any;
9
10use dioxus_core::Event;
11pub use file::*;
12pub use keyboard::*;
13pub use mouse::*;
14pub use pointer::*;
15pub use touch::*;
16pub use wheel::*;
17
18pub type KeyboardEvent = Event<KeyboardData>;
19pub type MouseEvent = Event<MouseData>;
20pub type WheelEvent = Event<WheelData>;
21pub type TouchEvent = Event<TouchData>;
22pub type PointerEvent = Event<PointerData>;
23
24/// A platform specific event.
25#[doc(hidden)]
26pub struct ErasedEventData {
27    event: Box<dyn Any>,
28}
29
30impl ErasedEventData {
31    pub fn new(event: Box<dyn Any>) -> Self {
32        Self { event }
33    }
34
35    pub fn downcast<T: 'static>(&self) -> Option<&T> {
36        self.event.downcast_ref::<T>()
37    }
38
39    pub fn downcast_mut<T: 'static>(&mut self) -> Option<&mut T> {
40        self.event.downcast_mut::<T>()
41    }
42
43    pub fn into_inner<T: 'static>(self) -> Option<T> {
44        self.event.downcast::<T>().ok().map(|e| *e)
45    }
46}