pub struct MenuModel { /* private fields */ }Expand description
A declarative menu tree shared by the in-window MenuBar
and the native OS menu bar. Cloneable by handle (Rc inside); a clone shares
the same nodes and version signal, so mutating one updates every view.
Implementations§
Source§impl MenuModel
impl MenuModel
Append a top-level menu with the given title and contents (auto id).
Sourcepub fn standard(self, role: StandardMenuRole) -> Self
pub fn standard(self, role: StandardMenuRole) -> Self
Append a platform-standard top-level menu (macOS App / Window / Help)
with default (English) labels. Use standard_menu
to supply localized labels.
Append a platform-standard top-level menu with localized labels.
Sourcepub fn version(&self) -> Signal<u64>
pub fn version(&self) -> Signal<u64>
A Signal<u64> bumped whenever the tree’s structure changes. The
native bridge re-installs the menu on a bump; per-item state changes go
through the finer-grained update_item path instead.
Sourcepub fn modify(&self, f: impl FnOnce(&mut Vec<MenuNode>))
pub fn modify(&self, f: impl FnOnce(&mut Vec<MenuNode>))
Mutate the node tree directly, then bump version. The escape hatch for
any structural change the typed helpers don’t cover (reorder, retitle,
bulk edits). MenuNode / MenuEntry are public, so the closure can
build whatever it needs.
Append a top-level menu at runtime, returning its id. Mirrors
menu but takes &self.
Sourcepub fn push_item(&self, into: MenuItemId, entry: MenuEntry) -> bool
pub fn push_item(&self, into: MenuItemId, entry: MenuEntry) -> bool
Append entry to the submenu identified by into (a top-level menu or
nested submenu id). Returns true if the submenu was found.
Sourcepub fn push_separator(&self, into: MenuItemId) -> bool
pub fn push_separator(&self, into: MenuItemId) -> bool
Append a separator to the submenu identified by into. Returns true
if the submenu was found.
Insert a top-level menu at index, under a caller-supplied id.
push_menu appends, which puts a menu after Help —
fine for something added once at startup, wrong for a menu that comes and
goes, since a writer looking for it needs it in the same place every
time. The id is the caller’s for the same reason: a menu that will be
removed again has to be nameable before it exists.
index is clamped, so a model that has since grown or shrunk cannot
panic a caller holding a stale position.
Sourcepub fn contains(&self, id: MenuItemId) -> bool
pub fn contains(&self, id: MenuItemId) -> bool
Whether a node with this id is anywhere in the tree.
The companion to remove for callers that add and
remove the same node as state changes: without it, “is it already
there?” can only be answered by removing it and seeing what comes back,
which bumps the version and re-installs the native menu for nothing.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for MenuModel
impl !Send for MenuModel
impl !Sync for MenuModel
impl !UnwindSafe for MenuModel
impl Freeze for MenuModel
impl Unpin for MenuModel
impl UnsafeUnpin for MenuModel
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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.§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.§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.§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.impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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