pub struct Paragraph { /* private fields */ }Expand description
A paragraph of text.
A paragraph retains the size and position of each glyph in the text and can be efficiently resized and painted.
To create a Paragraph object, use a ParagraphBuilder.
Paragraphs can be displayed on a Canvas using CanvasText::draw_paragraph.
Implementations§
Source§impl Paragraph
impl Paragraph
Sourcepub fn width(&self) -> f64
pub fn width(&self) -> f64
The amount of horizontal space this paragraph occupies.
Valid only after layout has been called. As in Skia, this is the
width the paragraph was laid out at (possibly infinite), not the widest line: the
lines are aligned within it.
Sourcepub fn height(&self) -> f64
pub fn height(&self) -> f64
The amount of vertical space this paragraph occupies.
Valid only after layout has been called.
Sourcepub fn longest_line(&self) -> f64
pub fn longest_line(&self) -> f64
The distance from the left edge of the leftmost glyph to the right edge of the rightmost glyph in the paragraph.
Sourcepub fn min_intrinsic_width(&self) -> f64
pub fn min_intrinsic_width(&self) -> f64
The minimum width that this paragraph could be without failing to paint its contents within itself.
Sourcepub fn max_intrinsic_width(&self) -> f64
pub fn max_intrinsic_width(&self) -> f64
Returns the smallest width beyond which increasing the width never decreases the height.
Sourcepub fn alphabetic_baseline(&self) -> f64
pub fn alphabetic_baseline(&self) -> f64
The distance from the top of the paragraph to the alphabetic baseline of the first line, in logical pixels.
Sourcepub fn ideographic_baseline(&self) -> f64
pub fn ideographic_baseline(&self) -> f64
The distance from the top of the paragraph to the ideographic baseline of the first line, in logical pixels.
The host has no ideographic metrics; this is the bottom of the first line.
Sourcepub fn did_exceed_max_lines(&self) -> bool
pub fn did_exceed_max_lines(&self) -> bool
True if there is more vertical content, but the text was truncated, either because we
reached max_lines lines of text or because the max_lines was None, ellipsis
was not None, and one of the lines exceeded the width constraint.
Sourcepub fn layout(&mut self, constraints: ParagraphConstraints)
pub fn layout(&mut self, constraints: ParagraphConstraints)
Computes the size and position of each glyph in the paragraph.
The ParagraphConstraints control how wide the text is allowed to be.
Sourcepub fn get_boxes_for_range(
&self,
start: i32,
end: i32,
box_height_style: BoxHeightStyle,
box_width_style: BoxWidthStyle,
) -> Vec<TextBox>
pub fn get_boxes_for_range( &self, start: i32, end: i32, box_height_style: BoxHeightStyle, box_width_style: BoxWidthStyle, ) -> Vec<TextBox>
Returns a list of text boxes that enclose the given text range.
The host returns tight boxes only: box_height_style and box_width_style do not
change the result.
Sourcepub fn get_boxes_for_placeholders(&self) -> Vec<TextBox>
pub fn get_boxes_for_placeholders(&self) -> Vec<TextBox>
Returns a list of text boxes that enclose all placeholders in the paragraph.
The order of the boxes are in the same order as passed in through
ParagraphBuilder::add_placeholder.
Coordinates of the TextBox are relative to the upper-left corner of the paragraph,
where positive y values indicate down.
Sourcepub fn get_position_for_offset(&self, offset: Offset) -> TextPosition
pub fn get_position_for_offset(&self, offset: Offset) -> TextPosition
Returns the text position closest to the given offset.
Sourcepub fn get_closest_glyph_info_for_offset(
&self,
offset: Offset,
) -> Option<GlyphInfo>
pub fn get_closest_glyph_info_for_offset( &self, offset: Offset, ) -> Option<GlyphInfo>
Returns the GlyphInfo of the glyph closest to the given offset in the paragraph
coordinate system, or None if if the text is empty, or is entirely clipped or
ellipsized away.
Sourcepub fn get_glyph_info_at(&self, code_unit_offset: i32) -> Option<GlyphInfo>
pub fn get_glyph_info_at(&self, code_unit_offset: i32) -> Option<GlyphInfo>
Returns the GlyphInfo located at the given UTF-16 code_unit_offset in the
paragraph, or None if the given code_unit_offset is out of the visible lines’ range.
Sourcepub fn get_word_boundary(&self, position: TextPosition) -> TextRange
pub fn get_word_boundary(&self, position: TextPosition) -> TextRange
Returns the TextRange of the word at the given TextPosition.
Sourcepub fn get_line_boundary(&self, position: TextPosition) -> TextRange
pub fn get_line_boundary(&self, position: TextPosition) -> TextRange
Returns the TextRange of the line at the given TextPosition.
The newline (if any) is not returned as part of the range.
Sourcepub fn compute_line_metrics(&self) -> Vec<LineMetrics>
pub fn compute_line_metrics(&self) -> Vec<LineMetrics>
Returns the full list of LineMetrics that describe in detail the various metrics
of each laid out line.
Sourcepub fn get_line_metrics_at(&self, line_number: i32) -> Option<LineMetrics>
pub fn get_line_metrics_at(&self, line_number: i32) -> Option<LineMetrics>
Returns the LineMetrics for the line at line_number, or None if the given
line_number is greater than or equal to number_of_lines.
Sourcepub fn number_of_lines(&self) -> i32
pub fn number_of_lines(&self) -> i32
The total number of visible lines in the paragraph.
Returns a non-negative number. If max_lines is set, the value of this getter never
exceeds max_lines.
Sourcepub fn get_line_number_at(&self, code_unit_offset: i32) -> Option<i32>
pub fn get_line_number_at(&self, code_unit_offset: i32) -> Option<i32>
Returns the line number of the line that contains the code unit that
code_unit_offset points to, or None if the code_unit_offset is out of range.
Sourcepub fn dispose(&mut self)
pub fn dispose(&mut self)
Release the resources used by this object. The object is no longer usable after this method is called.
Sourcepub fn debug_disposed(&self) -> bool
pub fn debug_disposed(&self) -> bool
Whether this reference to the underlying paragraph is disposed.