A doc comment that describes another function goes stale when that function changes, and nobody editing it looks here.
54 lines
1.3 KiB
Rust
54 lines
1.3 KiB
Rust
mod ctx;
|
|
mod manager;
|
|
mod rsc;
|
|
|
|
pub use ctx::*;
|
|
pub use manager::*;
|
|
pub use rsc::*;
|
|
|
|
pub trait Event: Sized + 'static + Clone {
|
|
type Data<'a>: Clone = ();
|
|
type State: Default = ();
|
|
/// State the whole event type keeps, rather than one copy per widget.
|
|
type Global: Default = ();
|
|
#[allow(unused_variables)]
|
|
fn should_run<'a>(&self, data: &Self::Data<'a>) -> Option<Self::Data<'a>> {
|
|
Some(data.clone())
|
|
}
|
|
|
|
/// Whether having run on this data uses up whatever triggered it, so
|
|
/// nothing further should see it.
|
|
#[allow(unused_variables)]
|
|
fn consumes(&self, data: &Self::Data<'_>) -> bool {
|
|
false
|
|
}
|
|
}
|
|
|
|
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<Rsc: HasEvents, Data>: Fn(EventCtx<Rsc, Data>, &mut Rsc) + 'static {}
|
|
impl<Rsc: HasEvents, F: Fn(EventCtx<Rsc, Data>, &mut Rsc) + 'static, Data> EventFn<Rsc, Data>
|
|
for F
|
|
{
|
|
}
|
|
|
|
pub trait WidgetEventFn<Rsc: HasEvents, Data, W: ?Sized>:
|
|
Fn(EventIdCtx<Rsc, Data, W>, &mut Rsc) + 'static
|
|
{
|
|
}
|
|
impl<Rsc: HasEvents, F: Fn(EventIdCtx<Rsc, Data, W>, &mut Rsc) + 'static, Data, W: ?Sized>
|
|
WidgetEventFn<Rsc, Data, W> for F
|
|
{
|
|
}
|