Widgets#

Declared in ui.h. See widgets for examples and screenshots.

Every widget is placed in the current container at the next free spot, as wide as its column. Labeled controls draw the label in a column ui_metrics.label pixels wide (at most half the row) and the control to its right; a NULL label gives the control the full width. ui_next_style replaces a widget’s main style, and ui_height its height.

All text arguments are copied while the frame is recorded, so they may be temporary.

Screen chrome#

ui_titlebar#

void ui_titlebar(const char *title, const char *right);

Draws a bar ui_metrics.titlebar pixels high across the top of the screen, in ui_style_titlebar, and moves the top of the content area below it. Call it before the widgets of the frame.

Parameter

Meaning

title

Text drawn with the style’s alignment, or NULL

right

Text drawn at the right end, or NULL. The title is cut with an ellipsis to make room for it

ui_softkeys#

int ui_softkeys(const char *const *labels);

Draws five keys ui_metrics.softkeys pixels high across the bottom of the screen, in ui_style_softkey, and moves the bottom of the content area above them. A key is drawn in its UI_ACTIVE colors in the frame it is pressed. While a modal or menu is open, the keys are drawn but ignore their keys.

Parameter

Meaning

labels

An array of UI_SOFTKEYS (5) labels for [y=], [window], [zoom], [trace] and [graph]. A NULL label is an empty key that does nothing

Returns UI_F1 to UI_F5 for the key pressed in this frame, or -1. The key is used up.

Text#

ui_heading#

void ui_heading(const char *text);

Draws a section title in ui_style_heading, wrapped to the column.

ui_text#

void ui_text(const char *text);

Draws a paragraph in ui_style_text, wrapped at spaces to the column. \n starts a new line. A word is split only when it is wider than the line. Lines outside the visible area are not recorded.

ui_caption#

void ui_caption(const char *text);

Draws wrapped text in ui_style_caption, a muted color in the default theme.

ui_label#

void ui_label(const char *text);

Draws one line of text in ui_style_text. Text that does not fit is cut and ends with an ellipsis. In a UI_AUTO column it is as wide as its text.

ui_fmt#

const char *ui_fmt(const char *format, ...);

Formats text into one of UI_FMT_SLOTS (4) rotating buffers of UI_FMT_SIZE (64) bytes and returns it.

Parameter

Meaning

format

Text with %s, %c, %d, %u, %x, %ld, %lu, %lx or %%. No widths or precision

...

One argument per specifier

Returns the formatted text, cut to UI_FMT_SIZE - 1 characters. It stays valid until ui_fmt has been called UI_FMT_SLOTS more times. %s with NULL prints nothing; an unknown specifier prints the character after %.

Buttons#

ui_button#

bool ui_button(const char *label);

Draws a button in ui_style_button with the label in the middle. Its id is a hash of the label; use ui_next_id for labels that change or repeat.

Returns true in the frame the user presses [enter] or [2nd] on it.

ui_icon_button#

bool ui_icon_button(const uint8_t *glyph, const char *label);

Draws a button in ui_style_button with a glyph at twice its size above the label. Its id is a hash of the label.

Parameter

Meaning

glyph

8 bytes, one per row from the top; the highest bit is the leftmost pixel. Drawn in the button’s text color

label

The text under the glyph

Returns true in the frame it is activated.

Value widgets#

ui_check#

bool ui_check(const char *label, bool *on);

Draws a check box in ui_style_check with its label right after it. [enter] or [2nd] flips *on. The id is the address on.

Returns true in the frame the value changed.

ui_toggle#

bool ui_toggle(const char *label, bool *on);

Draws a labeled switch, the track in ui_style_toggle and the knob in ui_style_knob. [enter] or [2nd] flips *on. The id is the address on.

Returns true in the frame the value changed.

ui_radio#

bool ui_radio(const char *label, uint8_t *value, uint8_t option);

Draws one radio button in ui_style_radio, checked when *value == option. Activating it sets *value to option. Radio buttons that share value form a group. The id is the address value mixed with option.

Returns true in the frame it is activated.

ui_choice#

bool ui_choice(const char *label, uint8_t *value, const char *const *options, uint8_t count);

Draws the option options[*value] between a left and a right arrow, in ui_style_choice. [left] and [right] step through the options and wrap around. A *value out of range is set to 0.

Parameter

Meaning

label

The label, or NULL

value

Index of the current option

options

count option labels

count

Number of options

Returns true in the frame the value changed.

ui_select#

bool ui_select(const char *label, uint8_t *value, const char *const *options, uint8_t count);

Draws the option options[*value] with a down arrow, in ui_style_select. [enter] or [2nd] opens a menu of all options next to it; picking one sets *value, and [clear] closes the menu without a change. The field is drawn in its UI_ACTIVE colors while the menu is open. A *value out of range is set to 0. Parameters as in ui_choice.

Returns true in the frame the value changed.

ui_slider#

bool ui_slider(const char *label, int *value, int min, int max, int step);

Draws a labeled slider: a track in ui_style_track, filled up to the thumb in ui_style_fill, and a thumb in ui_style_thumb. [left] and [right] change *value by step. *value is kept between min and max.

Returns true in the frame the value changed.

ui_number#

bool ui_number(const char *label, int *value, int min, int max);

Draws a labeled number field in ui_style_input, with arrows on both sides.

Key

Effect

Digit keys

The first digit replaces the value, the next ones are appended. Digits that would go past the larger of abs(min) and abs(max) are ignored

[del]

Removes the last digit

[(-)]

Changes the sign, when min is below 0

[left], [right]

Subtract or add 1

[enter]

Ends typing

While digits are typed the field is drawn in its UI_ACTIVE colors, and the value may be outside min and max. It is clamped when typing ends, when an arrow is pressed and when focus leaves.

Returns true in the frame the value changed.

ui_progress#

void ui_progress(unsigned long done, unsigned long total);

Draws an 8 pixel high bar in ui_style_track, filled to done / total in ui_style_fill. done above total counts as total, and a total of 0 draws an empty bar. It takes no focus.

ui_spinner#

void ui_spinner(void);

Draws three dots in ui_style_track, one of them in ui_style_fill, moving every 160 ms. It calls ui_wake for its own frames. It takes no focus.

Text input#

See text input for modes and the key map.

Input flags#

enum { UI_INPUT_UPPER = 1, UI_INPUT_NUMERIC = 2, UI_INPUT_SECRET = 4 };

Flag

Effect

UI_INPUT_UPPER

Start in upper case mode instead of lower case

UI_INPUT_NUMERIC

Start in number mode and stay there

UI_INPUT_SECRET

Draw a * for each character

ui_input#

bool ui_input(const char *label, char *text, size_t size, uint8_t flags);

Draws a labeled one line text field in ui_style_input that edits text in place. The focused field shows a cursor and its mode letter (A, a or 1). The id is the address text.

Parameter

Meaning

label

The label, or NULL

text

A zero-terminated buffer

size

The size of the buffer in bytes, terminator included. A full buffer ignores further characters

flags

UI_INPUT_* flags joined with |, or 0

Returns true when [enter] is pressed in the field. Focus then moves to the next widget.

ui_textarea#

bool ui_textarea(char *text, size_t size, ui_scroll_t *scroll, int h);

Draws a multi-line text editor in ui_style_input, h pixels high, with a scroll bar. [enter] inserts a line break, [up] and [down] move between lines and leave the area at the first and the last line, and [clear] empties the text. It starts in lower case mode. At most 64 lines are laid out. The id is the address text.

Parameter

Meaning

text

A zero-terminated buffer

size

The size of the buffer in bytes, terminator included

scroll

The area’s scroll state. It follows the cursor

h

Height in pixels

Returns true in the frame the text changed.