Overlays#
Overlays are drawn on top of the screen: modals, messages, confirmations, menus and toasts. Each one except the toast
is opened by a bool of yours. Set it to true to open the overlay, and the overlay sets it to false when it closes.
You can call overlays anywhere in the frame. They record into their own command stream, which is drawn after everything else, so they are on top even when called before other widgets.
Layers#
Modals and menus each open a layer. Only widgets on the top layer take focus and keys; everything below is drawn
dimmed and ignores input. Softkeys also ignore their keys while a layer is open. [clear] closes the top layer.
When a layer opens, focus goes to its first focusable widget. When it closes, focus goes back to the widget that had
it below. Up to UI_LAYERS (4) layers can be open at once, so a message can open over a modal.
A layer that opens or closes runs the settle frame, so keys reach the right layer from the next frame on.
Modal#
static bool rename_open;
if (ui_modal_begin(&rename_open, "Rename")) {
ui_text("A name starts with a letter and holds up to 8 letters and digits.");
bool submit = ui_input("Name", new_name, sizeof new_name, UI_INPUT_UPPER);
ui_columns(2, NULL);
if (ui_button("Cancel")) rename_open = false;
if (ui_button("Rename")) submit = true;
if (submit) rename_open = !rename(new_name);
ui_modal_end();
}
ui_modal_begin returns false and draws nothing when *open is false. Otherwise it draws a panel
ui_metrics.modal pixels wide (260 in the default theme) in the middle of the screen, with the title as a heading,
and returns true. Call ui_modal_end only when it returned true. Everything in between is placed in the modal like in
any container, columns included.
The modal is as high as its content. [clear] sets *open to false.
A modal with text, a text field and two buttons over the dimmed table.#
Message#
ui_message(&problem_open, "Check the form", "The password needs at least 4 characters.");
A modal with a title, wrapped text and an OK button. OK and [clear] close it. Either the title or the text can be
NULL. The text pointer is read every frame while the message is open, so it must stay valid; a string literal or a
variable that holds one is fine.
A message.#
Confirm#
static bool delete_open;
int answer = ui_confirm(&delete_open, "Delete", ui_fmt("Delete %s? This cannot be undone.", name), "Delete");
if (answer == UI_YES) delete_file();
A modal with a title, text and two buttons: Cancel and the label you pass as yes. It returns:
Value |
When |
|---|---|
|
In the frame the user picks the |
|
In the frame the user picks Cancel or presses |
|
In every other frame, open or closed |
It closes itself when the user answers, so check the result in the same frame.
A confirmation with a formatted question.#
Select#
ui_select is a field that opens a menu of its options with [enter]. See widgets.
Toast#
ui_toast("The download finished.");
ui_toast(ui_fmt("Welcome, %s.", name));
A short note centered above the softkey bar for UI_TOAST_MS (2000 ms). It takes no focus and no keys, and the
program goes on while it shows. The text is copied, up to 47 characters. A new toast replaces the one showing. Call
it once, in the frame the event happens, not every frame.
A toast after creating an account.#
Dimming#
While a modal or menu is open, the screen below and every overlay below the top one are drawn with each color slot
replaced by its dimmed slot from the theme’s ui_dimmed table. No pixels are read back or blended; it is the same
command stream drawn with other palette entries. Sprites and canvases are not dimmed and keep their colors.
A modal over the dimmed gallery.#