[][src]Struct gravitas::Friction

pub struct Friction { /* fields omitted */ }

a position with velocity that slows down due to drag.

This is good for objects that you fling—the scroll simulation uses this model in combination with a spring. It can also be used in combination with a constant velocity for infinite carousels, such as this one: Gravitas JavaScript Friction Example.

Methods

impl Friction[src]

pub fn new(drag: f32) -> Friction[src]

Create a new friction simulation with the given drag value. For scrolling interfaces where values are in pixels, a drag value of 0.001 feels quite good.

pub fn set(&mut self, x: f32, v: f32)[src]

Set the initial (time = 0.0) position and velocity for the friction simulation.

pub fn time_for_position(&self, p: f32) -> f32[src]

Return the time (in seconds) at which the friction simulation will reach the specified position. This value can be negative (which means the simulation would have reached that position if the velocity had been in the other direction) or not a number (NaN) which means the simulation will never reach that position.

This method is used by the scroll simulation to find out the exact time that the scroll position will go beyond the scroll extent (at which time the velocity is put into a spring simulation which bounces the scroll position back to the extent).

Trait Implementations

impl Simulation for Friction[src]

impl Clone for Friction[src]

impl Copy for Friction[src]

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]