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.

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 with one OK button

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

UI_YES

In the frame the user picks the yes button

UI_NO

In the frame the user picks Cancel or presses [clear]

UI_PENDING

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 Cancel and Delete buttons

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 that says Welcome above the softkey bar

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

A modal over the dimmed gallery.#