pub struct ScrollState { /* private fields */ }Expand description
State object for scroll position tracking.
Holds the current scroll offset and provides methods to programmatically
control scrolling. Can be created with rememberScrollState().
This is a pure scroll model - it does NOT store ephemeral gesture/pointer state. Gesture state is managed locally in the scroll modifier.
Implementations§
Source§impl ScrollState
impl ScrollState
Sourcepub fn new(initial: f32) -> ScrollState
pub fn new(initial: f32) -> ScrollState
Creates a new ScrollState with the given initial scroll position.
Sourcepub fn set_settle_policy(&self, policy: Option<Rc<dyn Fn(f32, f32) -> f32>>)
pub fn set_settle_policy(&self, policy: Option<Rc<dyn Fn(f32, f32) -> f32>>)
Installs (or clears) the settle policy consulted when interactions end.
Sourcepub fn settle_policy(&self) -> Option<Rc<dyn Fn(f32, f32) -> f32>>
pub fn settle_policy(&self) -> Option<Rc<dyn Fn(f32, f32) -> f32>>
The currently installed settle policy, if any.
Sourcepub fn value(&self) -> f32
pub fn value(&self) -> f32
Gets the current scroll position in pixels (reactive - triggers recomposition).
Use this in Composable functions when you want UI to update on scroll.
Example: Text("Scroll position: ${scrollState.value()}")
Sourcepub fn value_non_reactive(&self) -> f32
pub fn value_non_reactive(&self) -> f32
Gets the current scroll position in pixels (non-reactive).
Use this in layout/measure phase to avoid triggering recomposition. This is called internally by ScrollNode::measure().
Sourcepub fn dispatch_raw_delta(&self, delta: f32) -> f32
pub fn dispatch_raw_delta(&self, delta: f32) -> f32
Scrolls by the given delta, clamping to valid range [0, max_value]. Returns the actual amount scrolled.
Sourcepub fn viewport_extent(&self) -> f32
pub fn viewport_extent(&self) -> f32
The main-axis extent of the scroll viewport, as the last measure pass resolved it.
Sourcepub fn content_extent(&self) -> f32
pub fn content_extent(&self) -> f32
The whole scrollable content along the main axis.
Sourcepub fn metrics(&self) -> ScrollMetrics
pub fn metrics(&self) -> ScrollMetrics
Everything an indicator needs about this scroll, read together so it cannot mix a position from one frame with an extent from another.
Read outside composition — during draw, or from a gesture — so following a scroll costs no recomposition.
Trait Implementations§
Source§impl Clone for ScrollState
impl Clone for ScrollState
Source§fn clone(&self) -> ScrollState
fn clone(&self) -> ScrollState
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 ScrollState
Auto Trait Implementations§
impl Freeze for ScrollState
impl RefUnwindSafe for ScrollState
impl Send for ScrollState
impl Sync for ScrollState
impl Unpin for ScrollState
impl UnsafeUnpin for ScrollState
impl UnwindSafe for ScrollState
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.