pub trait Element {
// Required method
fn render(
&mut self,
context: &Context,
area: Area<'_>,
style: Style,
) -> Result<RenderResult, Error>;
// Provided methods
fn framed(self, line_style: impl Into<LineStyle>) -> FramedElement<Self>
where Self: Sized { ... }
fn padded(self, padding: impl Into<Margins>) -> PaddedElement<Self>
where Self: Sized { ... }
fn styled(self, style: impl Into<Style>) -> StyledElement<Self>
where Self: Sized { ... }
}Expand description
An element of a PDF document.
This trait is implemented by all elements that can be added to a Document. Implementors
have to define the render method that writes the content of this element to the generated
PDF document.
See the Rendering Process section of the crate documentation for more information on the rendering process.
Required Methods§
Sourcefn 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>
Renders this element to the given area using the given style and font cache.
For an overview over the rendering process, see the Rendering Process section of the crate documentation.
This method is called once for every element that has been added to a Document once
the render or render_to_file methods have been called. If this method is
called, it should print the element’s content to the given area. If the content does not
fit in the given area, it should set the has_more flag of the returned
RenderResult. It will then be called again with a new area on a new page until it
returns a RenderResult with has_more == false. Regardless of whether the content
fitted in the area or not, the size field of the RenderResult must always be set to
the size of the area that has been used, starting at the origin of the provided area.
The following guarantuees are made by genpdfi’s elements and must be followed by
implementations of this trait:
- There is only one rendering process per element instance. This means that the first call to this method is always the start of the rendering process, and subsequent calls are always continuations of the same rendering process. This means that the element does not have to reset its state after it has processed all content, and it is allowed to drop content that has already been rendered.
- If a call to this method returns an
Errvalue, it will not be called again. - After the first call, the method will only be called again if the
has_moreof the lastRenderResultwas set to true. - If none of the element’s content could be fitted in the provided area, the size of the
RenderResultmust be(0, 0). If the size is non-zero, this method must return aRenderResultwithhas_more == falseafter a finite number of calls.
Provided Methods§
Sourcefn 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,
Draws a frame around this element using the given line style.
Trait Implementations§
Source§impl IntoBoxedElement for Box<dyn Element>
impl IntoBoxedElement for Box<dyn Element>
Source§fn into_boxed_element(self) -> Box<dyn Element>
fn into_boxed_element(self) -> Box<dyn Element>
Implementors§
impl Element for Break
impl Element for Image
impl Element for Latex
impl Element for LinearLayout
impl Element for Mermaid
impl Element for OrderedList
impl Element for PageBreak
impl Element for Paragraph
impl Element for TableLayout
impl Element for Text
A multi-line wrapped paragraph of formatted text.