pub struct ScrollDimensions { /* private fields */ }Expand description
ScrollDimensions - Centralizes ALL scrolling and scrollbar mathematical operations
Eliminates ad hoc scrollbar math like:
- knob_size = std::cmp::max(1, (track_height as f64 * content_ratio).round() as usize)
- available_track = track_height.saturating_sub(knob_size)
- knob_position = ((scroll / 100.0) * available_track as f64).round() as usize
- All coordinate translation between scroll percentages and pixel positions
Replaces scattered scrollbar logic from vertical_scrollbar.rs, horizontal_scrollbar.rs, draw_loop.rs scrollbar detection, and box_renderer.rs scroll calculations.
Implementations§
Source§impl ScrollDimensions
impl ScrollDimensions
Sourcepub fn new(
content_size: (usize, usize),
viewable_size: (usize, usize),
scroll_position: (f64, f64),
parent_bounds: Bounds,
) -> Self
pub fn new( content_size: (usize, usize), viewable_size: (usize, usize), scroll_position: (f64, f64), parent_bounds: Bounds, ) -> Self
Create new scroll dimensions
Sourcepub fn set_scroll_position(&mut self, horizontal: f64, vertical: f64)
pub fn set_scroll_position(&mut self, horizontal: f64, vertical: f64)
Update scroll position (with automatic clamping)
Sourcepub fn is_scrollbar_needed(&self, orientation: Orientation) -> bool
pub fn is_scrollbar_needed(&self, orientation: Orientation) -> bool
Check if scrollbar is needed for given orientation Replaces: content_height > viewable_height checks
Sourcepub fn get_track_bounds(&self, orientation: Orientation) -> TrackBounds
pub fn get_track_bounds(&self, orientation: Orientation) -> TrackBounds
Get scrollbar track bounds (where scrollbar can be drawn) Centralizes track positioning logic from scrollbar components
Sourcepub fn calculate_knob_size(&self, orientation: Orientation) -> usize
pub fn calculate_knob_size(&self, orientation: Orientation) -> usize
Calculate scrollbar knob size Centralizes: knob_size = std::cmp::max(1, (track_length as f64 * content_ratio).round() as usize)
Sourcepub fn calculate_knob_position(&self, orientation: Orientation) -> usize
pub fn calculate_knob_position(&self, orientation: Orientation) -> usize
Calculate scrollbar knob position within track Centralizes: knob_position = ((scroll / 100.0) * available_track as f64).round() as usize
Sourcepub fn get_knob_bounds(&self, orientation: Orientation) -> KnobBounds
pub fn get_knob_bounds(&self, orientation: Orientation) -> KnobBounds
Get absolute knob bounds for drawing Centralizes knob positioning from scrollbar components
Sourcepub fn calculate_scroll_offset(&self, orientation: Orientation) -> usize
pub fn calculate_scroll_offset(&self, orientation: Orientation) -> usize
Calculate scroll offset in content coordinates Centralizes: offset = ((scroll / 100.0) * max_offset as f64).floor() as usize
Sourcepub fn pixel_to_scroll_percent(
&self,
pixel_coordinate: usize,
orientation: Orientation,
) -> f64
pub fn pixel_to_scroll_percent( &self, pixel_coordinate: usize, orientation: Orientation, ) -> f64
Convert pixel position within track to scroll percentage Centralizes click-to-scroll calculations from draw_loop.rs
Sourcepub fn hits_knob(&self, x: usize, y: usize, orientation: Orientation) -> bool
pub fn hits_knob(&self, x: usize, y: usize, orientation: Orientation) -> bool
Test if coordinate hits the scrollbar knob Centralizes knob hit testing from draw_loop.rs
Sourcepub fn hits_track(&self, x: usize, y: usize, orientation: Orientation) -> bool
pub fn hits_track(&self, x: usize, y: usize, orientation: Orientation) -> bool
Test if coordinate hits the scrollbar track (but not knob) Centralizes track click detection for jump-to-position
Sourcepub fn calculate_drag_scroll(
&self,
start_pixel: usize,
current_pixel: usize,
orientation: Orientation,
) -> f64
pub fn calculate_drag_scroll( &self, start_pixel: usize, current_pixel: usize, orientation: Orientation, ) -> f64
Calculate new scroll percentage from knob drag operation Centralizes drag-to-scroll calculations
Sourcepub fn get_visible_range(&self, orientation: Orientation) -> (usize, usize)
pub fn get_visible_range(&self, orientation: Orientation) -> (usize, usize)
Get visible content range (start, end) for given orientation
Centralizes visible range calculations for content clipping
Sourcepub fn calculate_auto_scroll_to_line(
&self,
target_line: usize,
orientation: Orientation,
) -> f64
pub fn calculate_auto_scroll_to_line( &self, target_line: usize, orientation: Orientation, ) -> f64
Calculate auto-scroll adjustment to keep target line visible Centralizes auto-scroll logic from draw_loop.rs choice navigation
Trait Implementations§
Source§impl Clone for ScrollDimensions
impl Clone for ScrollDimensions
Source§fn clone(&self) -> ScrollDimensions
fn clone(&self) -> ScrollDimensions
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ScrollDimensions
impl RefUnwindSafe for ScrollDimensions
impl Send for ScrollDimensions
impl Sync for ScrollDimensions
impl Unpin for ScrollDimensions
impl UnsafeUnpin for ScrollDimensions
impl UnwindSafe for ScrollDimensions
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.