Struct ScrollState

Source
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: Offset

Logical content-space offset from the content origin.

Implementations§

Source§

impl ScrollState

Source

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());
Source

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));
Source

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));
Source

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));
Source

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));
Source

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

Source§

fn clone(&self) -> ScrollState

Returns a copy 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

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

Source§

type Output = T

Should always be Self
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.