Guide API
Skip to main content

Module layout

Module layout 

Source
Expand description

Column specs and the pure layout/format/sort helpers behind the table’s header and body. Nothing here touches a view; everything is unit-tested.

The helpers are adapted from tvdocker’s table (MIT, by supertorpe): widest-first column shrinking, ellipsis truncation, the header sort marker, and the stable sort.

Structs§

ColumnSpec
One column of a Table.
RowLayout
The horizontal geometry of a table row for one view width: the leading frozen layout columns (the check column) stay put, the rest scroll.
ValidatorFactory
A shareable factory of Validators for a column’s cell editors: each editor owns its validator, so the column keeps the recipe, not an instance. Two factories are equal only when they are the same one.

Enums§

Align
Column alignment inside its cell.
Separators
Which column separators a Table draws between its columns. A separator is always one cell wide; this only chooses whether that cell holds a visible rule, so the layout never shifts. The rule glyph itself belongs to the theme (its frame_v); the draw that renders it passes it in, like the ListViewer divider does.
SortDir
A sort direction.

Constants§

CHECK_WIDTH
Width of the multi-select check column: the [ ] box of CheckBoxes.
MAX_COLUMN_WIDTH
The widest a column is ever laid out, in cells. Every cell is padded to its column width when drawn, so an unbounded width would allocate without bound; a user resize and Table::set_column_layout clamp to it as well.

Functions§

check_column
The fixed, non-shrinkable check column a multi-select table lays out in front of its own columns (blank label).
column_at
The column whose cell spans text-relative column x, or None (a separator, past the last column, or before the first).
format_line
The rendered text of model row row: each visible column padded or truncated to its width, separated by sep.
header_line
The header text: the labels laid out like format_line, the sorted column’s label carrying ▲/▼. A label too long for its column is cut so the marker stays visible.
layout_widths
Distribute avail cells over cols: hidden columns get 0; the visible ones keep their preferred width while everything (plus one separator between neighbouring visible columns) fits, else the currently widest shrinkable column loses one cell per pass until it fits or every column sits at its min_width (a fixed one at its width). Shrinking comes first, scrolling second: a layout that still does not fit, even one whose separators alone fill avail, keeps every column at that floor and is wider than avail; the table scrolls it horizontally. Spare cells go to the flex columns by weight (see stretch); without one they stay empty. With no visible column, or no cell at all (avail ≤ 0), every width is 0.
line_width
The width of a line of widths joined with one-cell separators (zero-width columns take no cell and no separator).
pad_cell
Fit cell into exactly width display columns: pad with spaces per align, or cut the tail and mark the cut with … (width 1 → "…"). Measured in display columns, so wide characters are never split.
slice_cols
The part of s from display column skip that fits in width display columns. A wide glyph cut by either edge turns into spaces for its visible half, so the result never starts mid-glyph.
sort_order
The display order of model sorted by column col: model row indices, stable for ties (equal keys keep model order in both directions). Numbers come before text in both directions.
stretch
Give spare cells to the visible, non-zero-width flex columns: each gets spare * weight / total_weight (rounded down), and the cells the rounding leaves over go one each to the leftmost flex columns. Without a flex column nothing changes.
with_check_cell
Prefix rest (an already joined line) with the check-column cell check of width w0, separated by sep exactly as the other columns are. A zero-width check column (no room at all) adds nothing.