pub struct Menu<T> { /* private fields */ }
Expand description
A menu.
Menus can be nested arbitrarily, so this could also be a submenu. See the module level documentation for more on how to use menus.
Implementations§
§impl<T> Menu<T>where
T: Data,
impl<T> Menu<T>where T: Data,
pub fn enabled_if(
self,
enabled: impl FnMut(&T, &Env) -> bool + 'static
) -> Menu<T>
pub fn enabled_if( self, enabled: impl FnMut(&T, &Env) -> bool + 'static ) -> Menu<T>
Provide a callback for determining whether this item should be enabled.
Whenever the callback returns true
, the menu will be enabled.
pub fn entry(self, entry: impl Into<MenuEntry<T>>) -> Menu<T>
pub fn entry(self, entry: impl Into<MenuEntry<T>>) -> Menu<T>
Append a menu entry to this menu, returning the modified menu.
pub fn refresh_on(
self,
refresh: impl FnMut(&T, &T, &Env) -> bool + 'static
) -> Menu<T>
pub fn refresh_on( self, refresh: impl FnMut(&T, &T, &Env) -> bool + 'static ) -> Menu<T>
Supply a function to check when this menu needs to refresh itself.
The arguments to the callback are (in order):
- the previous value of the data,
- the current value of the data, and
- the current value of the environment.
The callback should return true if the menu needs to refresh itself.
This callback is intended to be purely an optimization. If you do create a menu without supplying a refresh callback, the menu will recursively check whether any children have changed and refresh itself if any have. By supplying a callback here, you can short-circuit those recursive calls.
pub fn rebuild_on(
self,
rebuild: impl FnMut(&T, &T, &Env) -> bool + 'static
) -> Menu<T>
pub fn rebuild_on( self, rebuild: impl FnMut(&T, &T, &Env) -> bool + 'static ) -> Menu<T>
Supply a function to check when this menu needs to be rebuild from scratch.
The arguments to the callback are (in order):
- the previous value of the data,
- the current value of the data, and
- the current value of the environment.
The callback should return true if the menu needs to be rebuilt.
The difference between rebuilding and refreshing (as in refresh_on
) is
that rebuilding creates the menu from scratch using the original menu-building callback,
whereas refreshing involves tweaking the existing menu entries (e.g. enabling or disabling
items).
If you do not provide a callback using this method, the menu will never get rebuilt. Also, only window and application menus get rebuilt; context menus never do.