Struct rckive_genpdf::elements::Paragraph
source · pub struct Paragraph { /* private fields */ }
Expand description
A multi-line wrapped paragraph of formatted text.
If the text of this paragraph is longer than the page width, the paragraph is wrapped at word borders (and additionally at string borders if it contains multiple strings). If a word in the paragraph is longer than the page width, the text is truncated.
Use the push
, string
, push_styled
and string_styled
methods to add
strings to this paragraph. Besides the styling of the text (see Style
), you can also set
an Alignment
for the paragraph.
The line height and spacing are calculated based on the style of each string.
Examples
With setters:
use rckive_genpdf::{elements, style};
let mut p = elements::Paragraph::default();
p.push("This is an ");
p.push_styled("important", style::Color::Rgb(255, 0, 0));
p.push(" message!");
p.set_alignment(rckive_genpdf::Alignment::Center);
Chained:
use rckive_genpdf::{elements, style};
let p = elements::Paragraph::default()
.string("This is an ")
.styled_string("important", style::Color::Rgb(255, 0, 0))
.string(" message!")
.aligned(rckive_genpdf::Alignment::Center);
Implementations§
source§impl Paragraph
impl Paragraph
sourcepub fn new(text: impl Into<StyledString>) -> Paragraph
pub fn new(text: impl Into<StyledString>) -> Paragraph
Creates a new paragraph with the given content.
sourcepub fn set_alignment(&mut self, alignment: Alignment)
pub fn set_alignment(&mut self, alignment: Alignment)
Sets the alignment of this paragraph.
sourcepub fn aligned(self, alignment: Alignment) -> Self
pub fn aligned(self, alignment: Alignment) -> Self
Sets the alignment of this paragraph and returns the paragraph.
sourcepub fn push(&mut self, s: impl Into<StyledString>)
pub fn push(&mut self, s: impl Into<StyledString>)
Adds a string to the end of this paragraph.
sourcepub fn string(self, s: impl Into<StyledString>) -> Self
pub fn string(self, s: impl Into<StyledString>) -> Self
Adds a string to the end of this paragraph and returns the paragraph.
Trait Implementations§
source§impl Element for Paragraph
impl Element for Paragraph
source§fn render(
&mut self,
context: &Context,
area: Area<'_>,
style: Style
) -> Result<RenderResult, Error>
fn render(
&mut self,
context: &Context,
area: Area<'_>,
style: Style
) -> Result<RenderResult, Error>
source§fn framed(self, line_style: impl Into<LineStyle>) -> FramedElement<Self>where
Self: Sized,
fn framed(self, line_style: impl Into<LineStyle>) -> FramedElement<Self>where
Self: Sized,
source§impl<T: Into<StyledString>> Extend<T> for Paragraph
impl<T: Into<StyledString>> Extend<T> for Paragraph
source§fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)