Skip to main content

ParagraphBuilder

Struct ParagraphBuilder 

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

Builds a Paragraph containing text with the given styling information.

To set the paragraph’s alignment, truncation, and ellipsizing behavior, pass an appropriately-configured ParagraphStyle object to ParagraphBuilder::new.

Then, call combinations of push_style, add_text, and pop to add styled text to the object.

Finally, call build to obtain the constructed Paragraph object. After this point, the builder is no longer usable.

After constructing a Paragraph, call Paragraph::layout on it and then paint it with CanvasText::draw_paragraph.

Implementations§

Source§

impl ParagraphBuilder

Source

pub fn new(style: ParagraphStyle) -> ParagraphBuilder

Creates a new ParagraphBuilder object, which is used to create a Paragraph.

Source

pub fn placeholder_count(&self) -> i32

The number of placeholders currently in the paragraph.

Placeholders are not supported by the host; this is always zero.

Source

pub fn push_style(&mut self, style: TextStyle)

Applies the given style to the added text until pop is called.

Fields the style leaves unset inherit from the style below it.

Source

pub fn pop(&mut self)

Ends the effect of the most recent call to push_style.

Internally, the paragraph builder maintains a stack of text styles. Text added to the paragraph is affected by all the styles in the stack. Calling pop removes the topmost style in the stack, leaving the remaining styles in effect.

Source

pub fn add_text(&mut self, text: &str)

Adds the given text to the paragraph.

The text will be styled according to the current stack of text styles.

Source

pub fn build(self, fonts: &mut FontCollection) -> Paragraph

Applies the given paragraph style and returns a Paragraph containing the added text and associated styling, shaped against fonts.

After calling this function, the paragraph builder object is invalid and cannot be used further.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,