Skip to main content

ScrollState

Struct ScrollState 

Source
pub struct ScrollState {
    pub offset_x: i32,
    pub offset_y: i32,
    pub content_w: i32,
    pub content_h: i32,
    pub axis: ScrollAxis,
    pub snap: SnapConfig,
    pub snap_align: SnapAlign,
    pub scrollbar_mode: ScrollbarMode,
    pub snap_attraction_radius: i32,
}
Expand description

Scroll metadata owned by a scrollable ObjectNode.

Attach via ObjectNode::set_scroll_state. The node’s SCROLLABLE flag is set automatically.

§Content extent and viewport

The viewport size is derived from the node’s Widget::bounds() at the time of each scroll computation. The maximum scroll offset is:

max_scroll_y = (content_h - viewport_h).max(0)
max_scroll_x = (content_w - viewport_w).max(0)

LPAR-05 §5: SCROLLABLE is independent of actual overflow; the content extent is supplied explicitly (LPAR-10 will compute it from layout later).

Fields§

§offset_x: i32

Current horizontal scroll offset in logical pixels.

§offset_y: i32

Current vertical scroll offset in logical pixels.

§content_w: i32

Explicit content width in logical pixels.

The maximum horizontal scroll offset is (content_w - viewport_w).max(0).

§content_h: i32

Explicit content height in logical pixels.

The maximum vertical scroll offset is (content_h - viewport_h).max(0).

§axis: ScrollAxis

Scroll axis supported by this container.

§snap: SnapConfig

Snap configuration.

§snap_align: SnapAlign

Snap alignment (which viewport edge a snap point aligns to).

§scrollbar_mode: ScrollbarMode

Scrollbar display mode.

§snap_attraction_radius: i32

Snap attraction radius in pixels.

Implementations§

Source§

impl ScrollState

Source

pub fn new() -> Self

Create default scroll state for a vertical-only container.

Content extent must be updated via Self::content_w / Self::content_h before scroll is meaningful.

Source

pub fn max_scroll_y(&self, viewport_h: i32) -> i32

Return the maximum allowed vertical scroll offset given a viewport height.

Source

pub fn max_scroll_x(&self, viewport_w: i32) -> i32

Return the maximum allowed horizontal scroll offset given a viewport width.

Source

pub fn set_offset_y(&mut self, new_y: i32, viewport_h: i32) -> bool

Clamp and set the vertical offset; returns true if it changed.

Source

pub fn set_offset_x(&mut self, new_x: i32, viewport_w: i32) -> bool

Clamp and set the horizontal offset; returns true if it changed.

Source

pub fn scrollbar_thumb(&self, viewport: Rect) -> Option<Rect>

Compute the vertical scrollbar thumb rect in screen space for the given viewport Rect, using the same formula as ScrollView::scrollbar_thumb() (widgets/src/scroll_view.rs lines 139–158).

Returns None when:

  • scrollbar_mode is ScrollbarMode::Off, or
  • the content does not overflow the viewport (content_h ≤ viewport.height).

The returned rect is positioned on the right edge of viewport with width SCROLLBAR_WIDTH and a gap of SCROLLBAR_MARGIN pixels. Thumb height is computed as:

thumb_h = (viewport_h² / content_h).clamp(SCROLLBAR_MIN_THUMB, viewport_h)

Thumb position reflects the current offset_y: at offset 0 the thumb sits at the top of the track; at max_scroll_y the thumb sits at the bottom.

§Notes
  • Rendering and Auto-mode visibility are the consuming widget’s responsibility. This method returns geometry only; whether the scrollbar is currently visible (e.g. during an active session in Auto mode) is managed by the caller.
  • Horizontal axis is deferred (v1 vertical-first, LPAR-05 §17).

Trait Implementations§

Source§

impl Clone for ScrollState

Source§

fn clone(&self) -> ScrollState

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 Debug for ScrollState

Source§

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

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

impl Default for ScrollState

Source§

fn default() -> Self

Returns the “default value” for a type. 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> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
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.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.