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: i32Current horizontal scroll offset in logical pixels.
offset_y: i32Current vertical scroll offset in logical pixels.
content_w: i32Explicit content width in logical pixels.
The maximum horizontal scroll offset is (content_w - viewport_w).max(0).
content_h: i32Explicit content height in logical pixels.
The maximum vertical scroll offset is (content_h - viewport_h).max(0).
axis: ScrollAxisScroll axis supported by this container.
snap: SnapConfigSnap configuration.
snap_align: SnapAlignSnap alignment (which viewport edge a snap point aligns to).
scrollbar_mode: ScrollbarModeScrollbar display mode.
snap_attraction_radius: i32Snap attraction radius in pixels.
Implementations§
Source§impl ScrollState
impl ScrollState
Sourcepub fn new() -> Self
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.
Sourcepub fn max_scroll_y(&self, viewport_h: i32) -> i32
pub fn max_scroll_y(&self, viewport_h: i32) -> i32
Return the maximum allowed vertical scroll offset given a viewport height.
Sourcepub fn max_scroll_x(&self, viewport_w: i32) -> i32
pub fn max_scroll_x(&self, viewport_w: i32) -> i32
Return the maximum allowed horizontal scroll offset given a viewport width.
Sourcepub fn set_offset_y(&mut self, new_y: i32, viewport_h: i32) -> bool
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.
Sourcepub fn set_offset_x(&mut self, new_x: i32, viewport_w: i32) -> bool
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.
Sourcepub fn scrollbar_thumb(&self, viewport: Rect) -> Option<Rect>
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_modeisScrollbarMode::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
Automode) is managed by the caller. - Horizontal axis is deferred (v1 vertical-first, LPAR-05 §17).
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 more