Track who is hovered, apart from what consumes
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.
This commit is contained in:
1 parent
5494642dec
commit
36fec09d11
4 files changed
+120
-40
No files matched your search
@@ -79,6 +79,7 @@ type EventData<Rsc, E> = (E, Rc<dyn for<'a> EventFn<Rsc, <E as Event>::Data<'a>>
|
||||
pub struct TypeEventManager<Rsc: HasEvents, E: Event> {
|
||||
// TODO: reduce visiblity!!
|
||||
pub active: HashMap<LayerId, HashMap<WidgetId, E::State>>,
|
||||
pub global: E::Global,
|
||||
map: HashMap<WidgetId, Vec<EventData<Rsc, E>>>,
|
||||
}
|
||||
|
||||
@@ -107,6 +108,7 @@ impl<Rsc: HasEvents, E: Event> Default for TypeEventManager<Rsc, E> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
active: Default::default(),
|
||||
global: Default::default(),
|
||||
map: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@ 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())
|
||||
|
||||
Reference in new issue
Block a user