Skip to main content

TableCursor

Struct TableCursor 

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

Tracks where the next row will be placed within a page.

Created once per table area, then passed to each fit_row call. Call reset() when starting a new page to restore the cursor to the top of the new rect. is_first_row() lets the caller detect a fresh page — useful for repeating a header row.

§Example

let mut cursor = TableCursor::new(&rect);
let mut rows = data.iter().peekable();
while rows.peek().is_some() {
    doc.begin_page(612.0, 792.0);
    // Repeat header on every page
    doc.fit_row(&table, &header, &mut cursor).unwrap();
    while let Some(row) = rows.peek() {
        match doc.fit_row(&table, row, &mut cursor).unwrap() {
            FitResult::Stop    => { rows.next(); }
            FitResult::BoxFull => break,
            FitResult::BoxEmpty => { rows.next(); break; }
        }
    }
    doc.end_page().unwrap();
    if rows.peek().is_some() { cursor.reset(&rect); }
}

Implementations§

Source§

impl TableCursor

Source

pub fn new(rect: &Rect) -> Self

Create a cursor positioned at the top of rect.

Source

pub fn reset(&mut self, rect: &Rect)

Reset to the top of a new rect. Call this when starting a new page.

Source

pub fn is_first_row(&self) -> bool

Returns true if no rows have been placed on the current page yet.

Use this to detect the start of a new page so you can insert a repeated header row before placing data rows.

Source

pub fn current_y(&self) -> f64

Returns the Y coordinate where the next row would be placed.

After placing all rows, this equals the bottom edge of the last row. Use it to position content that follows the table (e.g., totals section) without guessing where the table ended.

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.