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.
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.
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 turned off and Wi-Fi turned on.#
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.
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.
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 |
|
Remove the last digit |
|
Change the sign, when |
|
Subtract or add 1 |
|
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.
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 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, ¬es_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#
The value widgets of the gallery test program in the default theme.#
The text area, tabs, a panel, a table and a canvas.#