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 aMenuViewas 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 anotherpaintof the same view (game ADR-0054). - view
- What a
Menushows, as plain data: its items with their labels and which one is focused, no cells or positions. A screen puts theMenuViewin its own view and its skin paints it (super::glyph::painttoday; game ADR-0054).
Structs§
- Menu
- A vertical list of items in a single-line box.
CursorDown/CursorUpmove the focus (wrapping, skipping disabled items),Confirmchooses the focused item,Cancelcancels (unless the menu iswithout_cancel). A menushowingfewer rows than it has scrolls. - Menu
Item - One menu entry, standing for a
valueof the game’s type (()for a menu whose screen only needs to know an item was chosen).
Enums§
- Menu
Event - What a menu reports back to its screen.