pub struct TextLayout { /* private fields */ }Expand description
A paragraph laid out in lines: glyph runs placed for drawing, and the
queries of Compose’s TextLayoutResult. Distances are in pixels from the
layout’s top left corner; offsets are byte offsets in the text. The
default is empty, ready for TextLayouter::layout_into.
Implementations§
Source§impl TextLayout
impl TextLayout
Sourcepub fn id(&self) -> u32
pub fn id(&self) -> u32
A number this layout’s glyphs and positions go by: a layout laid out or aligned again takes a new one, so a renderer keys what it drew of a layout by it; a clone keeps it.
Sourcepub fn holds(&self, min_width: f32, max_width: f32) -> bool
pub fn holds(&self, min_width: f32, max_width: f32) -> bool
Whether the text laid out again between min_width and max_width,
with the rest of its input the same, breaks into the same lines:
TextLayout::align then gives that layout without laying the text
out again.
Sourcepub fn width_between(&self, min_width: f32, max_width: f32) -> f32
pub fn width_between(&self, min_width: f32, max_width: f32) -> f32
The width the paragraph takes laid out between min_width and
max_width: its max intrinsic width rounded up to whole device
pixels within them, the max when they are equal, and its widest line
rounded up to whole device pixels within them when its lines wrap.
Sourcepub fn max_widths_kept(&self, min_width: f32) -> (f32, f32)
pub fn max_widths_kept(&self, min_width: f32) -> (f32, f32)
The max widths, from .0 up to and with .1, at which the paragraph
laid out from min_width keeps its width and its lines: every width
when its width follows no max, every width from its own when its text
fits, else the widths its lines wrap the same at below the width it
fits at, or only the one it wraps at when those are not known or its
widest line is wider than that one: its width is then the one it
wraps at, and moves with it.
Sourcepub fn align(&mut self, min_width: f32, max_width: f32, align: TextAlign)
pub fn align(&mut self, min_width: f32, max_width: f32, align: TextAlign)
Places the lines across the width the paragraph takes between
min_width and max_width as align says, for widths the layout
holds.
Sourcepub fn width(&self) -> f32
pub fn width(&self) -> f32
The paragraph’s width: its max intrinsic width rounded up to whole device pixels, within the widths it was laid out between.
Sourcepub fn line_advance(&self) -> f32
pub fn line_advance(&self) -> f32
The distance from the first line’s baseline down to the next line’s: the first line’s height before the paragraph’s edges trim it.
Sourcepub fn line_count(&self) -> usize
pub fn line_count(&self) -> usize
The number of lines, at least one.
Sourcepub fn lines_reach(&self) -> (f32, f32)
pub fn lines_reach(&self) -> (f32, f32)
How far the visible text of the lines reaches across: the left edge of the leftmost line’s and the right edge of the rightmost line’s, both zero for the empty default.
Sourcepub fn synthesized_style(&self) -> SynthesizedStyle
pub fn synthesized_style(&self) -> SynthesizedStyle
The bold and the italic the glyphs ask of faces that lack them, which a renderer synthesizes and which spread their ink.
Sourcepub fn glyph_reach(&self) -> Rect
pub fn glyph_reach(&self) -> Rect
How far the glyphs reach, in pixels from the layout’s top left
corner: across, the visible text of the lines and the ink a glyph puts
past it, as the overhang of an f that ends a line does; down, from
the top, or the ink above it, to the lowest ink, at the top when the
glyphs ink no lower than the box. A renderer joins it with the box it
draws the text in.
Sourcepub fn did_overflow_height(&self) -> bool
pub fn did_overflow_height(&self) -> bool
Whether the text had more lines than the line limit: Compose’s
didOverflowHeight of a layout the line limit cut.
Sourcepub fn did_overflow_width(&self) -> bool
pub fn did_overflow_width(&self) -> bool
Whether the paragraph is wider than the widest it was laid out at, or
a line wider than the paragraph: Compose’s didOverflowWidth.
Sourcepub fn is_line_ellipsized(&self, line: usize) -> bool
pub fn is_line_ellipsized(&self, line: usize) -> bool
Whether line shows an ellipsis in place of text.
Sourcepub fn line_start(&self, line: usize) -> usize
pub fn line_start(&self, line: usize) -> usize
The offset where line starts. Panics when line is out of range, as
Compose throws.
Sourcepub fn line_end(&self, line: usize) -> usize
pub fn line_end(&self, line: usize) -> usize
The offset where line ends, after its line break and trailing
whitespace.
Sourcepub fn line_visible_end(&self, line: usize) -> usize
pub fn line_visible_end(&self, line: usize) -> usize
The offset where the visible text of line ends, before its line
break and trailing whitespace: Compose’s getLineEnd(line, true).
Sourcepub fn line_bottom(&self, line: usize) -> f32
pub fn line_bottom(&self, line: usize) -> f32
The bottom of line.
Sourcepub fn line_baseline(&self, line: usize) -> f32
pub fn line_baseline(&self, line: usize) -> f32
The baseline of line.
Sourcepub fn line_right(&self, line: usize) -> f32
pub fn line_right(&self, line: usize) -> f32
The right edge of the visible text of line.
Sourcepub fn line_for_offset(&self, offset: usize) -> usize
pub fn line_for_offset(&self, offset: usize) -> usize
The line that holds offset; the last line for the end of the text.
Sourcepub fn line_for_vertical_position(&self, y: f32) -> usize
pub fn line_for_vertical_position(&self, y: f32) -> usize
The line at height y, the first above the text and the last below it.
Sourcepub fn horizontal_position(
&self,
offset: usize,
direction: CaretDirection,
) -> f32
pub fn horizontal_position( &self, offset: usize, direction: CaretDirection, ) -> f32
The x of a caret at offset. Where the text before and after offset
runs in different directions the caret has two places, and direction
picks one.
Sourcepub fn offset_for_position(&self, x: f32, y: f32) -> usize
pub fn offset_for_position(&self, x: f32, y: f32) -> usize
The offset of the caret nearest to the point x, y.
Sourcepub fn glyph_runs(&self, line: usize) -> impl Iterator<Item = GlyphRun<'_>> + '_
pub fn glyph_runs(&self, line: usize) -> impl Iterator<Item = GlyphRun<'_>> + '_
The glyph runs of line, left to right.
Sourcepub fn bounding_box(&self, offset: usize) -> Rect
pub fn bounding_box(&self, offset: usize) -> Rect
The box of the character at offset, across its line: Compose’s
getBoundingBox. A zero-width box at the caret for an offset with no
character, such as the end of the text.
Sourcepub fn cursor_rect(&self, offset: usize) -> Rect
pub fn cursor_rect(&self, offset: usize) -> Rect
The caret at offset as a zero-width rectangle across its line:
Compose’s getCursorRect.
Sourcepub fn selection_rects(&self, start: usize, end: usize, rects: &mut Vec<Rect>)
pub fn selection_rects(&self, start: usize, end: usize, rects: &mut Vec<Rect>)
Pushes onto rects the rectangles that cover the text from start
to end line by line, one for each stretch of it that runs in one
direction, within the paragraph’s width or its visible text: Compose’s
getPathForRange as rectangles. The spaces a wrapped line ends with
hang past the widest line, which they do not widen, and cover nothing
there.