Skip to main content

Module menu

Module menu 

Source
Expand description

A vertical list menu: a title screen’s, an action menu, a list of replies.

The menu holds its items and its focus (a ListCursor). What it shows is Menu::view, plain data, and glyph::paint draws that view as glyphs: the screens’ own skins call it for their menu.

Each item stands for a value of the game’s type, which the menu gives back when it is chosen, so a screen needs no list beside the menu to know what was picked. Its label is a Label: a text key the skin puts in the player’s language when it paints, or text as it is, so a menu is built once, by logic that doesn’t know the language.

use shuyi_assets::keymap::sample::Action;
use shuyi_ui::widgets::{Menu, MenuEvent, MenuItem};

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum Seed {
    Turnip,
    Melon,
}

let mut seeds = Menu::new(vec![
    MenuItem::keyed("seed.turnip").with_value(Seed::Turnip),
    MenuItem::keyed("seed.melon").with_value(Seed::Melon),
]);
seeds.handle(Action::CursorDown);
assert_eq!(
    seeds.handle(Action::Confirm),
    Some(MenuEvent::Chosen(Seed::Melon))
);

Re-exports§

pub use view::MenuItemView;
pub use view::MenuView;
pub use view::SuffixKind;
pub use crate::text::Label;

Modules§

glyph
The glyph look of a Menu: paints a MenuView as a single-line box of text rows with the focused one as a bar and, when its items have notes, the focused item’s note under a rule. A menu that scrolls shows its window, with a mark on the border where more items are out of the box. Everything about the look lives here; nothing here decides what the menu shows. Another look is another paint of the same view (game ADR-0054).
view
What a Menu shows, as plain data: its items with their labels and which one is focused, no cells or positions. A screen puts the MenuView in its own view and its skin paints it (super::glyph::paint today; game ADR-0054).

Structs§

Menu
A vertical list of items in a single-line box. CursorDown/CursorUp move the focus (wrapping, skipping disabled items), Confirm chooses the focused item, Cancel cancels (unless the menu is without_cancel). A menu showing fewer rows than it has scrolls.
MenuItem
One menu entry, standing for a value of the game’s type (() for a menu whose screen only needs to know an item was chosen).

Enums§

MenuEvent
What a menu reports back to its screen.