pub struct ScrollLink { /* private fields */ }Expand description
Scroll offsets mapped onto progress from 0 to 1.
§Reduced motion
A link makes no decision of its own, and that is deliberate rather than lazy. A header that collapses as the content scrolls under it, or a shadow that appears once there is something above the fold, is not gratuitous motion: it is a direct, one-to-one response to a movement the user is making with their own hand, and suppressing it would remove information rather than calm. A decorative parallax — a background drifting at a different rate to say nothing at all — is the opposite, and under reduced motion it should not drift.
Only the caller knows which of those it is building, so the caller says so
with ScrollLink::decorative. A decorative link marked under reduced
motion reports 0 at every offset, which is the resting end of the effect:
the parallax layer simply sits where it belongs.
Implementations§
Source§impl ScrollLink
impl ScrollLink
Sourcepub fn new(start: Pixels, end: Pixels) -> Self
pub fn new(start: Pixels, end: Pixels) -> Self
Over the offsets start..end, measured the way a reader thinks about
scrolling: 0 is the top of the content and the number grows as the
content moves up.
A range with no length is a threshold rather than a ramp: progress is 0 below it and 1 from it on.
Sourcepub fn decorative(self, reduce_motion: bool) -> Self
pub fn decorative(self, reduce_motion: bool) -> Self
Marks the effect decorative, and suppresses it when the user has asked for less motion.
Pass reduce_motion. A link left unmarked
always reports the offset, because a response to the user’s own
scrolling is not the motion the preference is about.
Sourcepub fn progress(self, offset: Pixels) -> f32
pub fn progress(self, offset: Pixels) -> f32
Where offset sits in the range: 0 before it, 1 after it, and
monotonically between.
Sourcepub fn sample<T: Interpolate>(self, offset: Pixels, from: T, to: T) -> T
pub fn sample<T: Interpolate>(self, offset: Pixels, from: T, to: T) -> T
Anything interpolable, read off the offset.
Anything that takes a progress can be driven from here, including
Keyframes::sample for a value that passes
through stops on the way.
Trait Implementations§
Source§impl Clone for ScrollLink
impl Clone for ScrollLink
Source§fn clone(&self) -> ScrollLink
fn clone(&self) -> ScrollLink
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 ScrollLink
Source§impl Debug for ScrollLink
impl Debug for ScrollLink
Source§impl PartialEq for ScrollLink
impl PartialEq for ScrollLink
impl StructuralPartialEq for ScrollLink
Auto Trait Implementations§
impl Freeze for ScrollLink
impl RefUnwindSafe for ScrollLink
impl Send for ScrollLink
impl Sync for ScrollLink
impl Unpin for ScrollLink
impl UnsafeUnpin for ScrollLink
impl UnwindSafe for ScrollLink
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