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 default to Theme::DARK (as if
Table::theme had been called); 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.
§Examples
use retroglyph_core::grid::{Grid, Rect};
use retroglyph_ui::{ListState, StatefulWidget, Surface, Table};
let headers = ["Name", "Score"];
let widths = [10u16, 6];
let rows: [&[&str]; 2] = [&["Alpha", "10"], &["Bravo", "20"]];
let mut state = ListState::new();
state.select(Some(1));
let area = Rect::new(0, 0, 20, 3);
let mut grid = Grid::new(20, 3);
Table::new(&headers, &widths, &rows).render(&mut Surface::new(&mut grid, area, 0), &mut state);Implementations§
Source§impl<'a> Table<'a>
impl<'a> Table<'a>
Sourcepub fn new(
headers: &'a [&'a str],
widths: &'a [u16],
rows: &'a [&'a [&'a str]],
) -> Self
pub fn new( headers: &'a [&'a str], widths: &'a [u16], rows: &'a [&'a [&'a str]], ) -> Self
A table with the given header labels, column widths, and rows, styled from
Theme::DARK (as if Table::theme had been called).
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 for the same reason, and with
the same caveat, as super::Gauge::theme; see its doc comment for the full explanation.
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.
Sourcepub fn theme_on(self, theme: Theme, bg: Color) -> Self
pub fn theme_on(self, theme: Theme, bg: Color) -> Self
Same as Table::theme, but header_style/row_style are drawn on bg instead of
theme.panel_bg: for a table drawn directly on a backdrop other than a themed
super::Panel/super::Modal’s fill, e.g. the raw screen background or a different
panel’s fill color. Table::theme is exactly theme_on(theme, theme.panel_bg).
Trait Implementations§
Source§impl Measure for Table<'_>
impl Measure for Table<'_>
Source§fn height_for(&self, _width: u16) -> u16
fn height_for(&self, _width: u16) -> u16
One row per data row, plus the always-drawn header row; width is ignored, since cells
are truncated per column rather than wrapped.
Source§impl StatefulWidget for Table<'_>
impl StatefulWidget for Table<'_>
impl<'a> Copy for Table<'a>
Auto Trait Implementations§
impl<'a> Freeze for Table<'a>
impl<'a> RefUnwindSafe for Table<'a>
impl<'a> Send for Table<'a>
impl<'a> Sync for Table<'a>
impl<'a> Unpin for Table<'a>
impl<'a> UnsafeUnpin for Table<'a>
impl<'a> UnwindSafe for Table<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<C> WithAlpha for Cwhere
C: Copy,
impl<C> WithAlpha for Cwhere
C: Copy,
§fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
self with alpha, storing alpha before the color in memory
(see [AlphaFirst]).§fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
self with alpha, storing alpha after the color in memory
(see [AlphaLast]).