Skip to main content

Module table

Module table 

Source
Expand description

Table — for rows that are tuples.

Most lists of things in this library are records, and a record reads better as a card: group_box + card_row + row_title + meta_line already does that, and does it better than a table would. Reach for this one only when the third column of every row has to line up, because reading down it is the point.

Which is also the failure this component exists to prevent. A header and a body that size their own cells drift apart the moment either changes, and nothing catches it — both halves look right on their own. So the columns are declared once and shared:

const COLUMNS: &[Column] = ..;                     // one declaration

table(&theme)
    .child(header(&theme).children(COLUMNS.iter().enumerate().map(|(index, column)| {
        header_cell(&theme, column, sorted_direction(index))
            .id(("column", index))
            .on_click(cx.listener(move |view, _, _, cx| view.sort_by(index, cx)))
    })))
    .children(rows.iter().enumerate().map(|(index, item)| {
        row(&theme, COLUMNS, index == 0, false, vec![
            item.name.clone().into_any_element(),
            item.kind.clone().into_any_element(),
        ])
    }))

Sorting is the caller’s: next_sort says what a click on a heading means, the caller sorts its own rows, and this module paints the arrow. Nothing here holds data, so nothing here can hold it out of date.

Structs§

Column
One column, declared once and handed to both the header and every row.
Sort
Which column a table is sorted by, and which way.

Enums§

Align
Which edge a cell’s content sits against.
Width
How wide a column is: a fixed measure, or a share of what is left after the fixed ones have taken theirs.

Functions§

header
The heading strip. Fill header_cells into it, one per column.
header_cell
One heading. sorted carries the direction when this is the sorted column, and None when it is not.
next_sort
What a click on column’s heading means: the sorted column reverses, any other column starts ascending.
row
One body row, its cells zipped onto the columns.
table
The frame. Clipped, so a row’s hover wash cannot square off the corners.