Menu
Overlays · interactive
The rows inside a popover.
Import
cpp
#include "gbui/widgets/menu.hpp"Example
MenuItem
menuItem · Overlays · interactive
Nothing is downloaded until you press it.
cpp
bool menuItem(Ui& ui, const Interaction& input, std::string_view id, std::string_view label, const MenuItemOptions& options = {});Returns true on the frame it was chosen.
MenuSeparator
menuSeparator · Overlays
Nothing is downloaded until you press it.
cpp
void menuSeparator(Ui& ui);A rule between groups of items.
API
MenuItemOptions
| Option | Type | Default | What it does |
|---|---|---|---|
leading optional | std::optional<Icon> | ||
shortcut | std::string_view | Drawn right-aligned in the mono face, and drawn only: the row does not bind it. A menu is where a shortcut is advertised; the application is where it is handled. | |
selected | bool | false | The chosen value: a check mark and the strong text colour. |
checkSide | CheckSideLeading · Trailing | CheckSide::Leading | Where that check mark goes. Leading suits a menu, trailing a select. |
highlighted | bool | false | Drawn as though the pointer were on it. That is what walking a list with the arrow keys looks like — the highlight moves and the pointer does not — and it is a different question from selected, which is the value the list would return. |
disabled | bool | false | |
danger | bool | false | The destructive one, in the error colour — which is the only warning a reader gets before pressing it. |
focusable | bool | true | Whether Tab can land on it. A list whose owner drives the highlight — a select — turns this off, so Tab leaves the control instead of walking into an open popup and back out of the window's order. |
role | Role | Role::MenuItem | What a reader is told this row is. The same distinction checkSide draws visually, and it has to be said separately because a screen reader announces the two differently: a menu holds commands — "New branch, menu item" — and a select holds values, where the reader also wants "option, three of twelve". A command that toggles is MenuItemCheckbox, which is what makes selected announce "not checked" instead of saying nothing. |
positionInSet | std::size_t | 0 | Its place in the list, one-based, and how long the list is. Zero on both is "not one of a set", which is right for a menu: a reader walking commands does not want them counted. A select sets them, and a filtered select sets them from what is shown — "3 of 40" in a list narrowed to four is three lies in five words. |
setSize | std::size_t | 0 |