pub struct Paragraph {
text: Vec<StyledString>,
words: VecDeque<StyledString>,
style_applied: bool,
alignment: Alignment,
}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 genpdfi_extended::{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(genpdfi_extended::Alignment::Center);Chained:
use genpdfi_extended::{elements, style};
let p = elements::Paragraph::default()
.string("This is an ")
.styled_string("important", style::Color::Rgb(255, 0, 0))
.string(" message!")
.aligned(genpdfi_extended::Alignment::Center);Fields§
§text: Vec<StyledString>§words: VecDeque<StyledString>§style_applied: bool§alignment: AlignmentImplementations§
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.
§Example
use genpdfi_extended::elements::Paragraph;
let mut p = Paragraph::new("start");
p.push("middle");
let _ = p.aligned(genpdfi_extended::Alignment::Center).string("end");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.
Sourcepub fn push_styled(&mut self, s: impl Into<String>, style: impl Into<Style>)
pub fn push_styled(&mut self, s: impl Into<String>, style: impl Into<Style>)
Adds a string with the given style to the end of this paragraph.
Sourcepub fn push_link(
&mut self,
text: impl Into<String>,
url: impl Into<String>,
style: impl Into<Style>,
) -> &mut Self
pub fn push_link( &mut self, text: impl Into<String>, url: impl Into<String>, style: impl Into<Style>, ) -> &mut Self
Adds a string with the given style to the end of this paragraph and returns the paragraph.
§Examples
use genpdfi_extended::elements::Paragraph;
use genpdfi_extended::style::Style;
let mut p = Paragraph::new("start");
p.push_link("click", "https://example.com", Style::new());
p.push("more");Sourcepub fn styled_string(
self,
s: impl Into<String>,
style: impl Into<Style>,
) -> Self
pub fn styled_string( self, s: impl Into<String>, style: impl Into<Style>, ) -> Self
Adds a string with the given style to the end of this paragraph and returns the paragraph.
fn get_offset(&self, width: Mm, max_width: Mm) -> Mm
fn apply_style(&mut self, style: Style)
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)Source§impl<T: Into<StyledString>> FromIterator<T> for Paragraph
impl<T: Into<StyledString>> FromIterator<T> for Paragraph
Source§fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Auto Trait Implementations§
impl Freeze for Paragraph
impl RefUnwindSafe for Paragraph
impl Send for Paragraph
impl Sync for Paragraph
impl Unpin for Paragraph
impl UnwindSafe for Paragraph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<E> IntoBoxedElement for Ewhere
E: Element + 'static,
impl<E> IntoBoxedElement for Ewhere
E: Element + 'static,
Source§fn into_boxed_element(self) -> Box<dyn Element>
fn into_boxed_element(self) -> Box<dyn Element>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
T, using the provided data to resolve any offsets.