Skip to main content

MaterialMenu

Struct MaterialMenu 

Source
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>

Source

pub fn new(id: impl Into<Id>, open: &'a mut bool) -> Self

Create a new MaterialMenu instance.

§Arguments
  • id - Unique identifier for this menu
  • open - Mutable reference to the menu’s open state
§Example
let mut menu_open = false;
let menu = MaterialMenu::new("main_menu", &mut menu_open);
Source

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);
Source

pub fn item(self, item: MenuItem<'a>) -> Self

Add an item to the menu.

§Arguments
  • item - The menu item to add
§Example
let mut menu_open = false;
let item = MenuItem::new("Cut").action(|| println!("Cut"));
let menu = MaterialMenu::new("menu", &mut menu_open).item(item);
Source

pub fn style(self, style: MenuStyle) -> Self

Set the menu style, overriding Material Design 3 defaults.

§Arguments
  • style - The MenuStyle to apply
Source

pub fn button_theme(self, theme: MenuButtonThemeData) -> Self

Set the button theme, overriding Material Design 3 defaults.

§Arguments
  • theme - The MenuButtonThemeData to apply
Source

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
Source

pub fn anchor_corner(self, corner: Corner) -> Self

Set the anchor corner for the menu.

Source

pub fn menu_corner(self, corner: Corner) -> Self

Set the menu corner for positioning.

Source

pub fn default_focus(self, focus: FocusState) -> Self

Set the default focus state for the menu.

Source

pub fn positioning(self, positioning: Positioning) -> Self

Set the positioning mode for the menu.

Source

pub fn quick(self, quick: bool) -> Self

Enable or disable quick animation for the menu.

Source

pub fn has_overflow(self, has_overflow: bool) -> Self

Enable or disable overflow scrolling for the menu.

Source

pub fn stay_open_on_outside_click(self, stay_open: bool) -> Self

Keep the menu open when clicking outside of it.

Source

pub fn stay_open_on_focusout(self, stay_open: bool) -> Self

Keep the menu open when focus moves away from it.

Source

pub fn skip_restore_focus(self, skip: bool) -> Self

Skip restoring focus when the menu closes.

Source

pub fn x_offset(self, offset: f32) -> Self

Set the horizontal offset for the menu.

Source

pub fn y_offset(self, offset: f32) -> Self

Set the vertical offset for the menu.

Source

pub fn no_horizontal_flip(self, no_flip: bool) -> Self

Prevent horizontal flipping when the menu would go offscreen.

Source

pub fn no_vertical_flip(self, no_flip: bool) -> Self

Prevent vertical flipping when the menu would go offscreen.

Source

pub fn typeahead_delay(self, delay: f32) -> Self

Set the typeahead delay for the menu.

Source

pub fn list_tab_index(self, index: i32) -> Self

Set the tab index for keyboard navigation.

Source

pub fn show(self, ctx: &Context)

Show the menu in the given context.

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> 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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more