pub struct ScrollState { /* private fields */ }Expand description
Two finite, nonnegative extents and a clamped offset, with no dynamic storage.
Zero viewport height suspends scrolling at offset zero. Invalid operations
return UiError::InvalidLayout without changing the state.
Implementations§
Source§impl ScrollState
impl ScrollState
Sourcepub fn new(
viewport_extent: f32,
content_extent: f32,
) -> Result<ScrollState, UiError>
pub fn new( viewport_extent: f32, content_extent: f32, ) -> Result<ScrollState, UiError>
Construct a top-aligned scroll state; see the module’s executable recipe.
pub fn viewport_extent(&self) -> f32
pub fn content_extent(&self) -> f32
pub fn offset(&self) -> f32
Sourcepub fn max_offset(&self) -> f32
pub fn max_offset(&self) -> f32
Largest legal offset; zero for an empty viewport or fitting content.
Sourcepub fn set_extents(
&mut self,
viewport_extent: f32,
content_extent: f32,
) -> Result<bool, UiError>
pub fn set_extents( &mut self, viewport_extent: f32, content_extent: f32, ) -> Result<bool, UiError>
Resize/reflow, preserving the old offset where possible. Returns whether the offset changed, not whether the extents changed.
Sourcepub fn set_offset(&mut self, offset: f32) -> Result<bool, UiError>
pub fn set_offset(&mut self, offset: f32) -> Result<bool, UiError>
Clamp a finite requested offset, including negative values, to the range.
Sourcepub fn scroll_by(&mut self, delta: f32) -> Result<bool, UiError>
pub fn scroll_by(&mut self, delta: f32) -> Result<bool, UiError>
Move by logical units. Positive deltas scroll down. Finite sums that exceed f32 range saturate at the scroll boundary, never at infinity.
Sourcepub fn page(&mut self, reverse: bool) -> bool
pub fn page(&mut self, reverse: bool) -> bool
Move one viewport height; reverse selects Page Up. Exhaustion is false.
Sourcepub fn ensure_visible(&mut self, top: f32, height: f32) -> Result<bool, UiError>
pub fn ensure_visible(&mut self, top: f32, height: f32) -> Result<bool, UiError>
Reveal a content-space vertical interval using the smallest movement. Oversized intervals align their top edge; empty intervals/viewports do nothing. The whole interval must be inside the declared content extent. No padding is inserted and no text is scaled.
Sourcepub fn translate_rect(
&self,
viewport: Rect,
content: Rect,
) -> Result<Rect, UiError>
pub fn translate_rect( &self, viewport: Rect, content: Rect, ) -> Result<Rect, UiError>
Translate a content rectangle into UI coordinates without clipping it.
The viewport height must match this state’s extent. Content must lie
inside [0, viewport.width] × [0, content_extent]. Apply the viewport
clip separately so a partially visible label keeps its original layout.
Trait Implementations§
Source§impl Clone for ScrollState
impl Clone for ScrollState
Source§fn clone(&self) -> ScrollState
fn clone(&self) -> ScrollState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more