Overlays#

Declared in ui.h. See overlays for layers, dimming and examples.

Modals and menus open a layer each, up to UI_LAYERS (4). Only the top layer takes focus and keys, and everything below it is drawn dimmed. Overlays record into the overlay stream, so they are drawn on top wherever in the frame they are called.

Answers#

enum { UI_PENDING = -1, UI_NO, UI_YES };

The values ui_confirm returns: UI_PENDING (-1) while there is no answer, UI_NO (0) and UI_YES (1).

ui_modal_begin#

bool ui_modal_begin(bool *open, const char *title);

Opens a modal when *open is true: a panel ui_metrics.modal pixels wide in ui_style_modal, centered on the screen, as high as its content, with the title as a heading. Widgets until ui_modal_end go inside it. [clear] sets *open to false.

Parameter

Meaning

open

Whether the modal is open. Its address is also the modal’s id

title

A heading at the top, or NULL

Returns true when the modal is open and its content should be placed, false otherwise. Call ui_modal_end only when it returned true.

ui_modal_end#

void ui_modal_end(void);

Ends the modal started last, sets its height, and handles [clear] for it. It does nothing when the current container is not a modal.

ui_message#

void ui_message(bool *open, const char *title, const char *text);

A modal with a title, wrapped text and an OK button. OK and [clear] set *open to false. Does nothing when *open is false.

Parameter

Meaning

open

Whether the message is shown

title

A heading, or NULL

text

The message, or NULL. Read every frame while open

ui_confirm#

int ui_confirm(bool *open, const char *title, const char *text, const char *yes);

A modal with a title, wrapped text and two buttons, Cancel and yes. It closes itself when the user answers.

Parameter

Meaning

open

Whether the question is shown

title

A heading, or NULL

text

The question, or NULL

yes

The label of the button that confirms, such as “Delete”

Returns UI_YES in the frame the yes button is picked, UI_NO in the frame Cancel is picked or [clear] is pressed, and UI_PENDING in every other frame.

ui_menu#

int ui_menu(bool *open, const char *const *items, uint8_t count);

Opens a menu in ui_style_menu with one item per entry, in ui_style_menu_item, when *open is true. It opens right below the widget that had focus when it opened (for a list, the selected row), above it when there is no room below, and is kept on the screen. It is as wide as the longest item. Picking an item or pressing [clear] sets *open to false.

Parameter

Meaning

open

Whether the menu is open

items

count item labels. Their address is also the menu’s id

count

Number of items

Returns the index of the item picked in this frame, or -1.

ui_toast#

void ui_toast(const char *text);

Shows text in ui_style_toast, centered just above the softkey bar, for UI_TOAST_MS (2000 ms). The text is copied, up to UI_TOAST_SIZE - 1 (47) characters. A new toast replaces the one showing. It takes no focus and no keys, and CEUI wakes up by itself to remove it. Call it once, when the event happens.