pub struct MenuState { /* private fields */ }Expand description
The open menu of a DropdownMenu, a
ContextMenu, or a text field.
Owned by the view that shows the menu, which observes it so a change renders. The rows are given when the menu opens, so what they show (whether Paste has something to paste) is read at that moment.
While open the menu holds focus. It closes on an outside press, on Escape at its root, when focus leaves it, and when an item is chosen, and then gives focus back to the element that had it before.
Implementations§
Source§impl MenuState
impl MenuState
Sourcepub fn highlighted(&self) -> Option<SharedString>
pub fn highlighted(&self) -> Option<SharedString>
The key of the row the keyboard or the pointer is on, in the innermost level that has one.
Sourcepub fn open(
&mut self,
entries: impl IntoIterator<Item = impl Into<MenuEntry>>,
anchor: MenuAnchor,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
pub fn open( &mut self, entries: impl IntoIterator<Item = impl Into<MenuEntry>>, anchor: MenuAnchor, window: &mut Window, cx: &mut Context<'_, Self>, )
Opens the menu with entries at anchor and moves focus into it.
An action an item dispatches goes to the element that had focus
before, as its key binding would, and its shortcut is read there;
with nothing focused it goes up from the element the menu is drawn
in. A menu that is open already opens again in the new place.
Sourcepub fn set_entries(
&mut self,
entries: impl IntoIterator<Item = impl Into<MenuEntry>>,
cx: &mut Context<'_, Self>,
)
pub fn set_entries( &mut self, entries: impl IntoIterator<Item = impl Into<MenuEntry>>, cx: &mut Context<'_, Self>, )
Replaces the rows of the open menu, as an answer that arrives after it opened. Submenus close; the keyboard stays on the row with the same key when there is one. A closed menu ignores it.
Sourcepub fn open_for(
&mut self,
entries: impl IntoIterator<Item = impl Into<MenuEntry>>,
anchor: MenuAnchor,
action_context: &FocusHandle,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
pub fn open_for( &mut self, entries: impl IntoIterator<Item = impl Into<MenuEntry>>, anchor: MenuAnchor, action_context: &FocusHandle, window: &mut Window, cx: &mut Context<'_, Self>, )
Opens the menu as open does, with the actions its
items dispatch going to action_context, and their shortcuts read
from it.
Trait Implementations§
impl EventEmitter<MenuEvent> for MenuState
Source§impl Focusable for MenuState
The menu’s own focus handle, which holds the keyboard while it is open.
impl Focusable for MenuState
The menu’s own focus handle, which holds the keyboard while it is open.
Source§fn focus_handle(&self, _: &App) -> FocusHandle
fn focus_handle(&self, _: &App) -> FocusHandle
Auto Trait Implementations§
impl !RefUnwindSafe for MenuState
impl !Send for MenuState
impl !Sync for MenuState
impl !UnwindSafe for MenuState
impl Freeze for MenuState
impl Unpin for MenuState
impl UnsafeUnpin for MenuState
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> 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.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§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