Struct ScrollState

Source
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

Source

pub fn new( viewport_extent: f32, content_extent: f32, ) -> Result<ScrollState, UiError>

Construct a top-aligned scroll state; see the module’s executable recipe.

Source

pub fn viewport_extent(&self) -> f32

Source

pub fn content_extent(&self) -> f32

Source

pub fn offset(&self) -> f32

Source

pub fn max_offset(&self) -> f32

Largest legal offset; zero for an empty viewport or fitting content.

Source

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.

Source

pub fn set_offset(&mut self, offset: f32) -> Result<bool, UiError>

Clamp a finite requested offset, including negative values, to the range.

Source

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.

Source

pub fn page(&mut self, reverse: bool) -> bool

Move one viewport height; reverse selects Page Up. Exhaustion is false.

Source

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.

Source

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.

Source

pub fn content_point(&self, viewport: Rect, point: [f32; 2]) -> Option<[f32; 2]>

Map a half-open viewport hit back into content space. Empty trailing viewport space beyond the content is inert; nonfinite input is rejected.

Source

pub fn reset(&mut self)

Return to the top without forgetting the current extents.

Trait Implementations§

Source§

impl Clone for ScrollState

Source§

fn clone(&self) -> ScrollState

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ScrollState

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for ScrollState

Source§

fn default() -> ScrollState

Returns the “default value” for a type. Read more
Source§

impl PartialEq for ScrollState

Source§

fn eq(&self, other: &ScrollState) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for ScrollState

Source§

impl StructuralPartialEq for ScrollState

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<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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.