pub struct FlowLayout { /* private fields */ }Expand description
Automatic flow layout engine with page break support.
Manages a vertical cursor and a list of elements. When an element would overflow the current page’s bottom margin, a new page is created automatically.
§Example
use oxidize_pdf::{Document, Font};
use oxidize_pdf::layout::{FlowLayout, PageConfig};
let config = PageConfig::a4_with_margins(50.0, 50.0, 50.0, 50.0);
let mut layout = FlowLayout::new(config);
layout.add_text("Hello World", Font::Helvetica, 12.0);
layout.add_spacer(20.0);
layout.add_text("Second paragraph", Font::Helvetica, 12.0);
let mut doc = Document::new();
layout.build_into(&mut doc).unwrap();Implementations§
Source§impl FlowLayout
impl FlowLayout
Sourcepub fn new(config: PageConfig) -> Self
pub fn new(config: PageConfig) -> Self
Create a new FlowLayout with the given page configuration.
Sourcepub fn add_text(&mut self, text: &str, font: Font, font_size: f64) -> &mut Self
pub fn add_text(&mut self, text: &str, font: Font, font_size: f64) -> &mut Self
Add a text block. Uses default line_height of 1.2.
Sourcepub fn add_text_with_line_height(
&mut self,
text: &str,
font: Font,
font_size: f64,
line_height: f64,
) -> &mut Self
pub fn add_text_with_line_height( &mut self, text: &str, font: Font, font_size: f64, line_height: f64, ) -> &mut Self
Add a text block with custom line height.
Sourcepub fn add_spacer(&mut self, points: f64) -> &mut Self
pub fn add_spacer(&mut self, points: f64) -> &mut Self
Add vertical spacing in points.
Sourcepub fn add_image(
&mut self,
name: &str,
image: Arc<Image>,
max_width: f64,
max_height: f64,
) -> &mut Self
pub fn add_image( &mut self, name: &str, image: Arc<Image>, max_width: f64, max_height: f64, ) -> &mut Self
Add an image scaled to fit within max dimensions, left-aligned.
Wraps the image in Arc internally to avoid expensive buffer clones.
Sourcepub fn add_image_centered(
&mut self,
name: &str,
image: Arc<Image>,
max_width: f64,
max_height: f64,
) -> &mut Self
pub fn add_image_centered( &mut self, name: &str, image: Arc<Image>, max_width: f64, max_height: f64, ) -> &mut Self
Add an image scaled to fit within max dimensions, centered horizontally.
Wraps the image in Arc internally to avoid expensive buffer clones.
Sourcepub fn add_rich_text(&mut self, rich: RichText) -> &mut Self
pub fn add_rich_text(&mut self, rich: RichText) -> &mut Self
Add a single line of mixed-style text.
Sourcepub fn build_into(&self, doc: &mut Document) -> Result<()>
pub fn build_into(&self, doc: &mut Document) -> Result<()>
Build all elements into the document, creating pages as needed.
Limitation: Elements taller than PageConfig::usable_height() (e.g., a very
large table) will overflow past the bottom margin on a single page. They are not
split across pages.
Auto Trait Implementations§
impl Freeze for FlowLayout
impl RefUnwindSafe for FlowLayout
impl Send for FlowLayout
impl Sync for FlowLayout
impl Unpin for FlowLayout
impl UnsafeUnpin for FlowLayout
impl UnwindSafe for FlowLayout
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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