pub struct KineticScrollStyle {
pub decay_time: f32,
pub stop_distance: f32,
pub rubber_band: bool,
}Expand description
The physics of drag-scrolling a crate::ScrollArea, usually on a touch screen.
Controls how the content keeps coasting after the user lets go (kinetic scrolling), and how it rubber-bands when dragged past the edge.
The velocity decays exponentially, like it does in UIScrollView on iOS/macOS:
v(t) = v₀ · exp(-t / decay_time)which means the total coast distance is v₀ · decay_time,
i.e. proportional to the release velocity.
All distances are in ui points, and all velocities in ui points per second.
Fields§
§decay_time: f32Time constant of the exponential velocity decay, in seconds.
The velocity is reduced by a factor e every decay_time seconds,
and the total coast distance (in ui points) is release_velocity * decay_time,
where release_velocity is in ui points per second.
UIScrollView.DecelerationRate.normal (0.998 per millisecond) corresponds to ≈ 0.5 s,
and .fast (0.99 per millisecond) corresponds to ≈ 0.1 s.
Set to 0.0 to disable kinetic scrolling.
stop_distance: f32Stop the kinetic scrolling when the remaining coast distance is shorter than this many ui points.
The exponential decay never reaches zero velocity on its own, so we need a cutoff.
rubber_band: boolLet the user drag (or coast) past the edge of the content, with increasing resistance, and spring back when released. Like iOS and macOS.
Affects drag-to-scroll (touch) and trackpad scrolling, not mouse wheels or scroll bars.
Implementations§
Source§impl KineticScrollStyle
impl KineticScrollStyle
Sourcepub fn decay_time_from_deceleration_rate_per_ms(rate: f32) -> f32
pub fn decay_time_from_deceleration_rate_per_ms(rate: f32) -> f32
Convert from a per-millisecond deceleration rate (as used by UIScrollView.DecelerationRate)
to a Self::decay_time in seconds.
0.998 (iOS normal) ≈ 0.5 s, 0.99 (iOS fast) ≈ 0.1 s.
pub fn ui(&mut self, ui: &mut Ui)
Trait Implementations§
Source§impl Clone for KineticScrollStyle
impl Clone for KineticScrollStyle
Source§fn clone(&self) -> KineticScrollStyle
fn clone(&self) -> KineticScrollStyle
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for KineticScrollStyle
Source§impl Debug for KineticScrollStyle
impl Debug for KineticScrollStyle
Source§impl Default for KineticScrollStyle
impl Default for KineticScrollStyle
Source§fn default() -> KineticScrollStyle
fn default() -> KineticScrollStyle
Source§impl PartialEq for KineticScrollStyle
impl PartialEq for KineticScrollStyle
impl StructuralPartialEq for KineticScrollStyle
Auto Trait Implementations§
impl Forget for KineticScrollStyle
impl Freeze for KineticScrollStyle
impl Move for KineticScrollStyle
impl RefUnwindSafe for KineticScrollStyle
impl Send for KineticScrollStyle
impl Sync for KineticScrollStyle
impl Unpin for KineticScrollStyle
impl UnsafeUnpin for KineticScrollStyle
impl UnwindSafe for KineticScrollStyle
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 more