Skip to main content

ShowMenu

Struct ShowMenu 

Source
pub struct ShowMenu<T: Clone + PartialEq + 'static> { /* private fields */ }
Expand description

Show a popup menu that contains the items at position.

The items parameter must not be empty.

Only one of position or position_builder should be provided. Providing both throws an assertion error. The position_builder is called whenever the menu’s overlay is laid out, with the overlay’s constraints, and it should return the position of the menu.

If initial_value is specified then the first item with a matching value will be highlighted and the value of position gives the rectangle whose vertical center will be aligned with the vertical center of the highlighted item (when possible).

If initial_value is not specified then the top of the menu will be aligned with the top of the position rectangle.

In both cases, the menu position will be adjusted if necessary to fit on the screen.

Horizontally, the menu is positioned so that it grows in the direction that has the most room. For example, if the position describes a rectangle on the left edge of the screen, then the left edge of the menu is aligned with the left edge of the position, and the menu grows to the right. If both edges of the position are equidistant from the opposite edge of the screen, then the ambient Directionality is used as a tie-breaker, preferring to grow in the reading direction.

The positioning of the initial_value at the position is implemented by iterating over the items to find the first whose PopupMenuEntry::represents method returns true for initial_value, and then summing the values of PopupMenuEntry::height for all the preceding widgets in the list.

The elevation argument specifies the z-coordinate at which to place the menu. The elevation defaults to 8, the appropriate elevation for popup menus.

The context argument is used to look up the Navigator and Theme for the menu. It is only used when the method is called. Its corresponding widget can be safely removed from the tree before the popup menu is closed.

The use_root_navigator argument is used to determine whether to push the menu to the Navigator furthest from or nearest to the given context. It is false by default.

The semantic_label argument is used by accessibility frameworks to announce screen transitions when the menu is opened and closed. If this label is not provided, it will default to MaterialLocalizations::popup_menu_label.

The clip_behavior argument is used to clip the shape of the menu. Defaults to Clip::None.

The request_focus argument specifies whether the menu should request focus when it appears. If it is None, Navigator::request_focus is used instead.

The future resolves to the item’s value the menu was popped with, erased as a route’s result is, or None if the menu was dismissed.

See also:

Implementations§

Source§

impl<T: Clone + PartialEq + 'static> ShowMenu<T>

Source

pub fn new(items: Vec<PopupMenuEntryRef<T>>) -> ShowMenu<T>

Creates a builder for a popup menu; Dart’s showMenu required argument is the items, and every other argument is a setter.

Source

pub fn position(self, position: RelativeRect) -> ShowMenu<T>

The rectangle the menu is positioned against.

Source

pub fn position_builder( self, position_builder: PopupMenuPositionBuilder, ) -> ShowMenu<T>

A builder of the rectangle the menu is positioned against.

Source

pub fn initial_value(self, initial_value: T) -> ShowMenu<T>

The value the menu opens with.

Source

pub fn elevation(self, elevation: f64) -> ShowMenu<T>

The z-coordinate of the menu.

Source

pub fn shadow_color(self, shadow_color: Color) -> ShowMenu<T>

The color of the menu’s shadow.

Source

pub fn surface_tint_color(self, surface_tint_color: Color) -> ShowMenu<T>

The color of the menu’s surface tint.

Source

pub fn semantic_label(self, semantic_label: impl Into<String>) -> ShowMenu<T>

The semantic label announced when the menu opens and closes.

Source

pub fn shape(self, shape: impl Into<ShapeBorderRef>) -> ShowMenu<T>

The shape of the menu.

Source

pub fn menu_padding( self, menu_padding: impl Into<EdgeInsetsGeometry>, ) -> ShowMenu<T>

The padding inside the menu.

Source

pub fn color(self, color: Color) -> ShowMenu<T>

The menu’s background color.

Source

pub fn use_root_navigator(self, use_root_navigator: bool) -> ShowMenu<T>

Whether to push the menu to the root navigator. Defaults to false.

Source

pub fn constraints(self, constraints: BoxConstraints) -> ShowMenu<T>

The size constraints on the menu.

Source

pub fn clip_behavior(self, clip_behavior: Clip) -> ShowMenu<T>

The clip behavior of the menu. Defaults to Clip::None.

Source

pub fn route_settings(self, route_settings: RouteSettingsRef) -> ShowMenu<T>

The route settings passed to the menu’s route.

Source

pub fn pop_up_animation_style( self, pop_up_animation_style: AnimationStyle, ) -> ShowMenu<T>

An animation style that overrides the menu’s animation.

Source

pub fn request_focus(self, request_focus: bool) -> ShowMenu<T>

Whether the menu’s route requests focus when it appears.

Source

pub fn show( self, app: &mut App, context: BuildContext, ) -> CompleterFuture<RouteResult> ⓘ

Shows the menu and returns the value the menu was popped with.

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for ShowMenu<T>

§

impl<T> !Send for ShowMenu<T>

§

impl<T> !Sync for ShowMenu<T>

§

impl<T> !UnwindSafe for ShowMenu<T>

§

impl<T> Forget for ShowMenu<T>

§

impl<T> Freeze for ShowMenu<T>
where *const RcInner<dyn Fn(&mut App, AnyElement, BoxConstraints) -> RelativeRect> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, AnyElement, BoxConstraints) -> RelativeRect>>: Freeze, *const u8 is !null: Freeze, PhantomData<PopupMenuEntryRef<T>>: Freeze, T: Freeze, PhantomData<u8>: Freeze, *const RcInner<dyn ShapeBorder> is !null: Freeze, PhantomData<RcInner<dyn ShapeBorder>>: Freeze, *const RcInner<dyn Any> is !null: Freeze, PhantomData<RcInner<dyn Any>>: Freeze, *const RcInner<dyn Page> is !null: Freeze, PhantomData<RcInner<dyn Page>>: Freeze, *const RcInner<dyn Curve> is !null: Freeze, PhantomData<RcInner<dyn Curve>>: Freeze,

§

impl<T> Move for ShowMenu<T>

§

impl<T> Unpin for ShowMenu<T>
where T: Unpin, Rc<dyn Fn(&mut App, AnyElement, BoxConstraints) -> RelativeRect>: Unpin, *const u8 is !null: Unpin, Rc<dyn Widget>: Unpin, Rc<dyn ShapeBorder>: Unpin, Rc<dyn Any>: Unpin, Rc<dyn Page>: Unpin, Rc<dyn Curve>: Unpin,

§

impl<T> UnsafeUnpin for ShowMenu<T>
where *const RcInner<dyn Fn(&mut App, AnyElement, BoxConstraints) -> RelativeRect> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, AnyElement, BoxConstraints) -> RelativeRect>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<PopupMenuEntryRef<T>>: UnsafeUnpin, T: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const RcInner<dyn ShapeBorder> is !null: UnsafeUnpin, PhantomData<RcInner<dyn ShapeBorder>>: UnsafeUnpin, *const RcInner<dyn Any> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Any>>: UnsafeUnpin, *const RcInner<dyn Page> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Page>>: UnsafeUnpin, *const RcInner<dyn Curve> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Curve>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>