pub enum ScrollPhysics {
Bouncing(ScrollDecelerationRate),
Clamping,
}Expand description
The behaviour of a scrollable at its edges and after a fling.
Variants§
Bouncing(ScrollDecelerationRate)
Overscroll is allowed, resisted, and springs back — at the given rate.
Clamping
Overscroll is refused; a fling stops at the edge.
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 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 const fn platform_default() -> Self
pub const fn platform_default() -> Self
What the running platform expects. Bouncing where the system scroll views bounce, clamping everywhere else.
This is resolved at compile time from the target, not at runtime: a build is for one platform, and a constant keeps the choice out of the frame loop.
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.