pub struct ScrollPhysics { /* private fields */ }Expand description
The behaviour of a scrollable: its feel at the edges and after a fling, and whether the user may scroll it.
The reference builds these as a chain, each physics a parent to the next —
AlwaysScrollableScrollPhysics(parent: BouncingScrollPhysics()). Here the same chain
is two settings, written the same way round:
ScrollPhysics::BOUNCING.always_scrollable() // bounces, and always takes the drag
ScrollPhysics::NEVER // never takes it, whatever the platform
ScrollPhysics::ALWAYS // always takes it, the platform's feelA setting left open is the platform’s: an area’s physics are laid over its
ScrollBehavior’s with apply_to, as the
reference applies a widget’s physics to the scroll configuration’s.
Implementations§
Source§impl ScrollPhysics
impl ScrollPhysics
Sourcepub const BOUNCING: Self
pub const BOUNCING: Self
Bouncing physics at a finger’s deceleration — the common case, and what
ScrollPhysics::BOUNCING meant before there were two.
Sourcepub const NEVER: Self
pub const NEVER: Self
The user may never scroll it — the reference’s NeverScrollableScrollPhysics — and
the platform’s feel for anything else.
Sourcepub const ALWAYS: Self
pub const ALWAYS: Self
The user may always scroll it, even with everything in sight — the reference’s
AlwaysScrollableScrollPhysics — with the platform’s feel.
Sourcepub const fn bouncing(rate: ScrollDecelerationRate) -> Self
pub const fn bouncing(rate: ScrollDecelerationRate) -> Self
Bouncing physics at rate.
Sourcepub const fn always_scrollable(self) -> Self
pub const fn always_scrollable(self) -> Self
These physics, and the user may always scroll.
Sourcepub const fn never_scrollable(self) -> Self
pub const fn never_scrollable(self) -> Self
These physics, and the user may never scroll.
Sourcepub fn apply_to(self, ancestor: ScrollPhysics) -> ScrollPhysics
pub fn apply_to(self, ancestor: ScrollPhysics) -> ScrollPhysics
These physics laid over ancestor’s — the reference’s applyTo: what these
settle, they keep; what they leave open, ancestor decides.
Sourcepub fn feel(self) -> ScrollFeel
pub fn feel(self) -> ScrollFeel
The feel in force: clamping when nothing settled one.
Sourcepub fn user(self) -> UserScroll
pub fn user(self) -> UserScroll
Whether the user may scroll.
Sourcepub fn deceleration_rate(self) -> Option<ScrollDecelerationRate>
pub fn deceleration_rate(self) -> Option<ScrollDecelerationRate>
The deceleration profile in force, or None for a family that has none.
Source§impl ScrollPhysics
impl ScrollPhysics
Sourcepub fn spring(self) -> SpringDescription
pub fn spring(self) -> SpringDescription
The spring that returns overscrolled content to its edge.
Sourcepub fn min_fling_velocity(self) -> f32
pub fn min_fling_velocity(self) -> f32
The release speed under which a drag does not fling at all.
Bouncing physics decelerates far more gently, so it asks for a more deliberate gesture before it commits to a fling.
Sourcepub fn max_fling_velocity(self) -> f32
pub fn max_fling_velocity(self) -> f32
The cap on a release speed.
A pointing device can be flicked far harder than a finger can — a wheel notch or a two-finger flick on a trackpad reports speeds no fingertip reaches — so the fast profile lifts the ceiling eightfold rather than clipping what the hardware actually said.
Sourcepub fn drag_start_distance_threshold(self) -> f32
pub fn drag_start_distance_threshold(self) -> f32
The distance a finger must cover before the content starts to move, in px.
Bouncing physics asks for a little more, to swallow the small unintended motion of a finger lifting off.
Sourcepub fn carried_momentum(self, existing_velocity: f32) -> f32
pub fn carried_momentum(self, existing_velocity: f32) -> f32
The speed carried over when a fling is thrown on top of one already running — the repeated-swipe speed-up.
Only the bouncing family builds momentum this way; clamping starts each fling from the gesture alone.
Sourcepub fn apply_user_offset(self, metrics: ScrollMetrics, delta: f32) -> f32
pub fn apply_user_offset(self, metrics: ScrollMetrics, delta: f32) -> f32
How much of a finger’s delta actually reaches the offset.
Inside the content it is all of it. Past an edge, the bouncing family applies a friction that falls off quadratically with how far out we already are: the further you pull, the less each pixel of finger buys — the rubber band. Easing back towards the content is measured at the position the gesture is heading to, so releasing tension is easier than adding it.
Sourcepub fn apply_boundary_conditions(
self,
metrics: ScrollMetrics,
value: f32,
) -> f32
pub fn apply_boundary_conditions( self, metrics: ScrollMetrics, value: f32, ) -> f32
The part of a proposed move that must be refused, so that the caller
can apply value - refused.
Clamping physics refuses everything that would leave the content; bouncing physics refuses nothing, and lets the spring deal with it.
Sourcepub fn allows_overscroll(self) -> bool
pub fn allows_overscroll(self) -> bool
May the content be dragged past its edges at all?
Sourcepub fn ballistic(
self,
metrics: ScrollMetrics,
velocity: f32,
) -> Option<Ballistic>
pub fn ballistic( self, metrics: ScrollMetrics, velocity: f32, ) -> Option<Ballistic>
The motion that follows the finger lifting off at velocity (px/s, positive
meaning the offset grows). None when nothing should move.
Sourcepub fn page_ballistic(
self,
metrics: ScrollMetrics,
velocity: f32,
extent: f32,
) -> Option<Ballistic>
pub fn page_ballistic( self, metrics: ScrollMetrics, velocity: f32, extent: f32, ) -> Option<Ballistic>
The motion that follows the finger lifting off a paged area, where the
content may not come to rest between two pages. extent is the distance
from one page to the next.
This replaces the fling rather than correcting it afterwards: a paged view never coasts. Whatever the release speed, the content springs to one page — the next one on a flick, the nearer one otherwise. A fling that crossed three pages and then had to be caught and pulled back would be a different, worse gesture.
Past an edge and still heading out, there is no page to go to, so the ordinary physics takes over — which is what brings the overscroll home, with the platform’s own bounce or clamp.