Skip to main content

ScrollableBehavior

Struct ScrollableBehavior 

Source
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

Source

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.

Source

pub fn with_scroller(self, scroller: Rc<RefCell<KineticScroller>>) -> Self

Use the caller’s scroller rather than the one new made.

Source

pub fn axes(self, axes: PanAxes) -> Self

Which axes a finger may pan.

Source

pub fn overscroll(self, behavior: OverscrollBehavior) -> Self

Whether a boundary scroll chains outward or is absorbed.

Source

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.

Source

pub fn overscroll_style(self, style: OverscrollStyle) -> Self

Which overscroll feel to use when the band is on.

Source

pub fn smooth(self, on: bool) -> Self

Whether a wheel notch tweens to its target.

Source

pub fn smooth_duration(self, duration: Duration) -> Self

How long that tween lasts.

Source

pub fn line_height(self, pixels: f32) -> Self

Pixels one line of a ScrollDelta::Lines notch is worth.

Source

pub fn pan_devices(self, devices: PointerKindMask) -> Self

Which pointer kinds may pan this surface.

Source

pub fn reduced_motion(self, reduced: bool) -> Self

prefers-reduced-motion, read from the build context.

Source

pub fn physics(self, physics: ScrollPhysicsTokens) -> Self

The theme’s scroll-physics constants, for the rubber-band curve.

Source

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, and r is the surface’s answer to it”. The shared treatment does not run at all. Both a surface’s own scroll-adjacent events (ScrollIntoView is the usual one) and an arm that rewrote the event and fed the rewrite to handle_scroll_event itself take this branch — including when the rewrite could not move, where the answer is Some(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.

Source

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.

Source

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.

Source

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).

Source

pub fn install(self, handlers: HandlerSet) -> HandlerSet

Attach the pan claim and the scroll handler to handlers.

Trait Implementations§

Source§

impl Debug for ScrollableBehavior

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more