You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
space-editor/src/events/global.rs

37 lines
834 B

pub use std::rc::Rc;
pub use orbgame::prelude::*;
#[derive(Copy, Clone, PartialEq)]
pub enum GlobalEvent {
Load,
Reload,
}
pub type GlobalHandlerFn = dyn Fn(&mut StatesContext, &GlobalEvent) -> bool + 'static;
pub struct GlobalEventHandler {
pub handler: Rc<GlobalHandlerFn>,
}
impl Into<Rc<dyn EventHandler>> for GlobalEventHandler {
fn into(self) -> Rc<dyn EventHandler> {
Rc::new(self)
}
}
impl EventHandler for GlobalEventHandler {
fn handle_event(&self, states: &mut StatesContext, event: &EventBox) -> bool {
if let Ok(event) = event.downcast_ref::<GlobalEvent>() {
return (self.handler)(states, event);
}
false
}
fn handles_event(&self, event: &EventBox) -> bool {
event.is_type::<GlobalEvent>()
}
}
impl Event for GlobalEvent {}