Struct rckive_genpdf::elements::TableLayout
source · pub struct TableLayout { /* private fields */ }
Expand description
Arranges elements in columns and rows.
This struct can be used to layout arbitrary elements in columns in rows, or to draw typical
tables. You can customize the cell style by providing a CellDecorator
implementation.
If you want to print a typical table with borders around the cells, use the
FrameCellDecorator
.
The column widths are determined by the weights that have been set in the constructor. The table always uses the full width of the provided area.
Examples
With setters:
use rckive_genpdf::elements;
let mut table = elements::TableLayout::new(vec![1, 1]);
table.set_cell_decorator(elements::FrameCellDecorator::new(true, true, false));
let mut row = table.row();
row.push_element(elements::Paragraph::new("Cell 1"));
row.push_element(elements::Paragraph::new("Cell 2"));
row.push().expect("Invalid table row");
Chained:
use rckive_genpdf::elements;
let table = elements::TableLayout::new(vec![1, 1])
.row()
.element(elements::Paragraph::new("Cell 1"))
.element(elements::Paragraph::new("Cell 2"))
.push()
.expect("Invalid table row");
Implementations§
source§impl TableLayout
impl TableLayout
sourcepub fn new(column_weights: Vec<usize>) -> TableLayout
pub fn new(column_weights: Vec<usize>) -> TableLayout
Creates a new table layout with the given column weights.
The column weights are used to determine the relative width of the columns. The number of column weights determines the number of columns in the table.
sourcepub fn set_cell_decorator(&mut self, decorator: impl CellDecorator + 'static)
pub fn set_cell_decorator(&mut self, decorator: impl CellDecorator + 'static)
Sets the cell decorator for this table.
sourcepub fn row(&mut self) -> TableLayoutRow<'_>
pub fn row(&mut self) -> TableLayoutRow<'_>
Adds a row to this table using the TableLayoutRow
helper struct.