Skip to main content

Scrollable

Struct Scrollable 

Source
pub struct Scrollable {
Show 14 fields pub id: WidgetId, pub viewport: Rect, pub max_x: f32, pub max_y: f32, pub axis: Axis, pub physics: ScrollPhysics, pub overscroll: Option<OverscrollIndicator>, pub fling: VelocityStrategy, pub refresh: Option<WidgetId>, pub page: Option<PageSnap>, pub reverse_x: bool, pub reverse_y: bool, pub keep_visible: Option<KeepVisible>, pub host: Option<WidgetId>,
}
Expand description

A scrollable area of the frame: where it is, how far it may scroll, and how it is meant to behave at its edges.

The registry the shell and the runtime both read. What the area does when it is dragged, flung or pulled past an edge is settled when it is registered: its own physics if it asked for some, else what the ScrollBehavior in force there says, under the theme it is laid out in (milestone 616).

Fields§

§id: WidgetId

The scrollable area’s identity.

§viewport: Rect

The viewport, in absolute coordinates.

§max_x: f32

Largest horizontal offset the content may rest at (0 = nothing to scroll).

§max_y: f32

Largest vertical offset the content may rest at.

§axis: Axis

The axis the area scrolls along (milestone 649): what an area that is always scrollable takes a drag along when nothing overflows.

§physics: ScrollPhysics

How the area moves at its edges and after a fling: its own, when it asked for some, else its scroll behaviour’s.

§overscroll: Option<OverscrollIndicator>

What the area shows when pulled past an edge it will not move beyond, from its scroll behaviour; None for nothing.

§fling: VelocityStrategy

How a fling on this area is read from the finger’s last moves, from its scroll behaviour.

§refresh: Option<WidgetId>

The crate::RefreshIndicator area this scrollable sits inside, when there is one. Movement refused at its top edge feeds that area’s pull instead of the overscroll glow.

§page: Option<PageSnap>

Set when this area rests only on pages (crate::PageView): the release springs to a page boundary instead of flinging.

§reverse_x: bool

Whether the horizontal axis is reversed — offset 0 is the right-hand end of the content rather than the left.

§reverse_y: bool

Whether the vertical axis is reversed — offset 0 is the bottom of the content rather than the top.

Offsets are measured from the end an axis starts at, which is what makes a reversed list stay where it is when content arrives: a conversation resting at offset 0 is resting at the newest message, and the newest message is wherever the end now happens to be. Measuring from the top instead would leave the view drifting away from the end every time something was appended, which is the one thing this exists to prevent.

Everything the user does is unchanged by it. A finger pushes the content the way it moves, in either direction; only the arithmetic between that push and the number changes sign, in one place.

§keep_visible: Option<KeepVisible>

What the content asked to be kept in view, in the frame’s coordinates.

§host: Option<WidgetId>

The scroll region this one sits inside, when there is one.

Scroll areas nest — a sideways strip inside a page that scrolls down — and bringing something into view means moving every one of them, from the nearest outwards. Identities are hashes and carry no ancestry, so the walk records it.

Implementations§

Source§

impl Scrollable

Source

pub fn velocity_tracker(&self) -> VelocityTracker

The tracker a drag on this area reads its fling with.

Source

pub fn accepts_user_offset(&self, offset: (f32, f32)) -> bool

Whether a finger may move this area at all, resting at offset.

The rule the reference states plainly: the user can change the offset if, and only if, there is content outside the viewport to reveal — or the content is already displaced, having shrunk under an offset it no longer reaches. An area that fails this takes no drag at all: not a short one, not a refused one, and so no end-of-content glow either. An edge effect where there is no edge to meet is a statement about the content that is not true.

A crate::RefreshIndicator listening above is the exception, and the same one the reference makes: a list of two items must still pull down to reload.

The physics have the last word (milestone 649): an area the user may never scroll takes nothing, and one the user may always scroll takes everything.

Source

pub fn takes_user_scroll(&self, down: bool) -> bool

Whether a movement of the user’s along the vertical (down) or across is this area’s to take: there is content that way to reveal, or a pull to refresh above for a movement down — unless the physics say never, or always along its axis.

Source

pub fn metrics_x(&self, offset: f32) -> ScrollMetrics

The horizontal axis as the physics sees it, at offset.

Source

pub fn metrics_y(&self, offset: f32) -> ScrollMetrics

The vertical axis as the physics sees it, at offset.

Source

pub fn offset_delta(&self, screen: (f32, f32)) -> (f32, f32)

Turns a screen delta — how far the content was pushed, in pixels — into the change it makes to this area’s offsets.

Two sign changes, and both have a reason. The content moves opposite the number: dragging down reveals what is above, which is a smaller offset. And a reversed axis counts from the other end, so the same drag raises it instead.

One function rather than a minus sign at each of the five places a delta becomes an offset — the wheel, the drag, the release fling, and both axes of each — so that a reversed scroll is right in all of them or in none.

Source

pub fn refused_edge(&self, vertical: bool, refused: f32) -> GlowEdge

The edge a refusal happened at, given the refused movement in offset space.

A negative refusal means the content was pulled towards the axis’s start, and where that is on screen is exactly what reversing changes: the start of a reversed vertical axis is the bottom. Without this the glow would flash at the far end of a conversation the moment it refused to go further back.

Source

pub fn start_edge(&self, vertical: bool) -> GlowEdge

The edge an axis starts at, which is where a pull-to-refresh listens.

Source

pub fn reveal( &self, target: Rect, current: (f32, f32), ) -> ((f32, f32), (f32, f32))

The offset that brings target fully inside this viewport, and how far the content moves to get there.

The least movement that does it: a box already in view does not budge, one off the near edge comes to that edge and no further. Centring it instead would make Tab through a form scroll on every stop, which is motion nobody asked for.

A target too big for the viewport gets its leading edge aligned, which falls out of asking about that edge first: a tall field half off the top comes down to the top rather than up to the bottom, because its start is what you read.

Both halves are returned because they are not the same number. The offset is clamped to what this region can actually do, and an outer region has to be told how far the target really moved — not how far it was asked to.

Source

pub fn centre( &self, target: Rect, current: (f32, f32), ) -> ((f32, f32), (f32, f32))

The offset that puts target in the middle of this viewport, and how far the content moves to get there.

The same pair as Scrollable::reveal, and the same clamp — which is what makes the first item of a row rest at the start rather than half off it. A target bigger than the viewport centres too, which leaves it hanging over both edges, and that is the honest answer: there is no offset that shows all of it.

Source

pub fn keep_offset(&self, keep: KeepVisible) -> ((f32, f32), (f32, f32))

The offset that brings keep into view under its own policy, and how far the content moves from rest to get there.

Absolute, because KeepVisible::rect is recorded at rest: the base is offset zero, not wherever the region currently is.

Source

pub fn content_origin(&self, offset: (f32, f32), content: Size) -> (f32, f32)

Where the content’s leading edge sits, relative to the viewport’s, at offset.

Normally minus the offset. On a reversed axis the content is anchored to the far end, so offset 0 puts the content’s end against the viewport’s — which is also the answer for content too short to scroll, where it sits at the bottom of the box rather than the top.

Trait Implementations§

Source§

impl Clone for Scrollable

Source§

fn clone(&self) -> Scrollable

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Scrollable

Source§

impl Debug for Scrollable

Source§

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

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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<Msg> IntoMsg<Msg> for Msg

Source§

fn defer(work: impl Fn() -> Msg + 'static) -> Msg

The message that stands for work’s result.
Source§

impl<T> MaybeSend for T
where T: Send,

Source§

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

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