Skip to content

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

Nothing is downloaded until you press it.

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

OptionTypeDefaultWhat it does
rowHeightfloat30.0f
headerHeightfloat32.0f
stickyHeaderbooltrueThe header stays put while the body scrolls under it.
zebraboolfalseAlternating row shading. Off by default: with a hover and a selection already in play, a third band is usually noise.
virtualisebooltrueBuilds only the visible rows. Off draws them all, which is right for a table of twenty and wrong for one of fifty thousand.
cellPaddingEdgesEdges::symmetric(0.0f, 10.0f)
gridLinesfloat1.0fThe hairline under the header, and the width of every other rule here.
rowLinesboolfalseA 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.
columnLinesboolfalseA rule between every column, in the header and in the body — which, together with rowLines, is a full grid.
growfloat1.0f
heightfloatkAuto
namestd::string_viewWhat 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.

Released under the LGPL-3.0-or-later licence.