ui-contract: a multi-finger tap allows its own finger drift (MULTI_TAP_SLOP, 16 pt), not a press's slop

This commit is contained in:
bflatastic committed 2026-11-23 03:47:15 +07:00
1 parent 54af1b5ab0
commit f3119648e0
3 files changed
+15 -8

No files matched your search

+5 -1
View File
@@ -164,7 +164,7 @@ pub enum PressCancel {
Gesture,
}
/// Two or more fingers came down and all lifted within the tap time without moving past the slop.
/// Two or more fingers came down and all lifted within [`MULTI_TAP_TIME`] without moving past [`MULTI_TAP_SLOP`].
#[derive(Clone, Copy, Debug, PartialEq)]
#[non_exhaustive]
pub struct MultiTap {
@@ -357,6 +357,10 @@ pub const MULTI_CLICK_TIME: f64 = 0.3;
/// The longest the fingers of a multi-finger tap may stay down, in seconds.
pub const MULTI_TAP_TIME: f64 = 0.5;
/// How far a finger of a multi-finger tap may move from where it landed, in points: fingers drift more than a
/// pointer does while the others land.
pub const MULTI_TAP_SLOP: f32 = 16.0;
/// The click count of a press at `pos` and `time` with `mods` held, given the previous press `(pos, time, clicks,
/// mods)`: one more when it follows within [`MULTI_CLICK_TIME`] and `slop` of the previous one with the same
/// modifiers, else 1.
+7 -6
View File
@@ -9,7 +9,7 @@ use crate::runtime::egui::{input, pass};
use crate::runtime::frame::{PerViewport, Stamped};
use crate::runtime::inputs::{self, Input};
use crate::runtime::sampler;
use craft_behavior::press::MULTI_TAP_TIME;
use craft_behavior::press::{MULTI_TAP_SLOP, MULTI_TAP_TIME};
use craft_behavior::{
Buttons, MultiTap, MultiTouch, PartRef, PointerButton, PointerEvent, PointerKind, PointerSample, PressCancel, PressStart, ResolveFor, Shape,
Winner, count_clicks, resolve,
@@ -127,7 +127,7 @@ struct Touched {
}
/// The recognizer of the multi-finger tap: the fingers of one touch, where each landed, the most down at once, when
/// the first landed and whether the touch is spoiled (a finger moved past the slop, stayed past [`MULTI_TAP_TIME`] or
/// the first landed and whether the touch is spoiled (a finger moved past [`MULTI_TAP_SLOP`], stayed past [`MULTI_TAP_TIME`] or
/// was cancelled).
#[derive(Default)]
struct Taps {
@@ -139,8 +139,8 @@ struct Taps {
}
impl Taps {
/// Follows the pass's finger events at time `now`; a finger moves `slop` at most in a tap.
fn feed(&mut self, fingers: &[input::Finger], now: f64, slop: f32) -> Touched {
/// Follows the pass's finger events at time `now`.
fn feed(&mut self, fingers: &[input::Finger], now: f64) -> Touched {
let mut touched = Touched { landed: false, tap: None, tracked: None };
for finger in fingers {
match finger.phase {
@@ -156,7 +156,8 @@ impl Taps {
self.most = self.most.max(self.down.len());
}
TouchPhase::Move => {
let moved = self.landed.iter().rev().find(|(id, _)| *id == finger.id).is_some_and(|(_, at)| at.distance(finger.pos) > slop);
let moved =
self.landed.iter().rev().find(|(id, _)| *id == finger.id).is_some_and(|(_, at)| at.distance(finger.pos) > MULTI_TAP_SLOP);
self.spoiled |= moved && self.down.contains(&finger.id);
}
TouchPhase::End | TouchPhase::Cancel => {
@@ -268,7 +269,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, hit.slop))
(events, memory.press_targets, memory.taps.feed(&read.touches, read.time))
});
// 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.
@@ -1,5 +1,6 @@
//! Touch fingers: the multi-finger tap, the modal gate, the second finger that ends a press and the two-finger pan.
use craft_behavior::press::MULTI_TAP_SLOP;
use craft_behavior::{PressCancel, PressPhase, Sense, WheelTaker};
use craft_ui::contract::{Common, Component, Container, ContainerProps, Cx, Mount, Overlay, Props as _, Role, ShowContainer as _};
use craft_ui::style::StyleCx;
@@ -102,7 +103,8 @@ fn two_and_three_fingers_tap_and_a_pinch_a_hold_a_cancel_or_one_finger_do_not()
assert_eq!(taps[0].0 as usize, fingers);
assert!(taps[0].1.distance(centre(fingers)) < 0.5, "the tap is at the fingers' centre: {:?}", taps[0].1);
}
assert!(tapped(2, 0.0, TouchPhase::End, 40.0).is_empty(), "a finger that moved past the slop pinches or pans");
assert_eq!(tapped(2, 0.0, TouchPhase::End, MULTI_TAP_SLOP / 2.0).len(), 1, "a finger may drift past a press's slop while the others land");
assert!(tapped(2, 0.0, TouchPhase::End, MULTI_TAP_SLOP * 2.0).is_empty(), "a finger that moved past the tap's slop pinches or pans");
assert!(tapped(2, 0.6, TouchPhase::End, 0.0).is_empty(), "fingers held past the tap time");
assert!(tapped(2, 0.0, TouchPhase::Cancel, 0.0).is_empty(), "a cancelled touch");
assert!(tapped(1, 0.0, TouchPhase::End, 0.0).is_empty(), "one finger is a press");