Struct prototty_common::MenuInstance
source · pub struct MenuInstance<T: Copy> { /* private fields */ }
Expand description
An instance of a menu, with a selected entry.
When a MenuInstance
is rendered, the
currently-selected entry is rendered using
the Menu
’s selected_info
.
Implementations
sourceimpl<T: Copy> MenuInstance<T>
impl<T: Copy> MenuInstance<T>
sourcepub fn new(menu: Menu<T>) -> Option<Self>
pub fn new(menu: Menu<T>) -> Option<Self>
Create a new MenuInstance
with the first entry selected.
Returns None
if the Menu
has 0 elements.
sourcepub fn with_index(menu: Menu<T>, index: usize) -> Option<Self>
pub fn with_index(menu: Menu<T>, index: usize) -> Option<Self>
Create a new MenuInstance
with the given index selected.
Returns None
if index >= menu.entries.len()
.
Returns a reference to the internal menu
Consumes the instance, returning its menu
sourcepub fn set_index(&mut self, index: usize)
pub fn set_index(&mut self, index: usize)
Sets the index, if the specified index < menu.entries.len()
sourcepub fn up(&mut self)
pub fn up(&mut self)
Select the entry above the current selection, unless the first entry is currently selected.
sourcepub fn down(&mut self)
pub fn down(&mut self)
Select the entry below the current selection, unless the last entry is currently selected.
sourcepub fn tick<I>(&mut self, inputs: I) -> Option<MenuOutput<T>>where
I: IntoIterator<Item = Input>,
pub fn tick<I>(&mut self, inputs: I) -> Option<MenuOutput<T>>where
I: IntoIterator<Item = Input>,
Feed input into the menu instance, possibly changing the selected entry, cancelling the menu, attempting to exit the program, or finalising the selection.
pub fn tick_with_mouse<'a, I, M>(
&mut self,
inputs: I,
view: &'a M
) -> Option<MenuOutput<T>>where
I: IntoIterator<Item = Input>,
M: MenuIndexFromScreenCoord,
Trait Implementations
sourceimpl<T: Clone + Copy> Clone for MenuInstance<T>
impl<T: Clone + Copy> Clone for MenuInstance<T>
sourcefn clone(&self) -> MenuInstance<T>
fn clone(&self) -> MenuInstance<T>
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more