pub struct Menu { /* private fields */ }Expand description
Positions a Material menu against a caller-owned, keyboard-focusable trigger. Pointer and keyboard activation use the same Base popover focus lifecycle.
Implementations§
Source§impl Menu
impl Menu
Sourcepub fn new(
id: impl Into<ElementId>,
trigger: impl IntoElement,
items: impl IntoIterator<Item = MenuItem>,
) -> Self
pub fn new( id: impl Into<ElementId>, trigger: impl IntoElement, items: impl IntoIterator<Item = MenuItem>, ) -> Self
Creates a menu anchored to trigger with eagerly constructed items.
Sourcepub fn new_with<I>(
id: impl Into<ElementId>,
trigger: impl IntoElement,
build: impl FnOnce(&mut Window, &mut App) -> I + 'static,
) -> Selfwhere
I: IntoIterator<Item = MenuItem>,
pub fn new_with<I>(
id: impl Into<ElementId>,
trigger: impl IntoElement,
build: impl FnOnce(&mut Window, &mut App) -> I + 'static,
) -> Selfwhere
I: IntoIterator<Item = MenuItem>,
Creates a menu whose items are built lazily only while the menu is open.
Sourcepub fn disabled(self, disabled: bool) -> Self
pub fn disabled(self, disabled: bool) -> Self
Disables menu activation while continuing to render the trigger element.
Sourcepub fn context(self) -> Self
pub fn context(self) -> Self
Opens on secondary click at the pointer location (viewport-clamped), or
anchored to the trigger on Shift+F10 / ContextMenu, without hijacking
the trigger’s own Enter or Space activation.
Sourcepub fn anchor(self, anchor: Anchor) -> Self
pub fn anchor(self, anchor: Anchor) -> Self
Sets the anchor corner used to align the popup against its trigger (default Anchor::TopLeft).
Sourcepub fn offset(self, offset: Pixels) -> Self
pub fn offset(self, offset: Pixels) -> Self
Sets the outward gap between the trigger and popup.
Sourcepub fn position(self, position: Point<Pixels>) -> Self
pub fn position(self, position: Point<Pixels>) -> Self
Anchors the popup at a window-local point. It remains clamped to the viewport.
Sourcepub fn color(self, color: MenuColor) -> Self
pub fn color(self, color: MenuColor) -> Self
Applies a semantic color preset to the menu and its submenus.
Sourcepub fn appearance(self, appearance: MenuSurfaceStyle) -> Self
pub fn appearance(self, appearance: MenuSurfaceStyle) -> Self
Applies overrides to this popup’s surface.
Sourcepub fn content<E: IntoElement>(self, build: impl Fn() -> E + 'static) -> Self
pub fn content<E: IntoElement>(self, build: impl Fn() -> E + 'static) -> Self
Renders arbitrary content before the menu rows. Use a repeatable factory for content that also needs to appear during exit.
Sourcepub fn track_scroll(self, scroll: &ScrollHandle) -> Self
pub fn track_scroll(self, scroll: &ScrollHandle) -> Self
Tracks the popup’s scrolling through a caller-owned handle.
Sourcepub fn composed(
id: impl Into<ElementId>,
items: impl IntoIterator<Item = MenuItem>,
trigger: impl FnOnce(bool, Rc<dyn Fn(&mut Window, &mut App)>) -> AnyElement + 'static,
) -> Self
pub fn composed( id: impl Into<ElementId>, items: impl IntoIterator<Item = MenuItem>, trigger: impl FnOnce(bool, Rc<dyn Fn(&mut Window, &mut App)>) -> AnyElement + 'static, ) -> Self
Builds a trigger from the displayed open value and its activation callback.
Keep the trigger focusable and use the supplied callback for a custom accessibility action. The menu owns pointer and keyboard activation.
Sourcepub fn on_open_change(
self,
callback: impl Fn(bool, &mut Window, &mut App) + 'static,
) -> Self
pub fn on_open_change( self, callback: impl Fn(bool, &mut Window, &mut App) + 'static, ) -> Self
Receives user requests to open or close the menu. In controlled mode,
apply the requested value and render with open to accept a request.
Sourcepub fn on_dismiss_request(
self,
callback: impl Fn(&mut Window, &mut App) + 'static,
) -> Self
pub fn on_dismiss_request( self, callback: impl Fn(&mut Window, &mut App) + 'static, ) -> Self
Receives a user request to close. Setting open(false) externally
synchronizes the menu without running this callback.
Trait Implementations§
Source§impl IntoElement for Menu
impl IntoElement for Menu
Source§type Element = ViewElement<Menu>
type Element = ViewElement<Menu>
Source§fn into_element(self) -> Self::Element
fn into_element(self) -> Self::Element
Element.Source§fn into_any_element(self) -> AnyElement
fn into_any_element(self) -> AnyElement
AnyElement.Source§impl RenderOnce for Menu
impl RenderOnce for Menu
Source§fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement
Render::render() method
which takes a mutable reference.Auto Trait Implementations§
impl !RefUnwindSafe for Menu
impl !Send for Menu
impl !Sync for Menu
impl !UnwindSafe for Menu
impl Forget for Menu
impl Freeze for Menuwhere
NonZero<u32>: Freeze,
&'static str: Freeze,
*const ArcInner<str> is !null: Freeze,
PhantomData<ArcInner<str>>: Freeze,
*const ArcInner<Path> is !null: Freeze,
PhantomData<ArcInner<Path>>: Freeze,
*const str is !null: Freeze,
PhantomData<&'static str>: Freeze,
*const ArcInner<ElementId> is !null: Freeze,
PhantomData<ArcInner<ElementId>>: Freeze,
*mut dyn ElementObject: Freeze,
*const RcInner<Cell<bool>> is !null: Freeze,
PhantomData<RcInner<Cell<bool>>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<MenuItem>: Freeze,
*const dyn FnOnce(&mut Window, &mut App) -> Vec<MenuItem> is !null: Freeze,
PhantomData<dyn FnOnce(&mut Window, &mut App) -> Vec<MenuItem>>: Freeze,
*const RcInner<dyn Fn(&mut Window, &mut App)> is !null: Freeze,
PhantomData<RcInner<dyn Fn(&mut Window, &mut App)>>: Freeze,
*const RcInner<PopupBounds> is !null: Freeze,
PhantomData<RcInner<PopupBounds>>: Freeze,
*const dyn FnOnce(bool, Rc<dyn Fn(&mut Window, &mut App)>) -> AnyElement is !null: Freeze,
PhantomData<dyn FnOnce(bool, Rc<dyn Fn(&mut Window, &mut App)>) -> AnyElement>: Freeze,
*const RcInner<dyn Fn(bool, &mut Window, &mut App)> is !null: Freeze,
PhantomData<RcInner<dyn Fn(bool, &mut Window, &mut App)>>: Freeze,
*const RcInner<dyn Fn() -> AnyElement> is !null: Freeze,
PhantomData<RcInner<dyn Fn() -> AnyElement>>: Freeze,
*const RcInner<RefCell<ScrollHandleState>> is !null: Freeze,
PhantomData<RcInner<RefCell<ScrollHandleState>>>: Freeze,
impl Move for Menu
impl Unpin for Menuwhere
NonZero<u32>: Unpin,
&'static str: Unpin,
Arc<str>: Unpin,
Arc<Path>: Unpin,
*const str is !null: Unpin,
Arc<ElementId>: Unpin,
*mut dyn ElementObject: Unpin,
Rc<Cell<bool>>: Unpin,
*const u8 is !null: Unpin,
Rc<dyn Fn(&mut Window, &mut App)>: Unpin,
Rc<dyn Fn() -> AnyElement>: Unpin,
Rc<dyn Fn(bool, &mut Window, &mut App)>: Unpin,
Box<dyn FnOnce(&mut Window, &mut App) -> Vec<MenuItem>>: Unpin,
Rc<PopupBounds>: Unpin,
Box<dyn FnOnce(bool, Rc<dyn Fn(&mut Window, &mut App)>) -> AnyElement>: Unpin,
Rc<RefCell<ScrollHandleState>>: Unpin,
impl UnsafeUnpin for Menuwhere
NonZeroU32Inner: UnsafeUnpin,
&'static str: UnsafeUnpin,
*const ArcInner<str> is !null: UnsafeUnpin,
PhantomData<ArcInner<str>>: UnsafeUnpin,
*const ArcInner<Path> is !null: UnsafeUnpin,
PhantomData<ArcInner<Path>>: UnsafeUnpin,
*const str is !null: UnsafeUnpin,
PhantomData<&'static str>: UnsafeUnpin,
*const ArcInner<ElementId> is !null: UnsafeUnpin,
PhantomData<ArcInner<ElementId>>: UnsafeUnpin,
*mut dyn ElementObject: UnsafeUnpin,
*const RcInner<Cell<bool>> is !null: UnsafeUnpin,
PhantomData<RcInner<Cell<bool>>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<MenuItem>: UnsafeUnpin,
*const dyn FnOnce(&mut Window, &mut App) -> Vec<MenuItem> is !null: UnsafeUnpin,
PhantomData<dyn FnOnce(&mut Window, &mut App) -> Vec<MenuItem>>: UnsafeUnpin,
*const RcInner<dyn Fn(&mut Window, &mut App)> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Fn(&mut Window, &mut App)>>: UnsafeUnpin,
*const RcInner<PopupBounds> is !null: UnsafeUnpin,
PhantomData<RcInner<PopupBounds>>: UnsafeUnpin,
*const dyn FnOnce(bool, Rc<dyn Fn(&mut Window, &mut App)>) -> AnyElement is !null: UnsafeUnpin,
PhantomData<dyn FnOnce(bool, Rc<dyn Fn(&mut Window, &mut App)>) -> AnyElement>: UnsafeUnpin,
*const RcInner<dyn Fn(bool, &mut Window, &mut App)> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Fn(bool, &mut Window, &mut App)>>: UnsafeUnpin,
*const RcInner<dyn Fn() -> AnyElement> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Fn() -> AnyElement>>: UnsafeUnpin,
*const RcInner<RefCell<ScrollHandleState>> is !null: UnsafeUnpin,
PhantomData<RcInner<RefCell<ScrollHandleState>>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<E> AnimationExt for Ewhere
E: IntoElement + 'static,
impl<E> AnimationExt for Ewhere
E: IntoElement + 'static,
Source§fn with_animation(
self,
id: impl Into<ElementId>,
animation: Animation,
animator: impl Fn(Self, f32) -> Self + 'static,
) -> AnimationElement<Self>where
Self: Sized,
fn with_animation(
self,
id: impl Into<ElementId>,
animation: Animation,
animator: impl Fn(Self, f32) -> Self + 'static,
) -> AnimationElement<Self>where
Self: Sized,
Source§fn with_animations(
self,
id: impl Into<ElementId>,
animations: Vec<Animation>,
animator: impl Fn(Self, usize, f32) -> Self + 'static,
) -> AnimationElement<Self>where
Self: Sized,
fn with_animations(
self,
id: impl Into<ElementId>,
animations: Vec<Animation>,
animator: impl Fn(Self, usize, f32) -> Self + 'static,
) -> AnimationElement<Self>where
Self: Sized,
Source§fn with_spring<T>(
self,
id: impl Into<ElementId>,
animation: SpringAnimation<T>,
animator: impl FnOnce(Self, <T as SpringTarget>::Output) -> Self + 'static,
) -> SpringAnimationElement<Self>
fn with_spring<T>( self, id: impl Into<ElementId>, animation: SpringAnimation<T>, animator: impl FnOnce(Self, <T as SpringTarget>::Output) -> Self + 'static, ) -> SpringAnimationElement<Self>
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
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> FluentBuilder for Twhere
T: IntoElement,
impl<T> FluentBuilder for Twhere
T: IntoElement,
Source§fn map<U>(self, f: impl FnOnce(Self) -> U) -> Uwhere
Self: Sized,
fn map<U>(self, f: impl FnOnce(Self) -> U) -> Uwhere
Self: Sized,
Source§fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Selfwhere
Self: Sized,
fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Selfwhere
Self: Sized,
Source§fn when_else(
self,
condition: bool,
then: impl FnOnce(Self) -> Self,
else_fn: impl FnOnce(Self) -> Self,
) -> Selfwhere
Self: Sized,
fn when_else(
self,
condition: bool,
then: impl FnOnce(Self) -> Self,
else_fn: impl FnOnce(Self) -> Self,
) -> Selfwhere
Self: Sized,
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 moreSource§impl<T> MaterialElementExt for Twhere
T: IntoElement,
impl<T> MaterialElementExt for Twhere
T: IntoElement,
Source§fn badge_label(self, text: impl Into<SharedString>) -> Badge
fn badge_label(self, text: impl Into<SharedString>) -> Badge
Badge to this element’s upper trailing edge.Source§fn badge_count(self, count: usize, maximum: usize) -> Badge
fn badge_count(self, count: usize, maximum: usize) -> Badge
Badge to this element’s upper trailing edge.Source§fn tooltip(
self,
id: impl Into<ElementId>,
text: impl Into<SharedString>,
) -> Tooltip
fn tooltip( self, id: impl Into<ElementId>, text: impl Into<SharedString>, ) -> Tooltip
Tooltip.Menu.Menu
whose items are built lazily only while the menu is open.Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<E> TestTextExt for Ewhere
E: IntoElement,
impl<E> TestTextExt for Ewhere
E: IntoElement,
Source§fn test_text(self, text: impl Into<SharedString>) -> ObservedText<Self::Element>
fn test_text(self, text: impl Into<SharedString>) -> ObservedText<Self::Element>
test-support, records text each time the element paints.
Otherwise returns the element it builds.Source§fn test_alt_text(
self,
text: impl Into<SharedString>,
) -> ObservedText<Self::Element>
fn test_alt_text( self, text: impl Into<SharedString>, ) -> ObservedText<Self::Element>
Self::test_text for an image’s alternative text, which
stands in for what the element draws.