pub struct ScrollableBehavior { /* private fields */ }Expand description
The whole of what a widget must do to become scrollable, as one value it
installs onto its HandlerSet.
Two halves, and both matter. The on_scroll handler is the arithmetic;
the PanClaim is what puts the node on the claimant chain a synthesised
pan walks. Installing one without the other yields a surface that scrolls on
a wheel and ignores a finger, which is exactly the state this crate was in
before this module.
Implementations§
Source§impl ScrollableBehavior
impl ScrollableBehavior
Sourcepub fn new(axes: ScrollableAxes) -> Self
pub fn new(axes: ScrollableAxes) -> Self
A behaviour over axes, with a scroller of its own.
A surface that must reach the scroller from its layout pass (to publish
its viewport, which is what the rubber-band curve is a fraction of)
keeps its own handle and passes it to
with_scroller instead, so the physics survives
a rebuild.
Sourcepub fn with_scroller(self, scroller: Rc<RefCell<KineticScroller>>) -> Self
pub fn with_scroller(self, scroller: Rc<RefCell<KineticScroller>>) -> Self
Use the caller’s scroller rather than the one new made.
Sourcepub fn overscroll(self, behavior: OverscrollBehavior) -> Self
pub fn overscroll(self, behavior: OverscrollBehavior) -> Self
Whether a boundary scroll chains outward or is absorbed.
Sourcepub fn rubber_band(self, on: bool) -> Self
pub fn rubber_band(self, on: bool) -> Self
Follow the finger past the end with decreasing gain. See
ScrollHandlingOptions::rubber_band for why this is off by default.
Sourcepub fn overscroll_style(self, style: OverscrollStyle) -> Self
pub fn overscroll_style(self, style: OverscrollStyle) -> Self
Which overscroll feel to use when the band is on.
Sourcepub fn smooth_duration(self, duration: Duration) -> Self
pub fn smooth_duration(self, duration: Duration) -> Self
How long that tween lasts.
Sourcepub fn line_height(self, pixels: f32) -> Self
pub fn line_height(self, pixels: f32) -> Self
Pixels one line of a ScrollDelta::Lines notch is worth.
Sourcepub fn pan_devices(self, devices: PointerKindMask) -> Self
pub fn pan_devices(self, devices: PointerKindMask) -> Self
Which pointer kinds may pan this surface.
Sourcepub fn reduced_motion(self, reduced: bool) -> Self
pub fn reduced_motion(self, reduced: bool) -> Self
prefers-reduced-motion, read from the build context.
Sourcepub fn physics(self, physics: ScrollPhysicsTokens) -> Self
pub fn physics(self, physics: ScrollPhysicsTokens) -> Self
The theme’s scroll-physics constants, for the rubber-band curve.
Sourcepub fn before(
self,
arm: impl Fn(&WidgetEvent, &mut EventContext<'_>) -> Option<EventResponse> + 'static,
) -> Self
pub fn before( self, arm: impl Fn(&WidgetEvent, &mut EventContext<'_>) -> Option<EventResponse> + 'static, ) -> Self
An arm the installed handler runs first, for every event.
The answer is an Option, and the two halves of it are different
questions:
None— “not mine”. The shared treatment then runs on the same, unmodified event. This is what an observing arm returns: a surface doing per-scroll bookkeeping before the delta lands looks, records, and declines.Some(r)— “this event is mine, andris the surface’s answer to it”. The shared treatment does not run at all. Both a surface’s own scroll-adjacent events (ScrollIntoViewis the usual one) and an arm that rewrote the event and fed the rewrite tohandle_scroll_eventitself take this branch — including when the rewrite could not move, where the answer isSome(Ignored)so the whole original event chains outward.
That last case is why this is an Option and not an EventResponse.
A Handled-means-short-circuit rule cannot express “I consumed this
event and the answer is Ignored”, so a remapping arm — the tables’
Shift+wheel — would fall through and have the shared handler apply the
original delta on top of the remapped one it just declined.
Sourcepub fn after(
self,
arm: impl Fn(&WidgetEvent, EventResponse, &mut EventContext<'_>) + 'static,
) -> Self
pub fn after( self, arm: impl Fn(&WidgetEvent, EventResponse, &mut EventContext<'_>) + 'static, ) -> Self
An arm the installed handler runs last, once the delta has landed.
It sees the event and the answer the surface is about to give, and can change neither: contradicting the boundary answer is how a chain stops working. It is for the bookkeeping a surface can only do after the offset moved — asking for a repaint being the one that matters, on a surface whose offset signals are read at paint rather than bound to the node.
It runs on every path, including the one where a
before arm claimed the event — a before arm that
answers Handled has moved the offset itself, which is exactly the
case this arm exists to notice.
Sourcepub fn scroller(&self) -> Rc<RefCell<KineticScroller>>
pub fn scroller(&self) -> Rc<RefCell<KineticScroller>>
The scroller this behaviour will use, for a surface that must publish its viewport into it from layout.
Sourcepub fn options(&self) -> ScrollHandlingOptions
pub fn options(&self) -> ScrollHandlingOptions
The options this behaviour resolved to. Exposed for a surface that wants to answer the same boundary question from a second call site (a keyboard page, an AT scroll action).
Sourcepub fn install(self, handlers: HandlerSet) -> HandlerSet
pub fn install(self, handlers: HandlerSet) -> HandlerSet
Attach the pan claim and the scroll handler to handlers.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for ScrollableBehavior
impl !Send for ScrollableBehavior
impl !Sync for ScrollableBehavior
impl !UnwindSafe for ScrollableBehavior
impl Freeze for ScrollableBehavior
impl Unpin for ScrollableBehavior
impl UnsafeUnpin for ScrollableBehavior
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.impl<T> ErasedDestructor for Twhere
T: 'static,
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