Widgets#

Every widget is one function call. This page shows each one with a short example. The full signatures are in the API reference.

Widgets that return bool return true in the frame something happened: a button was activated, or a value changed. Widgets that take a pointer read the value from it and write the new value back.

The gallery with text, buttons and icon buttons

Text widgets, buttons, a disabled button and icon buttons in the default theme.#

Title bar#

ui_titlebar("CEUI tour", ui_fmt("%u demos", 7));

A bar across the top of the screen with a title on the left and an optional second text on the right. Either can be NULL. Call it first in the frame; the content area starts below it.

Softkeys#

static const char *const keys[UI_SOFTKEYS] = {"Dark", NULL, NULL, "Home", "Quit"};

int key = ui_softkeys(keys);
if (key == UI_F1) toggle_dark();
if (key == UI_F5) ui_quit();

A bar of five keys across the bottom of the screen, one for each key under it: [y=], [window], [zoom], [trace] and [graph]. It returns UI_F1 to UI_F5 for the key pressed in this frame, or -1. A NULL label is an empty key that does nothing. The array must have UI_SOFTKEYS entries. Softkeys ignore their keys while a modal or menu is open.

Call it early in the frame, before the widgets, so the content area ends above it and the key is handled before anything else sees it.

Text#

ui_heading("Buttons");
ui_text("Text wraps at spaces to the width of its column.");
ui_caption("A caption is muted.");
ui_label("A label stays on one line and ends with an ellipsis");

ui_heading is a section title with a line under it, ui_text wraps, ui_caption is wrapped text in a muted color, and ui_label is one line that ends with an ellipsis when it does not fit. See text and formatting.

Button#

if (ui_button("Save")) save();

Returns true in the frame the user presses [enter] or [2nd] on it. The id comes from the label, so use ui_next_id when the label changes or two buttons share a label (see ids). Use ui_next_style for a primary or danger button:

ui_next_style(&style_primary);
if (ui_button("Create")) create();
Plain, primary and danger buttons, toggles and a check box

Three buttons in a row, the second and third with their own style, above toggles and a check box.#

Icon button#

static const uint8_t glyph_star[] = {0x10, 0x10, 0x38, 0xFE, 0x7C, 0x38, 0x6C, 0x44};

ui_height(44);
if (ui_icon_button(glyph_star, "Favorites")) open_favorites();

A button with an 8 by 8 glyph drawn at twice its size above the label. A glyph is 8 bytes, one per row from the top, and the highest bit of each byte is the leftmost pixel. It is drawn in the button’s text color, so it follows focus and the theme.

A grid of six icon buttons

A launcher made of icon buttons in three columns.#

Check box#

static bool locked;

ui_check("Lock the choices", &locked);

Flips *on when activated and returns true in that frame. The label is drawn right after the box. Pass NULL for a box without a label.

Toggle#

static bool sound = true;

if (ui_toggle("Sound", &sound)) set_sound(sound);

The same as a check box, drawn as a switch on the right of a labeled row.

Sound toggled off and Wi-Fi toggled on

Sound turned off and Wi-Fi turned on.#

Radio button#

static const char *const angles[] = {"Radian", "Degree"};
static uint8_t angle;

ui_columns(2, NULL);
for (uint8_t i = 0; i < 2; i++) ui_radio(angles[i], &angle, i);
ui_columns(1, NULL);

Sets *value to option when activated. Radio buttons that share value form a group. Each one gets its own id from the address and the option.

Choice#

static const char *const modes[] = {"Normal", "Sci", "Eng"};
static uint8_t mode;

ui_choice("Mode", &mode, modes, 3);

Shows the current option between two arrows. [left] and [right] step through the options and wrap around at both ends. Good for a handful of options that the user steps through.

A choice set to Sci

After one [right], the choice shows Sci.#

Select#

static const char *const sizes[] = {"Small", "Medium", "Large"};
static uint8_t size;

ui_select("Text size", &size, sizes, 3);

Shows the current option with a down arrow. [enter] opens a menu of all options next to it; [enter] in the menu picks one and [clear] closes it without a change. Good for longer lists of options. A value out of range is set to 0.

An open select menu over a dimmed screen

The select’s menu is open; the screen below is dimmed.#

Slider#

static int volume = 5;

ui_slider("Volume", &volume, 0, 10, 1);

[left] and [right] move the value by step. The value is kept between min and max.

Number#

static int speed = 1;

ui_number("Speed", &speed, 1, 500);

A number field. The user can:

Key

Effect

Digits

Type a new number. The first digit replaces the value, the next ones are appended

[del]

Remove the last digit

[(-)]

Change the sign, when min is below 0

[left], [right]

Subtract or add 1

[enter]

Finish typing

While the user types, the value may be outside min and max so that, for example, 150 can be typed with a minimum of 100. It is brought back into range when the user presses [enter], an arrow, or moves focus away. Digits that would make the number longer than the largest of min and max are ignored.

A slider moved right and a number with typed digits

The slider after three presses of [right], and the number after typing 42.#

Progress bar#

ui_progress(downloaded, total);

A bar filled to done out of total. Both are unsigned long, so byte counts fit. done above total shows a full bar and a total of 0 an empty one. It takes no focus.

Spinner#

if (downloading) ui_spinner();

Three dots that light up in turn, to show that work is going on. It asks for its own frames every 160 ms, so the program does not need ui_wake for it.

A pause button, a progress bar and a spinner

A download in progress. The button label changed to Pause, and ui_next_id keeps its id the same.#

Text field and text area#

ui_input("Name", name, sizeof name, UI_INPUT_UPPER);
ui_textarea(notes, sizeof notes, &notes_scroll, 72);

See text input.

List and table#

ui_list_begin(&list, count, 14, UI_FILL);
for (int i; ui_list_next(&list, &i);) ui_label(names[i]);
int picked = ui_list_end(&list);

See lists and tables.

Tabs#

ui_tabs(&tab, tab_names, 3);

See tabs.

Image and canvas#

ui_image(sprite, 2);
ui_canvas(96, draw_plot, &plot, plot.version);

See drawing.

All widgets in one screen#

Check box, radio buttons, toggle, choice, select, slider, number, progress and input

The value widgets of the gallery test program in the default theme.#

Text area, tabs, panel, table and canvas

The text area, tabs, a panel, a table and a canvas.#