pub struct VelocityTracker { /* private fields */ }Expand description
The speed and direction of a pointer, measured over a short trailing window.
The window rather than the last two events is the whole point. Platforms deliver moves at whatever rate they please, so the last pair can be a millisecond apart and report an impossible speed, and — more importantly — a gesture that stopped before release still has old fast samples behind it. Samples older than the window are discarded, so a drag the user parked reports a stop rather than the speed it had before the pause. A tracker that reported one would fling away the thing the user deliberately put down.
Implementations§
Source§impl VelocityTracker
impl VelocityTracker
pub fn new() -> Self
pub fn with_window(window: Duration) -> Self
Sourcepub fn sample(&mut self, position: Point<Pixels>, at: Instant)
pub fn sample(&mut self, position: Point<Pixels>, at: Instant)
Records where the pointer was at at.
A sample older than one already recorded is ignored: the tracker measures a gesture forward in time, and reordering events would let a late delivery invent a direction.
Sourcepub fn velocity_at(&self, now: Instant) -> Velocity
pub fn velocity_at(&self, now: Instant) -> Velocity
The speed the pointer is moving at as of now.
now rather than the last sample, because a pointer that has stopped
sends nothing at all: the pause is visible only against a clock.
Trait Implementations§
Source§impl Clone for VelocityTracker
impl Clone for VelocityTracker
Source§fn clone(&self) -> VelocityTracker
fn clone(&self) -> VelocityTracker
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for VelocityTracker
impl Debug for VelocityTracker
Auto Trait Implementations§
impl Freeze for VelocityTracker
impl RefUnwindSafe for VelocityTracker
impl Send for VelocityTracker
impl Sync for VelocityTracker
impl Unpin for VelocityTracker
impl UnsafeUnpin for VelocityTracker
impl UnwindSafe for VelocityTracker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().