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: WidgetIdThe scrollable area’s identity.
viewport: RectThe viewport, in absolute coordinates.
max_x: f32Largest horizontal offset the content may rest at (0 = nothing to scroll).
max_y: f32Largest vertical offset the content may rest at.
axis: AxisThe axis the area scrolls along (milestone 649): what an area that is always scrollable takes a drag along when nothing overflows.
physics: ScrollPhysicsHow 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: VelocityStrategyHow 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: boolWhether the horizontal axis is reversed — offset 0 is the right-hand end of the content rather than the left.
reverse_y: boolWhether 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
impl Scrollable
Sourcepub fn velocity_tracker(&self) -> VelocityTracker
pub fn velocity_tracker(&self) -> VelocityTracker
The tracker a drag on this area reads its fling with.
Sourcepub fn accepts_user_offset(&self, offset: (f32, f32)) -> bool
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.
Sourcepub fn takes_user_scroll(&self, down: bool) -> bool
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.
Sourcepub fn metrics_x(&self, offset: f32) -> ScrollMetrics
pub fn metrics_x(&self, offset: f32) -> ScrollMetrics
The horizontal axis as the physics sees it, at offset.
Sourcepub fn metrics_y(&self, offset: f32) -> ScrollMetrics
pub fn metrics_y(&self, offset: f32) -> ScrollMetrics
The vertical axis as the physics sees it, at offset.
Sourcepub fn offset_delta(&self, screen: (f32, f32)) -> (f32, f32)
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.
Sourcepub fn refused_edge(&self, vertical: bool, refused: f32) -> GlowEdge
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.
Sourcepub fn start_edge(&self, vertical: bool) -> GlowEdge
pub fn start_edge(&self, vertical: bool) -> GlowEdge
The edge an axis starts at, which is where a pull-to-refresh listens.
Sourcepub fn reveal(
&self,
target: Rect,
current: (f32, f32),
) -> ((f32, f32), (f32, f32))
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.
Sourcepub fn centre(
&self,
target: Rect,
current: (f32, f32),
) -> ((f32, f32), (f32, f32))
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.
Sourcepub fn keep_offset(&self, keep: KeepVisible) -> ((f32, f32), (f32, f32))
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.
Sourcepub fn content_origin(&self, offset: (f32, f32), content: Size) -> (f32, f32)
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
impl Clone for Scrollable
Source§fn clone(&self) -> Scrollable
fn clone(&self) -> Scrollable
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 Scrollable
Auto Trait Implementations§
impl Freeze for Scrollable
impl RefUnwindSafe for Scrollable
impl Send for Scrollable
impl Sync for Scrollable
impl Unpin for Scrollable
impl UnsafeUnpin for Scrollable
impl UnwindSafe for Scrollable
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> 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.