[][src]Trait genpdf::Element

pub trait Element {
    fn render(
        &mut self,
        font_cache: &FontCache,
        area: Area<'_>,
        style: Style
    ) -> Result<RenderResult, Error>; fn framed(self) -> 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
, { ... } }

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

fn render(
    &mut self,
    font_cache: &FontCache,
    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 genpdf’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 Err value, it will not be called again.
  • After the first call, the method will only be called again if the has_more of the last RenderResult was set to true.
  • If none of the element’s content could be fitted in the provided area, the size of the RenderResult must be (0, 0). If the size is non-zero, this method must return a RenderResult with has_more == false after a finite number of calls.
Loading content...

Provided methods

fn framed(self) -> FramedElement<Self> where
    Self: Sized

Draws a frame around this element.

fn padded(self, padding: impl Into<Margins>) -> PaddedElement<Self> where
    Self: Sized

Adds a padding to this element.

fn styled(self, style: impl Into<Style>) -> StyledElement<Self> where
    Self: Sized

Sets the default style for this element and its children.

Loading content...

Implementors

impl Element for Break[src]

impl Element for LinearLayout[src]

impl Element for OrderedList[src]

impl Element for Paragraph[src]

impl Element for TableLayout[src]

impl Element for Text[src]

impl Element for UnorderedList[src]

impl<E: Element> Element for BulletPoint<E>[src]

impl<E: Element> Element for FramedElement<E>[src]

impl<E: Element> Element for PaddedElement<E>[src]

impl<E: Element> Element for StyledElement<E>[src]

Loading content...