pub struct MouseDimensions { /* private fields */ }Expand description
MouseDimensions - Centralizes ALL mouse coordinate translation and hit testing
Eliminates ad hoc coordinate math like:
- column as usize, row as usize conversions from crossterm
- inbox_x = screen_x.saturating_sub(content_start_x.saturating_sub(horizontal_offset))
- Complex coordinate system translations between screen, content, and scrolled spaces
- Hit testing scattered across multiple files
Replaces scattered coordinate translation from box_renderer.rs, draw_loop.rs, input_loop.rs
Implementations§
Source§impl MouseDimensions
impl MouseDimensions
Sourcepub fn new(
screen_bounds: Bounds,
content_bounds: Bounds,
scroll_offset: (usize, usize),
content_size: (usize, usize),
) -> Self
pub fn new( screen_bounds: Bounds, content_bounds: Bounds, scroll_offset: (usize, usize), content_size: (usize, usize), ) -> Self
Create new mouse dimensions
Sourcepub fn set_scroll_offset(&mut self, horizontal: usize, vertical: usize)
pub fn set_scroll_offset(&mut self, horizontal: usize, vertical: usize)
Update scroll offset
Sourcepub fn crossterm_to_internal(&self, column: u16, row: u16) -> (usize, usize)
pub fn crossterm_to_internal(&self, column: u16, row: u16) -> (usize, usize)
Convert crossterm coordinates (u16) to internal coordinates (usize) Centralizes: column as usize, row as usize conversions
Sourcepub fn internal_to_crossterm(&self, x: usize, y: usize) -> (u16, u16)
pub fn internal_to_crossterm(&self, x: usize, y: usize) -> (u16, u16)
Convert internal coordinates back to crossterm (for event generation)
Sourcepub fn is_within_screen_bounds(&self, x: usize, y: usize) -> bool
pub fn is_within_screen_bounds(&self, x: usize, y: usize) -> bool
Test if screen coordinates are within component bounds
Sourcepub fn is_within_content_bounds(&self, x: usize, y: usize) -> bool
pub fn is_within_content_bounds(&self, x: usize, y: usize) -> bool
Test if screen coordinates are within content area
Sourcepub fn screen_to_content(
&self,
screen_x: usize,
screen_y: usize,
) -> Option<(usize, usize)>
pub fn screen_to_content( &self, screen_x: usize, screen_y: usize, ) -> Option<(usize, usize)>
Convert screen coordinates to content coordinates (accounting for scroll) Centralizes complex translation logic from box_renderer.rs
Sourcepub fn content_to_screen(
&self,
content_x: usize,
content_y: usize,
) -> Option<(usize, usize)>
pub fn content_to_screen( &self, content_x: usize, content_y: usize, ) -> Option<(usize, usize)>
Convert content coordinates to screen coordinates (reverse translation)
Sourcepub fn get_visible_content_range(&self) -> ((usize, usize), (usize, usize))
pub fn get_visible_content_range(&self) -> ((usize, usize), (usize, usize))
Get the content coordinate range that’s currently visible
Sourcepub fn is_content_coordinate_visible(
&self,
content_x: usize,
content_y: usize,
) -> bool
pub fn is_content_coordinate_visible( &self, content_x: usize, content_y: usize, ) -> bool
Test if content coordinates are currently visible on screen
Sourcepub fn screen_y_to_content_line(&self, screen_y: usize) -> Option<usize>
pub fn screen_y_to_content_line(&self, screen_y: usize) -> Option<usize>
Calculate which content line a screen Y coordinate corresponds to Useful for text selection and choice navigation
Sourcepub fn screen_x_to_content_column(&self, screen_x: usize) -> Option<usize>
pub fn screen_x_to_content_column(&self, screen_x: usize) -> Option<usize>
Calculate which content column a screen X coordinate corresponds to
Useful for text cursor positioning
Sourcepub fn detect_click_region(&self, x: usize, y: usize) -> ClickRegion
pub fn detect_click_region(&self, x: usize, y: usize) -> ClickRegion
Calculate click regions for UI components Centralizes region detection logic
Sourcepub fn calculate_distance(
&self,
x1: usize,
y1: usize,
x2: usize,
y2: usize,
) -> f64
pub fn calculate_distance( &self, x1: usize, y1: usize, x2: usize, y2: usize, ) -> f64
Calculate distance between two points (for drag detection)
Sourcepub fn is_drag_operation(
&self,
start_x: usize,
start_y: usize,
current_x: usize,
current_y: usize,
threshold: f64,
) -> bool
pub fn is_drag_operation( &self, start_x: usize, start_y: usize, current_x: usize, current_y: usize, threshold: f64, ) -> bool
Test if mouse movement constitutes a drag (beyond threshold)
Sourcepub fn calculate_selection_bounds(
&self,
start_x: usize,
start_y: usize,
end_x: usize,
end_y: usize,
) -> SelectionBounds
pub fn calculate_selection_bounds( &self, start_x: usize, start_y: usize, end_x: usize, end_y: usize, ) -> SelectionBounds
Calculate bounding box for a selection region
Sourcepub fn clamp_to_screen_bounds(&self, x: usize, y: usize) -> (usize, usize)
pub fn clamp_to_screen_bounds(&self, x: usize, y: usize) -> (usize, usize)
Clamp coordinates to valid screen bounds Prevents out-of-bounds coordinate issues
Sourcepub fn clamp_to_content_bounds(&self, x: usize, y: usize) -> (usize, usize)
pub fn clamp_to_content_bounds(&self, x: usize, y: usize) -> (usize, usize)
Clamp coordinates to valid content bounds
Sourcepub fn calculate_scroll_to_visible(
&self,
content_x: usize,
content_y: usize,
) -> (i32, i32)
pub fn calculate_scroll_to_visible( &self, content_x: usize, content_y: usize, ) -> (i32, i32)
Calculate scroll delta needed to make content coordinate visible
Sourcepub fn update_bounds(&mut self, screen_bounds: Bounds, content_bounds: Bounds)
pub fn update_bounds(&mut self, screen_bounds: Bounds, content_bounds: Bounds)
Update mouse dimensions for window/content resize
Sourcepub fn update_content_size(&mut self, width: usize, height: usize)
pub fn update_content_size(&mut self, width: usize, height: usize)
Update content size (when content changes)
Trait Implementations§
Source§impl Clone for MouseDimensions
impl Clone for MouseDimensions
Source§fn clone(&self) -> MouseDimensions
fn clone(&self) -> MouseDimensions
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 MouseDimensions
impl RefUnwindSafe for MouseDimensions
impl Send for MouseDimensions
impl Sync for MouseDimensions
impl Unpin for MouseDimensions
impl UnsafeUnpin for MouseDimensions
impl UnwindSafe for MouseDimensions
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.