pub struct MenuState { /* private fields */ }Expand description
State for a Menu component.
Implementations§
Source§impl MenuState
impl MenuState
Sourcepub fn new(items: Vec<MenuItem>) -> Self
pub fn new(items: Vec<MenuItem>) -> Self
Creates a new menu with the given items.
§Example
use envision::component::{MenuState, MenuItem};
let state = MenuState::new(vec![
MenuItem::new("File"),
MenuItem::new("Edit"),
]);
assert_eq!(state.items().len(), 2);Sourcepub fn set_items(&mut self, items: Vec<MenuItem>)
pub fn set_items(&mut self, items: Vec<MenuItem>)
Sets the menu items.
Resets selection to 0 if the current selection is out of bounds.
Sourcepub fn selected_index(&self) -> usize
pub fn selected_index(&self) -> usize
Returns the currently selected item index.
Sourcepub fn set_selected_index(&mut self, index: usize)
pub fn set_selected_index(&mut self, index: usize)
Sets the selected item index.
If the index is out of bounds, it will be clamped to the valid range.
Sourcepub fn selected_item(&self) -> Option<&MenuItem>
pub fn selected_item(&self) -> Option<&MenuItem>
Returns the currently selected item.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MenuState
impl RefUnwindSafe for MenuState
impl Send for MenuState
impl Sync for MenuState
impl Unpin for MenuState
impl UnwindSafe for MenuState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more