pub struct ScrollbarGeometry {
pub axis: ScrollbarAxis,
pub track: Rect,
pub thumb: Rect,
pub hit_track: Rect,
pub viewport_extent: f32,
pub max_offset: f32,
}Expand description
Resolved proportional scrollbar geometry in one coordinate space.
track and thumb are paint rectangles. hit_track may be wider than the
paint while remaining clipped to the original viewport.
§Examples
use ailloli_ui_core::{Rect, ScrollMetrics, ScrollState, ScrollbarAxis, ScrollbarGeometrySpec, Size};
let geometry = ScrollbarGeometrySpec::new(
ScrollbarAxis::Horizontal,
Rect::new(0.0, 0.0, 100.0, 60.0),
ScrollMetrics::new(Size::new(100.0, 60.0), Size::new(300.0, 60.0)),
ScrollState::new(),
).resolve().unwrap();
assert!(geometry.hit_track.h >= geometry.track.h);Fields§
§axis: ScrollbarAxisControlled axis.
track: RectPainted track bounds.
thumb: RectPainted proportional thumb bounds.
hit_track: RectPointer target containing the track and expanded cross-axis area.
viewport_extent: f32Visible content extent along Self::axis.
max_offset: f32Greatest valid content offset along Self::axis.
Implementations§
Source§impl ScrollbarGeometry
impl ScrollbarGeometry
Sourcepub fn hit_test(self, point: Point) -> Option<ScrollbarPart>
pub fn hit_test(self, point: Point) -> Option<ScrollbarPart>
Returns the thumb or the track side containing point.
§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, 300.0)),
ScrollState::new(),
).resolve().unwrap();
assert_eq!(geometry.hit_test(Point::new(geometry.track.x, geometry.track.bottom())), Some(ScrollbarPart::TrackAfter));Sourcepub fn page_target(self, current_offset: f32, part: ScrollbarPart) -> f32
pub fn page_target(self, current_offset: f32, part: ScrollbarPart) -> f32
Computes a one-viewport page target for a track hit.
Thumb hits leave the current offset unchanged. All results are finite
and clamped to 0.0..=max_offset.
§Examples
use ailloli_ui_core::{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();
assert_eq!(geometry.page_target(40.0, ScrollbarPart::TrackAfter), 140.0);Sourcepub fn track_target(self, point: Point) -> f32
pub fn track_target(self, point: Point) -> f32
Maps a track position to an offset with the thumb centered on the point.
The result is clamped at both track ends. Callers normally use this for
a press outside the thumb; thumb presses should retain their exact grab
offset through Self::begin_drag instead.
§Examples
use ailloli_ui_core::{Point, Rect, ScrollMetrics, ScrollState, ScrollbarAxis, ScrollbarGeometrySpec, Size};
let geometry = 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, 400.0)),
ScrollState::new(),
).resolve().unwrap();
let point = Point::new(geometry.track.x, geometry.track.y + geometry.track.h * 0.5);
assert!(geometry.track_target(point) > 0.0);Sourcepub fn begin_drag(self, point: Point) -> Option<ScrollbarDrag>
pub fn begin_drag(self, point: Point) -> Option<ScrollbarDrag>
Begins a drag only when point hits the thumb.
The retained logical grab offset keeps the exact pressed point attached to the pointer instead of recentering the thumb at drag start.
§Examples
use ailloli_ui_core::{Point, Rect, ScrollMetrics, ScrollState, ScrollbarAxis, ScrollbarGeometrySpec, Size};
let geometry = ScrollbarGeometrySpec::new(
ScrollbarAxis::Horizontal,
Rect::new(0.0, 0.0, 100.0, 60.0),
ScrollMetrics::new(Size::new(100.0, 60.0), Size::new(300.0, 60.0)),
ScrollState::new(),
).resolve().unwrap();
let center = Point::new(geometry.thumb.x + geometry.thumb.w * 0.5, geometry.thumb.y);
assert!(geometry.begin_drag(center).is_some());Trait Implementations§
Source§impl Clone for ScrollbarGeometry
impl Clone for ScrollbarGeometry
Source§fn clone(&self) -> ScrollbarGeometry
fn clone(&self) -> ScrollbarGeometry
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more