pub struct TextLayout { /* private fields */ }Expand description
A block of text laid out in logical pixels against one style.
The layout is computed eagerly by TextLayout::new and never changes
afterwards. A new layout replaces an old one rather than being edited. It
carries no color: layout runs without a theme, and the caller paints the
glyph runs in whatever color it resolves when it paints.
Implementations§
Source§impl TextLayout
impl TextLayout
Sourcepub fn glyph_runs_at(&self, origin: Point, color: Color) -> Vec<GlyphRun>
pub fn glyph_runs_at(&self, origin: Point, color: Color) -> Vec<GlyphRun>
Converts the laid out text into glyph runs at origin, in paint order.
origin is where the top left corner of the layout box goes, in the
caller’s paint coordinates, which leave out the scroll offsets of
enclosing views, so the first line’s baseline lies one ascent below
it. The layout itself carries no color, so color is the
color every returned run paints with, resolved by the caller at paint
time. Each run carries the font as bytes, the size its style used, the
given color, and glyphs positioned in those same coordinates. A run
whose text is empty produces no runs.
§Panics
Panics under the conditions of crate::TextSystem::with, in
particular when called from inside another with call on the same
thread.
Source§impl TextLayout
impl TextLayout
Sourcepub fn new(text: &str, style: &TextStyle, max_width: Option<f32>) -> TextLayout
pub fn new(text: &str, style: &TextStyle, max_width: Option<f32>) -> TextLayout
Lays out text with style, wrapping lines at max_width logical
pixels, or not at all when it is None.
Layout runs against the current thread’s TextSystem.
§Panics
Panics under the conditions of TextSystem::with, in particular
when called from inside another with call on the same thread.
Sourcepub fn size(&self) -> Size
pub fn size(&self) -> Size
Returns the width and height of the laid out text in logical pixels.
The width is the longest line, without hanging whitespace. The height is the sum of the line heights. A layout cut by truncation reports the kept lines and the cut line’s glyphs plus its ellipsis, so callers measure what paint draws.
Sourcepub fn line_count(&self) -> usize
pub fn line_count(&self) -> usize
Returns the number of lines the text was broken into.
A layout cut by truncation reports the lines it keeps.
Sourcepub fn glyph_runs(&self) -> impl Iterator<Item = GlyphRun<'_, ()>> + Clone + '_
pub fn glyph_runs(&self) -> impl Iterator<Item = GlyphRun<'_, ()>> + Clone + '_
Iterates the glyph runs of every line, in visual order.
A glyph run carries its font, size and positioned glyphs, and no color:
the caller supplies it when converting runs with glyph_runs_at. The
item type is parley’s, and its coordinates are relative to the top
left of the layout. The runs of lines a truncation dropped are not
yielded.