Struct ScrollbarGeometry

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

Controlled axis.

§track: Rect

Painted track bounds.

§thumb: Rect

Painted proportional thumb bounds.

§hit_track: Rect

Pointer target containing the track and expanded cross-axis area.

§viewport_extent: f32

Visible content extent along Self::axis.

§max_offset: f32

Greatest valid content offset along Self::axis.

Implementations§

Source§

impl ScrollbarGeometry

Source

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

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

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

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

Source§

fn clone(&self) -> ScrollbarGeometry

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 ScrollbarGeometry

Source§

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

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

impl PartialEq for ScrollbarGeometry

Source§

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

Source§

impl StructuralPartialEq for ScrollbarGeometry

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.