mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-30 18:27:00 +01:00
pointer: a move to the position of the last move does not stir the pass
The begin hook marked a pass as stirred for every PointerMoved event, so a canvas tool host re-hovered a still pointer, with a full hit test, on every pass that repeated the pointer's position. A move now stirs the pass only when it goes to a new position or carries a pen or touch reading. The last move's position is kept per viewport and cleared when the pointer leaves the window.
This commit is contained in:
1 parent
b1fc0c8a18
commit
c04b57ecbf
3 files changed
+46
-6
No files matched your search
@@ -1045,6 +1045,31 @@ fn a_pass_with_only_a_key_or_modifier_change_re_hovers_a_still_pointer_and_re_dr
|
||||
rig.fixture.frame(vec![pointer::release(at + BY)]);
|
||||
}
|
||||
|
||||
/// A pointer move to the position of the last move does not hover the still pointer again, in any number of passes. A
|
||||
/// move somewhere else hovers once, and so does a move back in after the pointer left the window.
|
||||
#[trial]
|
||||
fn a_move_to_the_same_position_does_not_re_hover_a_still_pointer() {
|
||||
let log = Log::default();
|
||||
let mut rig = Rig::with(Probe::new("main", &log), &log, None, Setup::default());
|
||||
let at = rig.centre();
|
||||
let count = |rig: &Rig| rig.calls().iter().filter(|logged| logged.as_str() == "main hover").count();
|
||||
|
||||
rig.fixture.frame(vec![pointer::moved(at)]).idle(2);
|
||||
rig.log.borrow_mut().clear();
|
||||
for _ in 0..3 {
|
||||
rig.fixture.frame(vec![pointer::moved(at)]);
|
||||
}
|
||||
rig.fixture.frame(vec![pointer::moved(at), pointer::moved(at)]);
|
||||
assert_eq!(count(&rig), 0, "moves to the same position hover nothing: {:?}", rig.calls());
|
||||
|
||||
rig.fixture.frame(vec![pointer::moved(at + BY)]);
|
||||
assert_eq!(count(&rig), 1, "a move somewhere else hovers once: {:?}", rig.calls());
|
||||
|
||||
rig.log.borrow_mut().clear();
|
||||
rig.fixture.frame(vec![pointer::gone()]).frame(vec![pointer::moved(at + BY)]);
|
||||
assert_eq!(count(&rig), 1, "a move back in at the same position hovers once: {:?}", rig.calls());
|
||||
}
|
||||
|
||||
/// What the drag session of `DropperTool` carries.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
struct Parcel(u32);
|
||||
|
||||
@@ -338,7 +338,7 @@ pub(crate) struct PointerRead {
|
||||
pub sample: Option<PointerSample>,
|
||||
/// The window lost focus in this pass.
|
||||
pub focus_lost: bool,
|
||||
/// Whether the real pointer moved or entered, or a held modifier or key changed, in this pass.
|
||||
/// Whether a held modifier or key changed in this pass. The begin hook adds the pass's moves to a new position.
|
||||
pub stirred: bool,
|
||||
/// The pass's finger events, in arrival order.
|
||||
pub touches: Vec<Finger>,
|
||||
@@ -432,7 +432,6 @@ pub(crate) fn pointer_read(ctx: &Context) -> PointerRead {
|
||||
}
|
||||
}
|
||||
Event::PointerMoved(pos) => {
|
||||
stirred = true;
|
||||
moves.push(events.len());
|
||||
events.push(PointerEvent::moved(*pos, None));
|
||||
}
|
||||
|
||||
@@ -102,7 +102,8 @@ pub struct PassPointer {
|
||||
pub primary_down: bool,
|
||||
pub press_targets: PressTargets,
|
||||
pub focus_lost: bool,
|
||||
/// Whether the real pointer moved or entered, or a held modifier or key changed, in the pass.
|
||||
/// Whether the real pointer moved to a new position or entered, a pen or touch reading arrived with a move, or a
|
||||
/// held modifier or key changed, in the pass.
|
||||
pub stirred: bool,
|
||||
/// A finger landed in the pass while another was down: a press open now is a gesture's.
|
||||
pub gesture: bool,
|
||||
@@ -127,6 +128,8 @@ pub(crate) struct Memory {
|
||||
withheld: IdMap<u64>,
|
||||
/// The touch under way, for the multi-finger tap.
|
||||
taps: Taps,
|
||||
/// Where the pointer's last move went, until the pointer leaves the window.
|
||||
last_move: Option<Pos2>,
|
||||
}
|
||||
|
||||
/// What one pass's finger events made of the touch.
|
||||
@@ -286,7 +289,20 @@ pub(crate) fn begin(ctx: &Context, hit: HitSizes, latched: craft_keymap::Mods) {
|
||||
let hits = input::hit_targets(ctx);
|
||||
let other_pressed =
|
||||
read.events.iter().any(|event| matches!(event, PointerEvent::Pressed { button: PointerButton::Middle | PointerButton::Secondary, .. }));
|
||||
let (events, targets, touched) = PerViewport::<Memory>::with(ctx, viewport, |memory| {
|
||||
let (events, targets, touched, moved) = PerViewport::<Memory>::with(ctx, viewport, |memory| {
|
||||
// A move stirs the pass when it goes somewhere other than the last move, or carries a pen or touch reading. A
|
||||
// move that repeats the pointer's position does not.
|
||||
let mut moved = false;
|
||||
for event in &read.events {
|
||||
match event {
|
||||
PointerEvent::Moved { at, sample, .. } => {
|
||||
moved |= memory.last_move != Some(*at) || sample.is_some();
|
||||
memory.last_move = Some(*at);
|
||||
}
|
||||
PointerEvent::Gone => memory.last_move = None,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let mut events = read.events.clone();
|
||||
// Every button's press runs on the click run, as a click of any button did in the old apps: a middle-button pan
|
||||
// click between two clicks makes the second a triple click. Only a primary press carries its count.
|
||||
@@ -313,7 +329,7 @@ pub(crate) fn begin(ctx: &Context, hit: HitSizes, latched: craft_keymap::Mods) {
|
||||
if read.primary_pressed || other_pressed {
|
||||
memory.press_targets = PressTargets { click: hits.0, drag: hits.1 };
|
||||
}
|
||||
(events, memory.press_targets, memory.taps.feed(&read.touches, read.time))
|
||||
(events, memory.press_targets, memory.taps.feed(&read.touches, read.time), moved)
|
||||
});
|
||||
// Where a modal holds the wheel off the canvas, a tap is not reported and a touch under way is dropped, by the
|
||||
// wheel's own rule.
|
||||
@@ -355,7 +371,7 @@ pub(crate) fn begin(ctx: &Context, hit: HitSizes, latched: craft_keymap::Mods) {
|
||||
primary_down: read.primary_down,
|
||||
press_targets: targets,
|
||||
focus_lost: read.focus_lost,
|
||||
stirred: read.stirred,
|
||||
stirred: read.stirred || moved,
|
||||
gesture: touched.landed,
|
||||
};
|
||||
let hover_at = pass_pointer.hover;
|
||||
|
||||
Reference in new issue
Block a user