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
pub mod file;
pub mod keyboard;
pub mod mouse;
pub mod pointer;
pub mod touch;
pub mod wheel;

use std::any::Any;

use dioxus_core::Event;
pub use file::*;
pub use keyboard::*;
pub use mouse::*;
pub use pointer::*;
pub use touch::*;
pub use wheel::*;

pub type KeyboardEvent = Event<KeyboardData>;
pub type MouseEvent = Event<MouseData>;
pub type WheelEvent = Event<WheelData>;
pub type TouchEvent = Event<TouchData>;
pub type PointerEvent = Event<PointerData>;

/// A platform specific event.
#[doc(hidden)]
pub struct ErasedEventData {
    event: Box<dyn Any>,
}

impl ErasedEventData {
    pub fn new(event: Box<dyn Any>) -> Self {
        Self { event }
    }

    pub fn downcast<T: 'static>(&self) -> Option<&T> {
        self.event.downcast_ref::<T>()
    }

    pub fn downcast_mut<T: 'static>(&mut self) -> Option<&mut T> {
        self.event.downcast_mut::<T>()
    }

    pub fn into_inner<T: 'static>(self) -> Option<T> {
        self.event.downcast::<T>().ok().map(|e| *e)
    }
}