pub struct MaterialMenu<'a> { /* private fields */ }Expand description
Material Design menu component.
Menus display a list of choices on a temporary surface. They appear when users interact with a button, action, or other control.
§Example
let mut menu_open = false;
if ui.button("Open Menu").clicked() {
menu_open = true;
}
let mut menu = MaterialMenu::new(&mut menu_open)
.item("Cut", Some(|| println!("Cut")))
.item("Copy", Some(|| println!("Copy")))
.item("Paste", Some(|| println!("Paste")));
if menu_open {
ui.add(menu);
}Implementations§
Source§impl<'a> MaterialMenu<'a>
impl<'a> MaterialMenu<'a>
Sourcepub fn anchor_rect(self, rect: Rect) -> Self
pub fn anchor_rect(self, rect: Rect) -> Self
Set the anchor rectangle for the menu.
The menu will be positioned relative to this rectangle.
§Arguments
rect- The rectangle to anchor the menu to
§Example
let mut menu_open = false;
let button_rect = ui.available_rect_before_wrap();
let menu = MaterialMenu::new("menu", &mut menu_open)
.anchor_rect(button_rect);Sourcepub fn style(self, style: MenuStyle) -> Self
pub fn style(self, style: MenuStyle) -> Self
Set the menu style, overriding Material Design 3 defaults.
§Arguments
style- TheMenuStyleto apply
Set the button theme, overriding Material Design 3 defaults.
§Arguments
theme- TheMenuButtonThemeDatato apply
Sourcepub fn elevation(self, elevation: f32) -> Self
pub fn elevation(self, elevation: f32) -> Self
Set the elevation (shadow) of the menu.
This is a shorthand for setting MenuStyle.elevation.
Material Design defines typical elevation levels from 0 to 12.
§Arguments
elevation- Elevation level
Sourcepub fn anchor_corner(self, corner: Corner) -> Self
pub fn anchor_corner(self, corner: Corner) -> Self
Set the anchor corner for the menu.
Set the menu corner for positioning.
Sourcepub fn default_focus(self, focus: FocusState) -> Self
pub fn default_focus(self, focus: FocusState) -> Self
Set the default focus state for the menu.
Sourcepub fn positioning(self, positioning: Positioning) -> Self
pub fn positioning(self, positioning: Positioning) -> Self
Set the positioning mode for the menu.
Sourcepub fn has_overflow(self, has_overflow: bool) -> Self
pub fn has_overflow(self, has_overflow: bool) -> Self
Enable or disable overflow scrolling for the menu.
Sourcepub fn stay_open_on_outside_click(self, stay_open: bool) -> Self
pub fn stay_open_on_outside_click(self, stay_open: bool) -> Self
Keep the menu open when clicking outside of it.
Sourcepub fn stay_open_on_focusout(self, stay_open: bool) -> Self
pub fn stay_open_on_focusout(self, stay_open: bool) -> Self
Keep the menu open when focus moves away from it.
Sourcepub fn skip_restore_focus(self, skip: bool) -> Self
pub fn skip_restore_focus(self, skip: bool) -> Self
Skip restoring focus when the menu closes.
Sourcepub fn no_horizontal_flip(self, no_flip: bool) -> Self
pub fn no_horizontal_flip(self, no_flip: bool) -> Self
Prevent horizontal flipping when the menu would go offscreen.
Sourcepub fn no_vertical_flip(self, no_flip: bool) -> Self
pub fn no_vertical_flip(self, no_flip: bool) -> Self
Prevent vertical flipping when the menu would go offscreen.
Sourcepub fn typeahead_delay(self, delay: f32) -> Self
pub fn typeahead_delay(self, delay: f32) -> Self
Set the typeahead delay for the menu.
Sourcepub fn list_tab_index(self, index: i32) -> Self
pub fn list_tab_index(self, index: i32) -> Self
Set the tab index for keyboard navigation.
Auto Trait Implementations§
impl<'a> Freeze for MaterialMenu<'a>
impl<'a> !RefUnwindSafe for MaterialMenu<'a>
impl<'a> !Send for MaterialMenu<'a>
impl<'a> !Sync for MaterialMenu<'a>
impl<'a> Unpin for MaterialMenu<'a>
impl<'a> UnsafeUnpin for MaterialMenu<'a>
impl<'a> !UnwindSafe for MaterialMenu<'a>
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.