Skip to main content

LayoutEngine

Struct LayoutEngine 

Source
pub struct LayoutEngine { /* private fields */ }
Expand description

Layout engine for converting tokens to paginated content

Implementations§

Source§

impl LayoutEngine

Source

pub const DISPLAY_WIDTH: f32 = 480.0

Default display width in pixels

Source

pub const DISPLAY_HEIGHT: f32 = 800.0

Default display height in pixels

Source

pub const DEFAULT_MARGIN: f32 = 32.0

Default side margins in pixels

Source

pub const DEFAULT_TOP_MARGIN: f32 = 0.0

Top margin - minimal

Source

pub const DEFAULT_HEADER_HEIGHT: f32 = 45.0

Header area for title (must match renderer HEADER_HEIGHT)

Footer area for progress (must match renderer FOOTER_HEIGHT)

Source

pub fn new(page_width: f32, page_height: f32, line_height: f32) -> Self

Create a new layout engine

§Arguments
  • page_width - Available width for content (excluding margins)
  • page_height - Available height for content (excluding header/footer)
  • line_height - Height of each line in pixels
Source

pub fn with_defaults() -> Self

Create layout engine with default display dimensions

Content area: 416x715 (accounting for margins, header, footer) Uses 10x20 font with 26px line height for comfortable reading

Source

pub fn with_font_metrics(self, metrics: FontMetrics) -> Self

Set font metrics

Source

pub fn with_margins(self, left: f32, top: f32) -> Self

Set margins

Source

pub fn layout_tokens(&mut self, tokens: &[Token]) -> Vec<Page>

Convert tokens into laid-out pages

Source

pub fn into_pages(self) -> Vec<Page>

Get the completed pages

Source

pub fn current_page_number(&self) -> usize

Get current page number

Source

pub fn total_pages(&self) -> usize

Get total pages created so far

Source

pub fn measure_text(&self, text: &str, style: TextStyle) -> f32

Measure text width for given string and style

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.