pub struct Menu<T = ()> { /* private fields */ }Expand description
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.
Implementations§
Source§impl<T> Menu<T>
impl<T> Menu<T>
Sourcepub const ACTIONS: &'static [UiAction]
pub const ACTIONS: &'static [UiAction]
What a menu reacts to (handle), for the screen
that shows it to declare (Screen::actions).
Sourcepub fn new(items: Vec<MenuItem<T>>) -> Self
pub fn new(items: Vec<MenuItem<T>>) -> Self
A menu focused on its first enabled item (or the first item, if none is enabled).
Sourcepub fn without_cancel(self) -> Self
pub fn without_cancel(self) -> Self
The same menu where Cancel does nothing (and so plays nothing):
for menus with nothing to back out of.
Sourcepub fn browsing_disabled(self) -> Self
pub fn browsing_disabled(self) -> Self
The same menu where the focus also stops on disabled items, so the player can read what they do. Confirm on one still chooses nothing.
Sourcepub fn showing(self, rows: usize, scroll: Scroll) -> Self
pub fn showing(self, rows: usize, scroll: Scroll) -> Self
The same menu showing at most rows rows: a longer one scrolls,
its window following the focus by scroll.
Sourcepub fn focused(self, index: usize) -> Self
pub fn focused(self, index: usize) -> Self
The same menu focused on item index, if it exists and the focus
may stop on it (it is enabled, or the menu is
browsing_disabled).
Sourcepub fn handle<A: ActionSet>(&mut self, action: A) -> Option<MenuEvent<T>>where
T: Clone,
pub fn handle<A: ActionSet>(&mut self, action: A) -> Option<MenuEvent<T>>where
T: Clone,
Handles one action, by what the game takes it for.
Returns an event for UiAction::Confirm on an enabled item (with
a copy of its value) and for UiAction::Cancel; moves the focus
for UiAction::Down and UiAction::Up; ignores everything else.