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
pub fn new( id: impl Into<ElementId>, trigger: impl IntoElement, items: impl IntoIterator<Item = MenuItem>, ) -> Self
Sourcepub fn context(self) -> Self
pub fn context(self) -> Self
Opens on secondary click; Enter and Space still work on the trigger.
pub fn anchor(self, anchor: Anchor) -> Self
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(
self,
callback: impl Fn(&mut Window, &mut App) + 'static,
) -> Self
pub fn on_dismiss( 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 Menu
impl Move for Menu
impl Unpin for Menu
impl UnsafeUnpin for Menu
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> 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>) -> Self::Element
fn test_text(self, text: impl Into<SharedString>) -> 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>) -> Self::Element
fn test_alt_text(self, text: impl Into<SharedString>) -> Self::Element
Self::test_text for an image’s alternative text, which
stands in for what the element draws.