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
impl ParagraphBuilder
Sourcepub fn new(style: ParagraphStyle) -> ParagraphBuilder
pub fn new(style: ParagraphStyle) -> ParagraphBuilder
Creates a new ParagraphBuilder object, which is used to create a Paragraph.
Sourcepub fn placeholder_count(&self) -> i32
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.
Sourcepub fn push_style(&mut self, style: TextStyle)
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.
Sourcepub fn pop(&mut self)
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.
Sourcepub fn add_text(&mut self, text: &str)
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.
Sourcepub fn build(self, fonts: &mut FontCollection) -> Paragraph
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.