Skip to main content

Module ui

Module ui 

Source
Expand description

Virtual, speech based user interface. Available as ctx.ui.

Nothing here is drawn on screen. Every widget announces itself through Speech and plays short interface sounds, and reacts to the keyboard directly. While any widget is open it owns the keyboard: game input is blocked (see Input::is_blocked).

Widgets form a stack. The top one receives input; closing it returns to the one below, which re-announces itself. This makes sub menus trivial.

ctx.ui.open(
    Menu::new("main", "Main menu")
        .button("play", "Play")
        .slider("volume", "Volume", 80.0, 0.0, 100.0, 10.0)
        .checkbox("music", "Music", true)
        .button("quit", "Quit"),
);
// ...later, in update():
if ctx.ui.clicked("main", "play") {
    ctx.ui.close();
}
if let Some(volume) = ctx.ui.changed("main", "volume") {
    ctx.audio.set_master_volume(volume.as_f32() / 100.0);
}

Built in widgets: Menu, Message, Confirm and TextInput. You can write your own by implementing Widget.

Structs§

Confirm
A yes/no question. Arrows switch the answer, Enter confirms, Escape answers no. The first letters of the answers work as shortcuts.
Menu
A vertical list of items navigated with the arrow keys.
MenuItem
One entry of a Menu.
Message
A message the player reads and dismisses with Enter, Space or Escape. Up/Down/Home/End review the text line by line.
TextInput
A single line text field.
Ui
The widget stack. Reach it through ctx.ui.
UiContext
Everything a widget may use while it updates.
UiSounds
Which sound to play for each UiSound. Each entry is a sound name as accepted by Audio::play; None means silence.

Enums§

ItemKind
What kind of item a MenuItem is.
Status
What a widget wants to happen after its update.
UiEvent
Something that happened in the UI this frame.
UiSound
The moments at which widgets play a sound.
Value
A value carried by a UI event or stored in a menu item.

Traits§

Widget
A virtual UI element. Implement this to create your own widgets.