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: ScrollbarAxisControlled axis.
bounds: RectComplete viewport bounds in the coordinate space used for hit testing.
metrics: ScrollMetricsVisible and full content extents.
state: ScrollStateCurrent logical content offset.
thickness: f32Painted cross-axis thickness.
min_thumb_len: f32Minimum painted thumb length, capped to the resolved track.
inset: f32Distance between the track and viewport edges.
end_reserve: f32Main-axis space reserved at the trailing end, normally for another bar.
hit_thickness: f32Minimum cross-axis thickness of the pointer hit region.
Implementations§
Source§impl ScrollbarGeometrySpec
impl ScrollbarGeometrySpec
Sourcepub const DEFAULT_HIT_THICKNESS: f32 = 16f32
pub const DEFAULT_HIT_THICKNESS: f32 = 16f32
Default pointer hit thickness used by framework scrollbars.
Sourcepub const fn new(
axis: ScrollbarAxis,
bounds: Rect,
metrics: ScrollMetrics,
state: ScrollState,
) -> Self
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);Sourcepub fn with_paint_metrics(
self,
thickness: f32,
min_thumb_len: f32,
inset: f32,
) -> Self
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));Sourcepub fn with_end_reserve(self, end_reserve: f32) -> Self
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);Sourcepub fn with_hit_thickness(self, hit_thickness: f32) -> Self
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);Sourcepub fn resolve(self) -> Option<ScrollbarGeometry>
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
impl Clone for ScrollbarGeometrySpec
Source§fn clone(&self) -> ScrollbarGeometrySpec
fn clone(&self) -> ScrollbarGeometrySpec
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more