Lists, tables and tabs#
Declared in ui.h. See lists and tables and tabs for examples.
ui_list_t#
typedef struct {
int selected, top;
} ui_list_t;
The state of a list. selected is the index of the selected row and top the index of the first visible row. Keep
it in a static or global variable and start it at zero. You may set selected; the list keeps it in range and
scrolls to it.
ui_list_begin#
void ui_list_begin(ui_list_t *list, int count, int row_h, int h);
Starts a list in ui_style_list, as wide as the current column. The list is one focus stop: [up] and [down] move
the selection (and leave the list at the first and last row), [left] and [right] move it by one page, and
[enter] or [2nd] activates the selected row. The list scrolls to keep the selection visible and shows a scroll
bar when not all rows fit.
Parameter |
Meaning |
|---|---|
|
The list’s state. Its address is also the list’s id |
|
The number of rows |
|
The height of each row in pixels, at least 1 |
|
The height of the list in pixels, or |
Follow it with a ui_list_next loop and ui_list_end. A ui_columns call right after it applies to every row.
ui_list_next#
bool ui_list_next(ui_list_t *list, int *index);
Moves to the next visible row. It ends the row before, draws the new row’s background in ui_style_row (in its
UI_FOCUS colors for the selected row of a focused list, UI_ON for the selected row otherwise), and makes the row
the current container for the widgets you place next. Widgets in rows take their colors from the row and do not take
focus.
Parameter |
Meaning |
|---|---|
|
The same state passed to |
|
Set to the index of the row |
Returns true for each visible row, then false.
for (int i; ui_list_next(&list, &i);) ui_label(names[i]);
ui_list_end#
int ui_list_end(ui_list_t *list);
Ends the list, draws its scroll bar and goes back to the parent container.
Returns the index of the row activated with [enter] or [2nd] in this frame, or -1.
ui_header#
void ui_header(const char *const *labels, const int *widths, uint8_t count);
Draws a table header in ui_style_header: one label per column, laid out like ui_columns(count, widths). Put it
right above a list that uses the same widths.
Parameter |
Meaning |
|---|---|
|
|
|
|
|
Number of columns |
ui_tabs#
bool ui_tabs(uint8_t *active, const char *const *labels, uint8_t count);
Draws a row of tabs in ui_style_tab, each as wide as its label. The row is one focus stop; [left] and [right]
move to the tab before or after, stopping at the ends. The active tab is drawn in its UI_ON colors, or UI_FOCUS
while the row has focus. A *active out of range is set to 0. The program draws the content of the active tab after
the call.
Parameter |
Meaning |
|---|---|
|
Index of the active tab. Its address is also the id |
|
|
|
Number of tabs |
Returns true in the frame the active tab changed.