Skip to main content

ClampingSimulation

Struct ClampingSimulation 

Source
pub struct ClampingSimulation { /* private fields */ }
Expand description

Android OverScroller’s friction fling, bounded by a scroll range.

The content decelerates along Android’s spline and stops dead at min or max — no overshoot, no bounce. This is the Clamp half of the pair, and the physics every Teksilo scrollable gets unless its theme or its owner asks for the other one.

use std::time::Duration;
use teksilo_core::kinetic::{ClampingSimulation, ScrollSimulation};
use teksilo_tokens::ScrollPhysicsTokens;

let tokens = ScrollPhysicsTokens::DEFAULT;
let sim = ClampingSimulation::new(0.0, 4000.0, -1.0e6, 1.0e6, &tokens);
// Android's getSplineFlingDistance(4000) — see the tests for the arithmetic.
assert!((sim.position(sim.duration()) - 2156.95).abs() < 1.0);
assert!(sim.is_done(sim.duration()));

Implementations§

Source§

impl ClampingSimulation

Source

pub fn new( position: f32, velocity: f32, min: f32, max: f32, tokens: &ScrollPhysicsTokens, ) -> Self

A fling released at position with velocity, confined to [min, max].

Pass a very wide range for an unbounded coast — that is what FlingDriver does, since the widget receiving the re-dispatched deltas owns the real bounds.

Source

pub fn duration(&self) -> Duration

How long the fling runs before the spline itself is spent. The simulation may finish earlier by hitting a bound.

Source

pub fn distance(&self) -> f32

The signed distance the spline covers over its whole duration.

Trait Implementations§

Source§

impl Clone for ClampingSimulation

Source§

fn clone(&self) -> ClampingSimulation

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ClampingSimulation

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl ScrollSimulation for ClampingSimulation

Source§

fn position(&self, t: Duration) -> f32

Where the content is at t, in logical pixels.
Source§

fn velocity(&self, t: Duration) -> f32

How fast the content is moving at t, in logical pixels per second.
Source§

fn is_done(&self, t: Duration) -> bool

Whether the content has come to rest at or before t.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.