ui_controls

module ui_controlssource

The controls of pkg::alloy::ui (REFOCUS.md, R6e, question 9A): widgets on the core's layers, what an app's menus, choices and notices and a game's pause screens want, with nothing of the app services.

import pkg::alloy::ui;
import pkg::alloy::ui_controls;

fn saving(ui: &var Ui) -> Element {
    return ui.add(Button::primary(&"Save", (ui) => ui.toast(Toast { .text = String::from(&"Saved") })));
}

Each keeps its state as an extension of the Ui (Extension), installed as it is first used, so a program not using one carries none of its code.

## How it was built

**R6e as built** (2026-10-26): moved out of ui, whose notes of F11a, F11b, F11c, F11e and F12c tell how each was first built, with their notes here: choices.alloy (Select, ChoiceList, Radios, Tabs), menus.alloy (ui.menu, MenuButton), tooltips.alloy, toasts.alloy, progress.alloy (Spinner, ProgressBar). Hooks became extensions: Menus (the pointer onto an item, Tab in a menu), Tips (the pointer and the focus), Toasts (their state, ticked as each update begins, their texts given a replay). The layer mechanism they stand on (ui.open, Overlay, Place, Popup) stays in the core.

**F11a as built** (2026-10-15; decisions/F11.md, "Layers"), the part ui_controls holds since R6e:

**F11b as built** (2026-10-15; decisions/F11.md, "Choices", questions 3A, 4A, 15A and 16A):

**F11c as built** (2026-10-15; decisions/F11.md, "Screens", questions 5A and 6B), the part ui_controls holds since R6e:

type Choicesource

exp type Choice<T: Equal> = struct

A value to choose, with its label.

Fields

exp label: String
exp value: T
exp enabled: bool = true

Functions

fn Choice::ofsource

exp fn Choice::of(label: &[u8], value: T) -> Choice<T>

type Selectsource

exp type Select<T: Equal> : Widget + Popup = struct

A field showing the chosen label (or the placeholder) and a chevron, as wide as its longest choice unless sized. A press, Space, Enter, Alt+Down, Up or Down opens its list below it (above without room), the chosen item highlighted; there Up, Down, Home, End, Page Up and Page Down move, Enter, Space or a click choose and close, a drag from the press and a release choose, Escape closes, Tab chooses and moves on. Typed characters move to the next item starting with them, forgotten after a second, the same letter again going through those starting with it; closed, that item is chosen at once. To a screen reader a combo box, its list a list box of options.

Fields

exp choices: Vector<Choice<T>>
exp selected: Option<T> = ::None

None shows the placeholder

exp placeholder: String = String::empty()
exp accessible: String = String::empty()
exp on_change: |=| (&var Ui, T) = (ui, value) {}
exp enabled: bool = true
exp error: String = String::empty()

what is wrong with the choice, none when empty: a border in the theme's danger color, and to screen readers invalid, the message its description; required a form needs one chosen

exp required: bool = false
exp sizing: Sizing = Sizing {}
exp open: Option<Layer> = ::None

its own state: the list it opened

exp laid: Option<*text::Layout> = ::None

the chosen label or the placeholder

Functions

type ChoiceListsource

exp type ChoiceList<T: Equal> : Widget = struct

The choices in a list, one chosen: a list box on its own, Up and Down choosing the next, Home, End, Page Up and Page Down further, a click or typed characters as a Select's; as tall as its choices unless sized, scrolling when not. A Select opens one.

Fields

exp choices: Vector<Choice<T>>
exp selected: Option<T> = ::None
exp accessible: String = String::empty()
exp on_change: |=| (&var Ui, T) = (ui, value) {}
exp enabled: bool = true
exp error: String = String::empty()

as a Select's

exp required: bool = false
exp sizing: Sizing = Sizing {}

Functions

type Radiossource

exp type Radios<T: Equal> : Widget = struct

A circle and a label for each choice, the chosen one's filled: one element and one Tab stop, on the chosen radio or the first; Up, Down, Left and Right choose the next enabled one, Space the focused one, a click the one under it. To a screen reader a radio group.

Fields

exp choices: Vector<Choice<T>>
exp selected: Option<T> = ::None
exp accessible: String = String::empty()

the group's label

exp on_change: |=| (&var Ui, T) = (ui, value) {}
exp horizontal: bool = false

side by side rather than one under the other

exp gap: f32 = 8.0
exp enabled: bool = true
exp error: String = String::empty()

what is wrong with the choice, none when empty: the circles in the theme's danger color, and to screen readers invalid, the message its description; required a form needs one chosen

exp required: bool = false
exp sizing: Sizing = Sizing {}

Functions

type Tabssource

exp type Tabs<T: Equal> : Widget = struct

A row of tabs, the selected one underlined in the primary color: one element and one Tab stop, Left and Right selecting the next enabled tab, Home and End the first and last, a click the one under it. What a tab shows is the program's, beside it (ui.switch). To a screen reader a tab list of tabs.

Fields

exp tabs: Vector<Choice<T>>
exp selected: T
exp accessible: String = String::empty()

the tab list's label

exp on_change: |=| (&var Ui, T) = (ui, value) {}
exp enabled: bool = true
exp sizing: Sizing = Sizing {}

Functions

type Toastsource

exp type Toast = struct

What a toast says, and how.

Fields

exp text: String
exp action: Option<ToastAction> = ::None
exp kind: ToastKind = ToastKind::Info
exp duration: Duration = Duration::from_seconds(5.0)

type ToastActionsource

exp type ToastAction = struct

A toast's button: the toast closes after its function runs.

Fields

exp label: String
exp on_press: |=| (&var Ui)

Functions

fn ToastAction::ofsource

exp fn ToastAction::of(label: &[u8], on_press: |=| (&var Ui)) -> ToastAction

type ToastKindsource

exp type ToastKind = enum

Variants

Info
Success
Error

stays until closed

fn toastsource

exp fn toast(self ui: &var Ui, toast: Toast)

Tells the user something happened, without taking the focus: in the window's bottom end corner, gone after its duration, its time paused while the pointer is over it or the focus in it; spoken by screen readers, an error at once.

type Spinnersource

exp type Spinner : Widget = struct

A looping sign of work under way: dots round a circle, the brightest going round once a second; under reduced motion they pulse together, slowly. To a screen reader its label, "Loading".

Fields

exp size: f32 = 24.0
exp color: Ink = Ink::Primary
exp accessible: String = String::empty()
exp sizing: Sizing = Sizing {}

Functions

type ProgressBarsource

exp type ProgressBar : Widget = struct

How much of a piece of work is done: a track filling from its start to value, from 0 to 1, or, while that is not known (None), a stretch going across it once a second, pulsing under reduced motion. To a screen reader a progress bar, its label accessible, its value in percent.

Fields

exp value: Option<f32> = ::None
exp accessible: String = String::empty()
exp color: Ink = Ink::Primary
exp width: f32 = 200.0
exp height: f32 = 6.0
exp sizing: Sizing = Sizing {}

Functions

type Tooltipsource

exp type Tooltip : Widget = struct

Text shown over the element it holds when the pointer rests on it or the keyboard's focus comes to it.

Fields

exp text: String
exp children: &[Element] = &[]
exp sizing: Sizing = Sizing {}

Functions