refactor events
This commit is contained in:
36
core/src/event/mod.rs
Normal file
36
core/src/event/mod.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
mod ctx;
|
||||
mod manager;
|
||||
|
||||
pub use ctx::*;
|
||||
pub use manager::*;
|
||||
|
||||
pub trait Event: Sized + 'static + Clone {
|
||||
type Data<'a> = ();
|
||||
type State: Default = ();
|
||||
#[allow(unused_variables)]
|
||||
fn should_run(&self, data: &mut Self::Data<'_>) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
pub trait EventLike {
|
||||
type Event: Event;
|
||||
fn into_event(self) -> Self::Event;
|
||||
}
|
||||
|
||||
impl<E: Event> EventLike for E {
|
||||
type Event = Self;
|
||||
|
||||
fn into_event(self) -> Self::Event {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub trait EventFn<Ctx, Data>: Fn(EventCtx<Ctx, Data>) + 'static {}
|
||||
impl<F: Fn(EventCtx<Ctx, Data>) + 'static, Ctx, Data> EventFn<Ctx, Data> for F {}
|
||||
|
||||
pub trait WidgetEventFn<Ctx, Data, W: ?Sized>: Fn(EventIdCtx<Ctx, Data, W>) + 'static {}
|
||||
impl<F: Fn(EventIdCtx<Ctx, Data, W>) + 'static, Ctx, Data, W: ?Sized> WidgetEventFn<Ctx, Data, W>
|
||||
for F
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user