Skip to main content

TextLayout

Struct TextLayout 

Source
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

Source

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

Source

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.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.