pub struct Table<'a> { /* private fields */ }Expand description
A fixed-column, scrollable table with a ListState-driven highlighted
row.
headers render on the first row of the area it’s rendered into;
rows follow, one per line, clipped to that area. widths gives each
column’s cell width; columns are space-separated and truncated to fit.
state.offset() is the index of the first row drawn below the header –
rendering draws whatever window offset names and does not clamp or
auto-scroll it, matching ListState’s existing “only the caller knows
the viewport height” design. Call
state.ensure_visible(visible_row_count)
before rendering to keep state.selected() on-screen. If selected() is
Some and its row falls within the visible window, that row is drawn
with an inverted highlight background; if it has scrolled out of view,
no row is highlighted.
header_style, row_style, and selected_style each default to a fixed
palette (a light blue-gray header, a dim gray-blue for unselected rows,
and a bright-white-on-dark-blue highlight for the selected row); set them
with Table::header_style, Table::row_style, and
Table::selected_style. column_spacing defaults to 1 (a single
blank column between cells); set it with Table::column_spacing.
Implementations§
Source§impl<'a> Table<'a>
impl<'a> Table<'a>
Sourcepub fn new(
headers: &'a [&'a str],
widths: &'a [u16],
rows: &'a [Vec<String>],
) -> Self
pub fn new( headers: &'a [&'a str], widths: &'a [u16], rows: &'a [Vec<String>], ) -> Self
A table with the given header labels, column widths, and rows, in the default style.
Sourcepub const fn header_style(self, style: Style) -> Self
pub const fn header_style(self, style: Style) -> Self
Set the header row’s style.
Sourcepub const fn selected_style(self, style: Style) -> Self
pub const fn selected_style(self, style: Style) -> Self
Set the style of the selected row, including its background fill.
Sourcepub const fn column_spacing(self, spacing: u16) -> Self
pub const fn column_spacing(self, spacing: u16) -> Self
Set the number of blank columns between cells.
Sourcepub fn theme(self, theme: Theme) -> Self
pub fn theme(self, theme: Theme) -> Self
Applies theme’s named roles to this table’s row styles: header_style becomes
theme.fg (brighter, matching the header’s original brighter-than-row default) on
theme.panel_bg, row_style becomes theme.dim (the same de-emphasized role a plain
body row already reads as) on theme.panel_bg, and selected_style becomes theme.bg
on theme.accent – the same bright-on-accent highlight super::List::theme and
super::Button::theme use.
header_style/row_style always set an explicit background rather than leaving it at
Style::new()’s default: an unset background isn’t “transparent” once a real backend
draws it (a bare Color::Default cell paints as solid black behind the glyph, not
whatever was there before – see retroglyph-software’s DEFAULT_BG), so this widget
assumes it’s drawn on theme.panel_bg – true when composed with a themed
super::Panel/super::Modal, the common case – rather than risk a black box behind
every row on a light Theme. Drawing this table directly on the raw screen background
instead of inside a themed panel needs a manual .header_style(...)/.row_style(...)
override afterwards.
Call before any manual Table::header_style/Table::row_style/
Table::selected_style override you want to keep.