Struct ScrollbarGeometrySpec

Source
pub struct ScrollbarGeometrySpec {
    pub axis: ScrollbarAxis,
    pub bounds: Rect,
    pub metrics: ScrollMetrics,
    pub state: ScrollState,
    pub thickness: f32,
    pub min_thumb_len: f32,
    pub inset: f32,
    pub end_reserve: f32,
    pub hit_thickness: f32,
}
Expand description

Inputs used to resolve one proportional scrollbar.

Geometry is expressed in logical pixels. Self::resolve rejects non-finite values, non-positive extents, and axes without meaningful overflow instead of constructing partially valid rectangles.

§Examples

use ailloli_ui_core::{
    Rect, ScrollMetrics, ScrollState, ScrollbarAxis, ScrollbarGeometrySpec, Size,
};
let geometry = ScrollbarGeometrySpec::new(
    ScrollbarAxis::Vertical,
    Rect::new(0.0, 0.0, 100.0, 80.0),
    ScrollMetrics::new(Size::new(100.0, 80.0), Size::new(100.0, 240.0)),
    ScrollState::new(),
)
.resolve()
.expect("vertical overflow");
assert_eq!(geometry.axis, ScrollbarAxis::Vertical);

Fields§

§axis: ScrollbarAxis

Controlled axis.

§bounds: Rect

Complete viewport bounds in the coordinate space used for hit testing.

§metrics: ScrollMetrics

Visible and full content extents.

§state: ScrollState

Current logical content offset.

§thickness: f32

Painted cross-axis thickness.

§min_thumb_len: f32

Minimum painted thumb length, capped to the resolved track.

§inset: f32

Distance between the track and viewport edges.

§end_reserve: f32

Main-axis space reserved at the trailing end, normally for another bar.

§hit_thickness: f32

Minimum cross-axis thickness of the pointer hit region.

Implementations§

Source§

impl ScrollbarGeometrySpec

Source

pub const DEFAULT_HIT_THICKNESS: f32 = 16f32

Default pointer hit thickness used by framework scrollbars.

Source

pub const fn new( axis: ScrollbarAxis, bounds: Rect, metrics: ScrollMetrics, state: ScrollState, ) -> Self

Creates a specification with the framework’s neutral geometry defaults.

The painted bar is six pixels thick, inset by three pixels, with a 24-pixel minimum thumb and a 16-pixel pointer target.

§Examples
use ailloli_ui_core::{Rect, ScrollMetrics, ScrollState, ScrollbarAxis, ScrollbarGeometrySpec, Size};
let spec = ScrollbarGeometrySpec::new(
    ScrollbarAxis::Horizontal,
    Rect::new(0.0, 0.0, 120.0, 60.0),
    ScrollMetrics::new(Size::new(120.0, 60.0), Size::new(360.0, 60.0)),
    ScrollState::new(),
);
assert_eq!(spec.hit_thickness, 16.0);
Source

pub fn with_paint_metrics( self, thickness: f32, min_thumb_len: f32, inset: f32, ) -> Self

Replaces painted geometry while retaining the standard hit thickness.

§Examples
use ailloli_ui_core::{Rect, ScrollMetrics, ScrollState, ScrollbarAxis, ScrollbarGeometrySpec, Size};
let spec = ScrollbarGeometrySpec::new(
    ScrollbarAxis::Vertical,
    Rect::new(0.0, 0.0, 80.0, 100.0),
    ScrollMetrics::new(Size::new(80.0, 100.0), Size::new(80.0, 300.0)),
    ScrollState::new(),
).with_paint_metrics(4.0, 18.0, 2.0);
assert_eq!((spec.thickness, spec.min_thumb_len, spec.inset), (4.0, 18.0, 2.0));
Source

pub fn with_end_reserve(self, end_reserve: f32) -> Self

Reserves main-axis space at the trailing end of the track.

§Examples
use ailloli_ui_core::{Rect, ScrollMetrics, ScrollState, ScrollbarAxis, ScrollbarGeometrySpec, Size};
let spec = ScrollbarGeometrySpec::new(
    ScrollbarAxis::Vertical,
    Rect::new(0.0, 0.0, 80.0, 100.0),
    ScrollMetrics::new(Size::new(80.0, 100.0), Size::new(80.0, 300.0)),
    ScrollState::new(),
).with_end_reserve(10.0);
assert_eq!(spec.end_reserve, 10.0);
Source

pub fn with_hit_thickness(self, hit_thickness: f32) -> Self

Replaces the minimum pointer-target thickness.

Values smaller than the painted thickness are promoted to the painted thickness during resolution.

§Examples
use ailloli_ui_core::{Rect, ScrollMetrics, ScrollState, ScrollbarAxis, ScrollbarGeometrySpec, Size};
let spec = ScrollbarGeometrySpec::new(
    ScrollbarAxis::Vertical,
    Rect::new(0.0, 0.0, 80.0, 100.0),
    ScrollMetrics::new(Size::new(80.0, 100.0), Size::new(80.0, 300.0)),
    ScrollState::new(),
).with_hit_thickness(20.0);
assert_eq!(spec.hit_thickness, 20.0);
Source

pub fn resolve(self) -> Option<ScrollbarGeometry>

Resolves proportional track, thumb, and pointer geometry.

Overflow of at most half a logical pixel is treated as absent. This avoids flickering bars for floating-point layout noise.

§Examples
use ailloli_ui_core::{Point, Rect, ScrollMetrics, ScrollState, ScrollbarAxis, ScrollbarGeometrySpec, ScrollbarPart, Size};
let geometry = ScrollbarGeometrySpec::new(
    ScrollbarAxis::Vertical,
    Rect::new(0.0, 0.0, 100.0, 100.0),
    ScrollMetrics::new(Size::new(100.0, 100.0), Size::new(100.0, 400.0)),
    ScrollState::new(),
).resolve().unwrap();
let center = Point::new(geometry.thumb.x + geometry.thumb.w * 0.5, geometry.thumb.y + geometry.thumb.h * 0.5);
assert_eq!(geometry.hit_test(center), Some(ScrollbarPart::Thumb));

Trait Implementations§

Source§

impl Clone for ScrollbarGeometrySpec

Source§

fn clone(&self) -> ScrollbarGeometrySpec

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 ScrollbarGeometrySpec

Source§

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

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

impl PartialEq for ScrollbarGeometrySpec

Source§

fn eq(&self, other: &ScrollbarGeometrySpec) -> 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 ScrollbarGeometrySpec

Source§

impl StructuralPartialEq for ScrollbarGeometrySpec

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.