Struct 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§

Source§

impl<T: Copy> MenuInstance<T>

Source

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.

Source

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().

Source

pub fn menu(&self) -> &Menu<T>

Returns a reference to the internal menu

Source

pub fn into_menu(self) -> Menu<T>

Consumes the instance, returning its menu

Source

pub fn index(&self) -> usize

Returns the current index

Source

pub fn set_index(&mut self, index: usize)

Sets the index, if the specified index < menu.entries.len()

Source

pub fn up(&mut self)

Select the entry above the current selection, unless the first entry is currently selected.

Source

pub fn down(&mut self)

Select the entry below the current selection, unless the last entry is currently selected.

Source

pub fn selected(&self) -> T

Returns a copy of the currently selected entry’s value.

Source

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.

Source

pub fn tick_with_mouse<'a, I, M>( &mut self, inputs: I, view: &'a M, ) -> Option<MenuOutput<T>>

Trait Implementations§

Source§

impl<T: Clone + Copy> Clone for MenuInstance<T>

Source§

fn clone(&self) -> MenuInstance<T>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Copy> Debug for MenuInstance<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Copy> View<MenuInstance<T>> for DefaultMenuInstanceView

Source§

fn view<G: ViewGrid>( &mut self, value: &MenuInstance<T>, offset: Coord, depth: i32, grid: &mut G, )

Update the cells in grid to describe how a type should be rendered. This mutably borrows self to allow the view to contain buffers/caches which are updated during rendering.
Source§

impl<T: Copy> ViewSize<MenuInstance<T>> for DefaultMenuInstanceView

Source§

fn size(&mut self, data: &MenuInstance<T>) -> Size

Returns the size in cells of the rectangle containing a ui element. This allows for the implementation of decorator ui components that render a border around some inner element.

Auto Trait Implementations§

§

impl<T> Freeze for MenuInstance<T>

§

impl<T> RefUnwindSafe for MenuInstance<T>
where T: RefUnwindSafe,

§

impl<T> Send for MenuInstance<T>
where T: Send,

§

impl<T> Sync for MenuInstance<T>
where T: Sync,

§

impl<T> Unpin for MenuInstance<T>
where T: Unpin,

§

impl<T> UnwindSafe for MenuInstance<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.