pub struct TextDimensions { /* private fields */ }Expand description
TextDimensions - Centralizes ALL text layout and wrapping mathematical operations
Eliminates ad hoc text math like:
- width.saturating_sub(border_width)
- title_start_position = x1 + (width.saturating_sub(title_length)) / 2
- Text wrapping and line counting scattered throughout draw_utils.rs
- Character-aware truncation with ellipsis
Replaces scattered text layout logic from draw_utils.rs, components/text_content.rs
Implementations§
Source§impl TextDimensions
impl TextDimensions
Sourcepub fn with_alignment(self, alignment: TextAlignment) -> Self
pub fn with_alignment(self, alignment: TextAlignment) -> Self
Builder methods
pub fn with_wrap_behavior(self, behavior: WrapBehavior) -> Self
pub fn with_font_metrics(self, metrics: FontMetrics) -> Self
Sourcepub fn available_width(&self) -> usize
pub fn available_width(&self) -> usize
Get available text width (accounting for UI chrome)
Sourcepub fn available_height(&self) -> usize
pub fn available_height(&self) -> usize
Get available text height (accounting for UI chrome)
Sourcepub fn wrap_text(&self, text: &str) -> Vec<String>
pub fn wrap_text(&self, text: &str) -> Vec<String>
Wrap text to fit within available width Centralizes text wrapping logic from draw_utils.rs
Sourcepub fn truncate_with_ellipsis(&self, text: &str, max_width: usize) -> String
pub fn truncate_with_ellipsis(&self, text: &str, max_width: usize) -> String
Truncate text with ellipsis if it exceeds width Centralizes ellipsis logic from various components
Sourcepub fn calculate_text_bounds(&self, text: &str) -> (usize, usize)
pub fn calculate_text_bounds(&self, text: &str) -> (usize, usize)
Calculate text bounds (width, height) for given text
Sourcepub fn center_text_in_bounds(&self, text: &str) -> TextLayout
pub fn center_text_in_bounds(&self, text: &str) -> TextLayout
Calculate positioning for centered text within bounds Centralizes center positioning logic from draw_utils.rs
Sourcepub fn layout_text(&self, text: &str) -> TextLayout
pub fn layout_text(&self, text: &str) -> TextLayout
Calculate text layout based on alignment
Sourcepub fn calculate_line_positions(&self, layout: &TextLayout) -> Vec<LinePosition>
pub fn calculate_line_positions(&self, layout: &TextLayout) -> Vec<LinePosition>
Calculate line positions for each wrapped line
Sourcepub fn count_visible_lines(&self, text: &str) -> usize
pub fn count_visible_lines(&self, text: &str) -> usize
Count visible lines that fit within available height
Sourcepub fn get_visible_lines(&self, text: &str, scroll_offset: usize) -> Vec<String>
pub fn get_visible_lines(&self, text: &str, scroll_offset: usize) -> Vec<String>
Get visible text portion for scrolling Centralizes scrolling text logic
Sourcepub fn max_scroll_offset(&self, text: &str) -> usize
pub fn max_scroll_offset(&self, text: &str) -> usize
Calculate maximum scroll offset for text
Sourcepub fn validate_text_fit(&self, text: &str) -> TextFitResult
pub fn validate_text_fit(&self, text: &str) -> TextFitResult
Validate text fits within dimensions
Trait Implementations§
Source§impl Clone for TextDimensions
impl Clone for TextDimensions
Source§fn clone(&self) -> TextDimensions
fn clone(&self) -> TextDimensions
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 TextDimensions
impl RefUnwindSafe for TextDimensions
impl Send for TextDimensions
impl Sync for TextDimensions
impl Unpin for TextDimensions
impl UnsafeUnpin for TextDimensions
impl UnwindSafe for TextDimensions
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.