Table
table · Containers · interactive
A table: columns that agree, a header that stays, and rows that virtualise.
Import
cpp
#include "gbui/widgets/table.hpp"Example
cpp
TableResult table(Ui& ui, const Interaction& input, std::string_view id, const std::vector<Column>& columns, std::size_t rowCount, TableState& state, const std::function<void(Ui&, std::size_t row, std::size_t column)>& cell, const TableOptions& options = {});Draws a table and reports what the reader did to it. cell is called for each visible cell and builds whatever belongs there. It is given the row and the column; the box it draws into is already the right width, because the widths are resolved once for the whole table rather than negotiated per row. That is the difference between a table and a list of rows that happen to contain the same number of things. The application owns the data, the order and the selection. This owns the geometry.
API
TableOptions
| Option | Type | Default | What it does |
|---|---|---|---|
rowHeight | float | 30.0f | |
headerHeight | float | 32.0f | |
stickyHeader | bool | true | The header stays put while the body scrolls under it. |
zebra | bool | false | Alternating row shading. Off by default: with a hover and a selection already in play, a third band is usually noise. |
virtualise | bool | true | Builds only the visible rows. Off draws them all, which is right for a table of twenty and wrong for one of fifty thousand. |
cellPadding | Edges | Edges::symmetric(0.0f, 10.0f) | |
gridLines | float | 1.0f | The hairline under the header, and the width of every other rule here. |
rowLines | bool | false | A rule under every row. Off by default: on a table read top to bottom, the rows are already separated by their own alignment, and a line under each one is a lot of ink for no information. Worth turning on when the cells wrap to different heights, or when the reader is comparing across a row rather than down a column. |
columnLines | bool | false | A rule between every column, in the header and in the body — which, together with rowLines, is a full grid. |
grow | float | 1.0f | |
height | float | kAuto | |
name | std::string_view | What the table is of — "Commits by author". A grid of numbers with no name is the hardest thing on a screen to make sense of by ear. |