orbit/events/
event.rs

1//! Event trait for OrbitRS events system
2
3use std::any::Any;
4
5/// Generic event trait
6pub trait Event: 'static {
7    /// Convert to Any for downcasting
8    fn as_any(&self) -> &dyn Any;
9
10    /// Convert to Any for downcasting (mutable)
11    fn as_any_mut(&mut self) -> &mut dyn Any;
12
13    /// Get the event type name
14    fn event_type(&self) -> &'static str;
15
16    /// Clone the event
17    fn box_clone(&self) -> Box<dyn Event>;
18}
19
20/// Default implementation for types that implement Clone
21impl<T: Any + Clone + 'static> Event for T {
22    fn as_any(&self) -> &dyn Any {
23        self
24    }
25
26    fn as_any_mut(&mut self) -> &mut dyn Any {
27        self
28    }
29
30    fn event_type(&self) -> &'static str {
31        std::any::type_name::<T>()
32    }
33
34    fn box_clone(&self) -> Box<dyn Event> {
35        Box::new(self.clone())
36    }
37}
38
39/// Re-export winit event types
40#[cfg(feature = "desktop")]
41pub mod winit {
42    pub use winit::event::{Event, MouseButton};
43}