Hover was per-sensor state that only changed when the walk reached that sensor, so ending it depended on the walk, which consumption cuts short. `CursorSenses` now keeps the set of widgets the cursor was inside, in a new `Event::Global` slot for state a whole event type owns rather than each widget -- which is also where the input restructure keeps its pointer capture. The walk visits only widgets the cursor is inside and stops at the layer that consumes, as before. Whoever was in the set and is not now has been left or covered, and gets its `HoverEnd` afterwards, however early the walk stopped. Two things fall out. `SensorState` is gone: whether a hover is starting, on or ending is the difference between the two sets. And the consumption line loses its `&& in_shape`, since being inside is now the reason the widget is looked at rather than something to test again. Nine tests, five of which fail on `main`. `hover_starts_and_ends_once_each` pins the lifecycle, and `covering_a_widget_ends_its_hover` now returns the cursor so an uncovered widget hovers again.
56 lines
1.4 KiB
Rust
56 lines
1.4 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, as opposed to `State`, which each
|
|
/// widget keeps its own of.
|
|
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. `run_event` reports back the `or` of
|
|
/// this across everything that ran.
|
|
#[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
|
|
{
|
|
}
|