etui/widgets/table
Types
Scroll and selection state. Keep external so state persists across renders.
pub type TableState {
TableState(selected_row: Int, offset: Int)
}
Constructors
-
TableState(selected_row: Int, offset: Int)
Table widget configuration. col_widths are in terminal cells.
pub type TableWidget {
TableWidget(
rows: List(List(String)),
col_widths: List(Int),
col_constraints: List(geometry.Constraint),
show_header: Bool,
fg: style.Color,
bg: style.Color,
highlight_style: style.Style,
blink_period: Int,
)
}
Constructors
-
TableWidget( rows: List(List(String)), col_widths: List(Int), col_constraints: List(geometry.Constraint), show_header: Bool, fg: style.Color, bg: style.Color, highlight_style: style.Style, blink_period: Int, )Arguments
- col_widths
-
Fixed column widths in cells. Used when
col_constraintsis empty. - col_constraints
-
Constraint-based column widths. When non-empty, resolved at render time from the available area width (separators subtracted automatically).
- blink_period
-
Blink period in frames (0 = no blink).
Values
pub fn clamp_state(
state: TableState,
row_count: Int,
) -> TableState
Clamp selected_row to [0, row_count - 1].
Call after replacing the row list to avoid a stale selection index.
pub fn effective_offset(
state: TableState,
visible_data_h: Int,
) -> Int
Effective scroll offset for a viewport of visible_data_h data rows.
When show_header is True, pass area.size.height - 1; otherwise pass area.size.height.
Pass as offset to scrollbar.scrollbar_new.
pub fn render(
buf: buffer.Buffer,
area: geometry.Rect,
t: TableWidget,
) -> buffer.Buffer
Render without selection highlight.
pub fn render_animated(
buf: buffer.Buffer,
area: geometry.Rect,
t: TableWidget,
state: TableState,
frame: Int,
) -> buffer.Buffer
Like render_stateful but supports blinking selection via t.blink_period.
Pass the current AnimState.frame; use with_blink(t, period) to configure.
pub fn render_stateful(
buf: buffer.Buffer,
area: geometry.Rect,
t: TableWidget,
state: TableState,
) -> buffer.Buffer
Render with selection and auto-scrolling from state.
pub fn select_next_row(
state: TableState,
row_count: Int,
) -> TableState
Move selection down by one, clamped to last row.
pub fn select_prev_row(state: TableState) -> TableState
Move selection up by one, clamped to 0.
pub fn select_row(state: TableState, idx: Int) -> TableState
Jump to a specific row (clamped to ≥ 0).
pub fn state_new() -> TableState
Initial state: selected_row=0, no scroll offset.
When using with_header(True), row 0 is the header (not selectable).
Use select_row(state_new(), 1) to start with the first data row highlighted.
pub fn table_new(rows: List(List(String))) -> TableWidget
New table. Column widths default to 10 cells each.
pub fn with_blink(t: TableWidget, period: Int) -> TableWidget
Blink period in frames. 0 = steady (no blink). Use with render_animated.
pub fn with_col_constraints(
t: TableWidget,
constraints: List(geometry.Constraint),
) -> TableWidget
Constraint-based column widths, resolved from area width at render time.
When set, takes precedence over col_widths.
Separator cells (│) are subtracted before resolving.
pub fn with_col_widths(
t: TableWidget,
widths: List(Int),
) -> TableWidget
Override column widths (cell counts). Must match number of columns.
pub fn with_colors(
t: TableWidget,
fg: style.Color,
bg: style.Color,
) -> TableWidget
pub fn with_header(t: TableWidget, show: Bool) -> TableWidget
When true, t.rows[0] is rendered as a bold header row (never selectable).
selected_row uses absolute indices: 0 = header, 1 = first data row, etc.
Initialize state with select_row(state_new(), 1) for the first data row.
pub fn with_highlight_style(
t: TableWidget,
s: style.Style,
) -> TableWidget
pub fn with_style(t: TableWidget, s: style.Style) -> TableWidget