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§
- Column
Spec - One column of a
Table. - RowLayout
- The horizontal geometry of a table row for one view width: the leading
frozenlayout columns (the check column) stay put, the rest scroll. - Validator
Factory - 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
Tabledraws 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 (itsframe_v); the draw that renders it passes it in, like theListViewerdivider does. - SortDir
- A sort direction.
Constants§
- CHECK_
WIDTH - Width of the multi-select check column: the
[ ]box ofCheckBoxes. - 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_layoutclamp 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, orNone(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 bysep. - 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
availcells overcols: 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 itsmin_width(afixedone at itswidth). Shrinking comes first, scrolling second: a layout that still does not fit, even one whose separators alone fillavail, keeps every column at that floor and is wider thanavail; the table scrolls it horizontally. Spare cells go to theflexcolumns by weight (seestretch); 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
widthsjoined with one-cell separators (zero-width columns take no cell and no separator). - pad_
cell - Fit
cellinto exactlywidthdisplay columns: pad with spaces peralign, 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
sfrom display columnskipthat fits inwidthdisplay 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
modelsorted by columncol: model row indices, stable for ties (equal keys keep model order in both directions). Numbers come before text in both directions. - stretch
- Give
sparecells to the visible, non-zero-width flex columns: each getsspare * 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 cellcheckof widthw0, separated bysepexactly as the other columns are. A zero-width check column (no room at all) adds nothing.