pub struct ScrollState {
pub offset: Offset,
}Expand description
Persistent logical scroll offset. Positive values move the viewport into content.
§Examples
use ailloli_ui_core::{Offset, ScrollState};
assert_eq!(ScrollState::with_offset(Offset::new(4.0, 5.0)).offset.x, 4.0);Fields§
§offset: OffsetLogical content-space offset from the content origin.
Implementations§
Source§impl ScrollState
impl ScrollState
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a state at the content origin.
§Examples
use ailloli_ui_core::{Offset, ScrollState};
assert_eq!(ScrollState::new().offset, Offset::default());Sourcepub fn with_offset(offset: Offset) -> Self
pub fn with_offset(offset: Offset) -> Self
Creates a state whose components are at least zero.
This does not know the content bounds. Use Self::clamp_to once
ScrollMetrics are available. Negative values and NaN become zero;
positive infinity remains infinite until a bounded operation such as
Self::clamp_to maps it to zero.
§Examples
use ailloli_ui_core::{Offset, ScrollState};
assert_eq!(ScrollState::with_offset(Offset::new(-1.0, 2.0)).offset, Offset::new(0.0, 2.0));Sourcepub fn clamp_to(self, metrics: ScrollMetrics, axes: ScrollAxes) -> ScrollOutcome
pub fn clamp_to(self, metrics: ScrollMetrics, axes: ScrollAxes) -> ScrollOutcome
Clamps the current state to the enabled axes and content bounds.
Disabled axes are reset to zero rather than preserving a latent offset.
§Examples
use ailloli_ui_core::{Offset, ScrollAxes, ScrollMetrics, ScrollState, Size};
let metrics = ScrollMetrics::new(Size::new(10.0, 10.0), Size::new(20.0, 20.0));
let out = ScrollState::with_offset(Offset::new(50.0, 5.0)).clamp_to(metrics, ScrollAxes::BOTH);
assert_eq!(out.after, Offset::new(10.0, 5.0));Sourcepub fn scroll_by(
self,
delta: Offset,
metrics: ScrollMetrics,
axes: ScrollAxes,
) -> ScrollOutcome
pub fn scroll_by( self, delta: Offset, metrics: ScrollMetrics, axes: ScrollAxes, ) -> ScrollOutcome
Adds a logical-pixel delta, filters disabled axes, and clamps the result.
Positive deltas move the viewport farther into the content.
§Examples
use ailloli_ui_core::{Offset, ScrollAxes, ScrollMetrics, ScrollState, Size};
let metrics = ScrollMetrics::new(Size::new(10.0, 10.0), Size::new(30.0, 30.0));
assert_eq!(ScrollState::new().scroll_by(Offset::new(4.0, 5.0), metrics, ScrollAxes::BOTH).after, Offset::new(4.0, 5.0));Sourcepub fn scroll_to(
self,
target: Offset,
metrics: ScrollMetrics,
axes: ScrollAxes,
) -> ScrollOutcome
pub fn scroll_to( self, target: Offset, metrics: ScrollMetrics, axes: ScrollAxes, ) -> ScrollOutcome
Moves directly to a logical content offset and clamps it to valid bounds.
Disabled axes and non-finite target components become zero.
§Examples
use ailloli_ui_core::{Offset, ScrollAxes, ScrollMetrics, ScrollState, Size};
let metrics = ScrollMetrics::new(Size::new(10.0, 10.0), Size::new(30.0, 30.0));
assert_eq!(ScrollState::new().scroll_to(Offset::new(8.0, 9.0), metrics, ScrollAxes::BOTH).after, Offset::new(8.0, 9.0));Sourcepub fn reveal_rect(
self,
rect: Rect,
metrics: ScrollMetrics,
axes: ScrollAxes,
) -> ScrollOutcome
pub fn reveal_rect( self, rect: Rect, metrics: ScrollMetrics, axes: ScrollAxes, ) -> ScrollOutcome
Moves the minimum distance needed to expose rect in the viewport.
rect uses content coordinates in logical pixels. Already visible axes
remain unchanged. If a rectangle is larger than the viewport, the first
violated edge chosen by the algorithm is aligned before final clamping.
§Examples
use ailloli_ui_core::{Offset, Rect, ScrollAxes, ScrollMetrics, ScrollState, Size};
let metrics = ScrollMetrics::new(Size::new(100.0, 100.0), Size::new(300.0, 300.0));
let out = ScrollState::new().reveal_rect(Rect::new(120.0, 0.0, 20.0, 20.0), metrics, ScrollAxes::BOTH);
assert_eq!(out.after, Offset::new(40.0, 0.0));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