@@ -15,6 +15,7 @@ use crate::text::fonts::FontSelector;
1515use crate :: text:: format:: FormattableText ;
1616use crate :: text:: * ;
1717use crate :: { Action , Layout } ;
18+ use std:: num:: NonZeroUsize ;
1819
1920/// Text type-setting object (theme aware)
2021///
@@ -442,13 +443,15 @@ impl<T: FormattableText> Text<T> {
442443 self . display . measure_width ( max_width)
443444 }
444445
445- /// Measure required vertical height
446+ /// Measure required vertical height, wrapping as configured
447+ ///
448+ /// Stops after `max_lines`, if provided.
446449 ///
447450 /// May partially prepare the text for display, but does not otherwise
448451 /// modify `self`.
449- pub fn measure_height ( & mut self , wrap_width : f32 ) -> f32 {
452+ pub fn measure_height ( & mut self , wrap_width : f32 , max_lines : Option < NonZeroUsize > ) -> f32 {
450453 self . prepare_runs ( ) ;
451- self . display . measure_height ( wrap_width)
454+ self . display . measure_height ( wrap_width, max_lines )
452455 }
453456
454457 /// Prepare text for display, as necessary
@@ -552,6 +555,20 @@ impl<T: FormattableText> Text<T> {
552555 Ok ( self . wrapped_display ( ) ?. num_lines ( ) )
553556 }
554557
558+ /// Get line properties
559+ #[ inline]
560+ pub fn get_line ( & self , index : usize ) -> Result < Option < & Line > , NotReady > {
561+ Ok ( self . wrapped_display ( ) ?. get_line ( index) )
562+ }
563+
564+ /// Iterate over line properties
565+ ///
566+ /// [Requires status][Self#status-of-preparation]: lines have been wrapped.
567+ #[ inline]
568+ pub fn lines ( & self ) -> Result < impl Iterator < Item = & Line > , NotReady > {
569+ Ok ( self . wrapped_display ( ) ?. lines ( ) )
570+ }
571+
555572 /// Find the line containing text `index`
556573 ///
557574 /// See [`TextDisplay::find_line`].
@@ -563,14 +580,6 @@ impl<T: FormattableText> Text<T> {
563580 Ok ( self . wrapped_display ( ) ?. find_line ( index) )
564581 }
565582
566- /// Get the range of a line, by line number
567- ///
568- /// See [`TextDisplay::line_range`].
569- #[ inline]
570- pub fn line_range ( & self , line : usize ) -> Result < Option < std:: ops:: Range < usize > > , NotReady > {
571- Ok ( self . wrapped_display ( ) ?. line_range ( line) )
572- }
573-
574583 /// Get the directionality of the current line
575584 ///
576585 /// See [`TextDisplay::line_is_rtl`].
@@ -705,6 +714,6 @@ impl<T: FormattableText> SizableText for Text<T> {
705714 }
706715
707716 fn measure_height ( & mut self , wrap_width : f32 ) -> f32 {
708- Text :: measure_height ( self , wrap_width)
717+ Text :: measure_height ( self , wrap_width, None )
709718 }
710719}
0 commit comments