pub struct Table { /* private fields */ }document only.Expand description
Rows of cells under an optional header row.
The table has as many columns as its longest row or its header row. A
shorter row gets empty cells. Column marks, such as Self::id_column,
choose the role of a column’s plain cells and how it is cut or aligned.
use ctl_core::document::Table;
let table = Table::new(["id", "title", "age"])
.id_column(0)
.ellipsis_column(1)
.numeric_column(2)
.row(["A-1", "Ship the release", "3"]);
assert_eq!(table.rows().len(), 1);
assert_eq!(table.id_column_index(), Some(0));Implementations§
Source§impl Table
impl Table
Sourcepub fn new(headers: impl IntoIterator<Item = impl Into<Text>>) -> Self
pub fn new(headers: impl IntoIterator<Item = impl Into<Text>>) -> Self
Start a table with one header cell per item of headers.
Sourcepub const fn token_column(self, index: usize) -> Self
pub const fn token_column(self, index: usize) -> Self
Draw the plain cells of column index (counted from 0) as
Role::Token.
Sourcepub const fn id_column(self, index: usize) -> Self
pub const fn id_column(self, index: usize) -> Self
Draw the plain cells of column index (counted from 0) as
Role::Id.
Sourcepub fn ellipsis_column(self, index: usize) -> Self
pub fn ellipsis_column(self, index: usize) -> Self
Mark column index (counted from 0) as text that may be cut short.
A cell too wide for its column keeps one line and ends in …. The
column gives up its width before a column of whole words does.
Use it for a title or a summary, never for a value a reader copies
out, such as a URL or a path. Call it once per column.
Sourcepub fn numeric_column(self, index: usize) -> Self
pub fn numeric_column(self, index: usize) -> Self
Mark column index (counted from 0) as numbers.
Every cell of the column, header included, aligns right, so numbers line up on their last digit. Call it once per column.
Sourcepub const fn stacked_below(self, width: u16, label_columns: usize) -> Self
pub const fn stacked_below(self, width: u16, label_columns: usize) -> Self
Stack each row when the available width is below width cells.
The first label_columns cells of a row form its label line. The
remaining cells form the indented description under it. The label cells
are drawn as Role::Token.
Sourcepub fn row(self, cells: impl IntoIterator<Item = impl Into<Text>>) -> Self
pub fn row(self, cells: impl IntoIterator<Item = impl Into<Text>>) -> Self
Append a row of cells, one per item.
Sourcepub const fn token_column_index(&self) -> Option<usize>
pub const fn token_column_index(&self) -> Option<usize>
The column set by Self::token_column, if any.
Sourcepub const fn id_column_index(&self) -> Option<usize>
pub const fn id_column_index(&self) -> Option<usize>
The column set by Self::id_column, if any.
Sourcepub fn ellipsis_columns(&self) -> &[usize]
pub fn ellipsis_columns(&self) -> &[usize]
Columns marked with Self::ellipsis_column, in the order marked.
Sourcepub fn numeric_columns(&self) -> &[usize]
pub fn numeric_columns(&self) -> &[usize]
Columns marked with Self::numeric_column, in the order marked.
Sourcepub const fn stacked(&self) -> Option<Stacked>
pub const fn stacked(&self) -> Option<Stacked>
The narrow-layout policy set by Self::stacked_below, if any.