Skip to main content

Paragraph

Struct Paragraph 

Source
pub struct Paragraph { /* private fields */ }
Expand description

Shaped, line-broken and aligned text, ready to draw as GlyphRuns.

Built by TextSystem::paragraph. Changing the width (reflow) re-breaks the shaped text without shaping it again; changing the text or styles needs a new paragraph. Iterating runs never allocates, so drawing a paragraph every frame is allocation-free.

Not yet supported: variable-font axes and synthetic bold/italic (glyphs are drawn from the face’s default instance), color glyphs (emoji draw as coverage masks).

Implementations§

Source§

impl Paragraph

Source

pub fn width(&self) -> f32

Width of the widest line, in pixels.

Source

pub fn height(&self) -> f32

Height of all lines, in pixels: the bottom of the last line box.

Taken from the (pixel-snapped) line boxes rather than parley’s unsnapped total, so stacking paragraphs by height never drifts from where their lines are drawn.

Source

pub fn max_width(&self) -> Option<f32>

The width lines wrap at; None if they only break at newlines.

Source

pub fn lines(&self) -> &[LineBox]

The lines, top to bottom.

Source

pub fn glyph_count(&self) -> usize

Glyphs to draw, in all runs.

Source

pub fn runs(&self) -> impl ExactSizeIterator<Item = GlyphRun<'_>> + '_

The glyph runs to draw, positioned relative to the paragraph’s top-left corner.

Source

pub fn reflow(&mut self, max_width: Option<f32>) -> Result<(), ParagraphError>

Re-breaks and re-aligns the lines for a new max_width (None: no wrapping), without shaping again.

§Errors

ParagraphError::InvalidWidth if max_width is negative or not finite.

Trait Implementations§

Source§

impl Debug for Paragraph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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.