pub enum MenuItem {
}
appkit
only.Expand description
Represents varying NSMenuItem
types - e.g, a separator vs an action. If you need something
outside of the stock item types, you can create a Custom
variant that supports dispatching a
callback on the Rust side of things.
Variants
Custom(Id<Object>)
A custom MenuItem. This type functions as a builder, so you can customize it easier.
You can (and should) create this variant via the new(title)
method, but if you need to do
something crazier, then wrap it in this and you can hook into the Cacao menu system
accordingly.
About(String)
Shows a standard “About” item, which will bring up the necessary window when clicked
(include a credits.html
in your App to make use of here). The argument baked in here
should be your app name.
Hide
A standard “hide the app” menu item.
Services
A standard “Services” menu item.
HideOthers
A “hide all other windows” menu item.
ShowAll
A menu item to show all the windows for this app.
CloseWindow
Close the current window.
Quit
A “quit this app” menu icon.
Copy
A menu item for enabling copying (often text) from responders.
Cut
A menu item for enabling cutting (often text) from responders.
Undo
An “undo” menu item; particularly useful for supporting the cut/copy/paste/undo lifecycle of events.
Redo
An “redo” menu item; particularly useful for supporting the cut/copy/paste/undo lifecycle of events.
SelectAll
A menu item for selecting all (often text) from responders.
Paste
A menu item for pasting (often text) into responders.
EnterFullScreen
A standard “enter full screen” item.
Minimize
An item for minimizing the window with the standard system controls.
Zoom
An item for instructing the app to zoom. Your app must react to this with necessary window lifecycle events.
ToggleSidebar
An item for automatically telling a SplitViewController to hide or show the sidebar. This only works on macOS 11.0+.
Separator
Represents a Separator. It’s useful nonetheless for
separating out pieces of the NSMenu
structure.
Implementations
sourceimpl MenuItem
impl MenuItem
sourcepub fn new<S: AsRef<str>>(title: S) -> Self
pub fn new<S: AsRef<str>>(title: S) -> Self
Returns a Custom
menu item, with the given title. You can configure this further with the
builder methods on this object.
sourcepub fn key(self, key: &str) -> Self
pub fn key(self, key: &str) -> Self
Configures the a custom item to have specified key equivalent. This does nothing if called
on a MenuItem
type that is not Custom
,
sourcepub fn modifiers(self, modifiers: &[EventModifierFlag]) -> Self
pub fn modifiers(self, modifiers: &[EventModifierFlag]) -> Self
Sets the modifier key flags for this menu item. This does nothing if called on a MenuItem
that is not Custom
.
sourcepub fn action<F: Fn() + 'static>(self, action: F) -> Self
pub fn action<F: Fn() + 'static>(self, action: F) -> Self
Attaches a target/action handler to dispatch events. This does nothing if called on a
MenuItem
that is not Custom
.
Note that we use an extra bit of unsafety here to pass over a heap’d block. We need to do this as some menu items live in odd places (the system menu bar), and we need the handlers to persist. We inject a custom dealloc method to pull the pointer back and drop the handler whenever the menu item goes kaput.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for MenuItem
impl Send for MenuItem
impl Sync for MenuItem
impl Unpin for MenuItem
impl UnwindSafe for MenuItem
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more