pub struct MenuAnchor {Show 20 fields
pub key: Option<KeyRef>,
pub controller: Option<MenuControllerRef>,
pub child_focus_node: Option<FocusNodeRef>,
pub style: Option<MenuStyle>,
pub alignment_offset: Option<Offset>,
pub layer_link: Option<Ref<LayerLink>>,
pub clip_behavior: Clip,
pub anchor_tap_closes_menu: bool,
pub consume_outside_tap: bool,
pub on_open: Option<VoidCallback>,
pub on_close: Option<VoidCallback>,
pub cross_axis_unconstrained: bool,
pub use_root_overlay: bool,
pub animated: bool,
pub on_animation_status_changed: Option<ValueChanged<AnimationStatus>>,
pub menu_children: Vec<WidgetRef>,
pub builder: Option<MenuAnchorChildBuilder>,
pub semantic_label: Option<String>,
pub child: Option<WidgetRef>,
pub reserved_padding: Option<EdgeInsetsGeometry>,
}Expand description
A widget used to mark the “anchor” for a set of submenus, defining the rectangle used to position the menu, which can be done either with an explicit location, or with an alignment.
When creating a menu with MenuBar or a SubmenuButton, a MenuAnchor is
not needed, since they provide their own internally.
The MenuAnchor is meant to be a slightly lower level interface than
MenuBar, used in situations where a MenuBar isn’t appropriate, or to
construct widgets or screen regions that have submenus.
To programmatically control a MenuAnchor, like opening or closing it, or checking its
state, you can get its associated MenuController. Use MenuController::maybe_of(app, context) to retrieve the controller for the closest MenuAnchor ancestor of a given
BuildContext. More detailed usage of MenuController is available in its type
documentation.
The MenuStyle::visual_density setting only affects horizontal padding,
and it will never make it negative. Vertical padding is not affected at all.
Fields§
§key: Option<KeyRef>See Widget::key.
controller: Option<MenuControllerRef>An optional controller that allows opening and closing of the menu from other widgets.
child_focus_node: Option<FocusNodeRef>The child_focus_node attribute is the optional FocusNode
also associated to the child or builder widget that
opens the menu.
The focus node should be attached to the widget that should receive focus if keyboard focus traversal moves the focus off of the submenu with the arrow keys.
If not supplied, then keyboard traversal from the menu back to the controlling button when the menu is open is disabled.
style: Option<MenuStyle>The MenuStyle that defines the visual attributes of the menu bar.
Colors and sizing of the menus is controllable via the MenuStyle.
Defaults to the ambient MenuThemeData::style.
alignment_offset: Option<Offset>The offset of the menu relative to the alignment origin determined by
MenuStyle::alignment on the style attribute and the ambient
Directionality.
Use this for adjustments of the menu placement.
Increasing Offset::dy values of alignment_offset move
the menu position down.
If the MenuStyle::alignment from style is not an
AlignmentDirectional (e.g. Alignment), then increasing Offset::dx values of
alignment_offset move the menu position to the right.
If the MenuStyle::alignment from style is an
AlignmentDirectional, then in a TextDirection::Ltr Directionality, increasing
Offset::dx values of alignment_offset move the menu
position to the right. In a TextDirection::Rtl directionality, increasing
Offset::dx values of alignment_offset move the menu
position to the left.
Defaults to Offset::ZERO.
layer_link: Option<Ref<LayerLink>>An optional LayerLink to attach the menu to the widget that this
MenuAnchor surrounds.
When provided, the menu will follow the widget that this MenuAnchor
surrounds if it moves because of view insets changes.
clip_behavior: ClipThe content will be clipped (or not) according to this option.
Defaults to Clip::HardEdge.
Use consumeOutsideTap instead. This feature was deprecated after v3.16.0-8.0.pre.
Whether the menus will be closed if the anchor area is tapped.
For menus opened by buttons that toggle the menu, if the button is tapped
when the menu is open, the button should close the menu. But if
anchor_tap_closes_menu is true, then the menu will
close, and (surprisingly) immediately re-open. This is because tapping on the button
closes the menu before the on_pressed or on_tap handler is called
because of it being considered to be “outside” the menu system, and then
the button (seeing that the menu is closed) immediately reopens the menu.
The result is that the user thinks that tapping on the button does
nothing. So, for button-initiated menus, this value is typically false so
that the menu anchor area is considered “inside” of the menu system and
doesn’t cause it to close unless [MenuControllerLeaf::close] is called.
For menus that are positioned using [MenuControllerLeaf::open]’s position
parameter, it is often desirable that clicking on the anchor always closes
the menu since the anchor area isn’t usually considered part of the menu
system by the user. In this case
anchor_tap_closes_menu should be true.
Defaults to false.
consume_outside_tap: boolWhether or not a tap event that closes the menu will be permitted to continue on to the gesture arena.
If false, then tapping outside of a menu when the menu is open will both close the menu, and allow the tap to participate in the gesture arena. If true, then it will only close the menu, and the tap event will be consumed.
Defaults to false.
on_open: Option<VoidCallback>A callback that is invoked when the menu begins opening.
Defaults to null.
on_close: Option<VoidCallback>A callback that is invoked when the menu finishes closing.
Defaults to null.
cross_axis_unconstrained: boolDetermine if the menu panel can be wrapped by a UnconstrainedBox which allows
the panel to render at its “natural” size.
Defaults to true as it allows developers to render the menu panel at the
size it should be. When it is set to false, it can be useful when the menu should
be constrained in both main axis and cross axis, such as a DropdownMenu.
use_root_overlay: boolWhether the menu panel should be rendered in the root Overlay.
See RawMenuAnchor::use_root_overlay.
Defaults to false.
animated: boolWhether this widget should open or close a submenu with an animation.
Defaults to false.
on_animation_status_changed: Option<ValueChanged<AnimationStatus>>An optional callback that is invoked when the AnimationStatus of the
menu changes during open and close animations.
If animated is false, this callback will only be invoked with
AnimationStatus::Completed when the menu is opened, and
AnimationStatus::Dismissed when the menu is closed.
This callback provides a way to determine when the menu is opening or
closing. This is necessary because the [MenuControllerLeaf::is_open] property
remains true throughout the opening, opened, and closing phases, and
therefore cannot be used on its own to determine the current animation
direction.
Defaults to null.
A list of children containing the menu items that are the contents of the
menu surrounded by this MenuAnchor.
Menus using MenuItemButton can have a SingleActivator or CharacterActivator
assigned to them as their MenuItemButton::shortcut, which will display an
appropriate shortcut hint. Even though the shortcut labels are displayed in the menu,
shortcuts are not automatically handled. They must be available in whatever context
they are appropriate, and handled via another mechanism.
builder: Option<MenuAnchorChildBuilder>The widget that this MenuAnchor surrounds.
Typically this is a button used to open the menu by calling
[MenuControllerLeaf::open] on the controller passed to the builder.
If not supplied, then the MenuAnchor will be the size that its parent
allocates for it.
If provided, the builder will be called each time the menu is opened or closed.
semantic_label: Option<String>The semantic label of the menu.
Defaults to null.
child: Option<WidgetRef>The optional child to be passed to the builder.
Supply this child if there is a portion of the widget tree built in
builder that doesn’t depend on the controller or context
supplied to the builder. It will be more efficient, since Flutter
doesn’t then need to rebuild this child when those change.
reserved_padding: Option<EdgeInsetsGeometry>The padding between the edge of the safe area and the menu panel.
Defaults to EdgeInsets::all(8).
Implementations§
Source§impl MenuAnchor
impl MenuAnchor
Sourcepub fn new(menu_children: Vec<WidgetRef>) -> MenuAnchor
pub fn new(menu_children: Vec<WidgetRef>) -> MenuAnchor
Creates a const MenuAnchor.
The menu_children argument is required.
Sourcepub fn key(self, key: KeyRef) -> MenuAnchor
pub fn key(self, key: KeyRef) -> MenuAnchor
Dart MenuAnchor(key:).
Sourcepub fn controller(self, controller: MenuControllerRef) -> MenuAnchor
pub fn controller(self, controller: MenuControllerRef) -> MenuAnchor
Dart MenuAnchor(controller:).
Sourcepub fn child_focus_node(self, child_focus_node: FocusNodeRef) -> MenuAnchor
pub fn child_focus_node(self, child_focus_node: FocusNodeRef) -> MenuAnchor
Dart MenuAnchor(childFocusNode:).
Sourcepub fn style(self, style: MenuStyle) -> MenuAnchor
pub fn style(self, style: MenuStyle) -> MenuAnchor
Dart MenuAnchor(style:).
Sourcepub fn alignment_offset(self, alignment_offset: Offset) -> MenuAnchor
pub fn alignment_offset(self, alignment_offset: Offset) -> MenuAnchor
Dart MenuAnchor(alignmentOffset:).
Sourcepub fn reserved_padding(
self,
reserved_padding: impl Into<EdgeInsetsGeometry>,
) -> MenuAnchor
pub fn reserved_padding( self, reserved_padding: impl Into<EdgeInsetsGeometry>, ) -> MenuAnchor
Dart MenuAnchor(reservedPadding:).
Sourcepub fn layer_link(self, layer_link: Ref<LayerLink>) -> MenuAnchor
pub fn layer_link(self, layer_link: Ref<LayerLink>) -> MenuAnchor
Dart MenuAnchor(layerLink:).
Sourcepub fn clip_behavior(self, clip_behavior: Clip) -> MenuAnchor
pub fn clip_behavior(self, clip_behavior: Clip) -> MenuAnchor
Dart MenuAnchor(clipBehavior:).
👎Deprecated: Use consumeOutsideTap instead. This feature was deprecated after v3.16.0-8.0.pre.
Use consumeOutsideTap instead. This feature was deprecated after v3.16.0-8.0.pre.
Dart MenuAnchor(anchorTapClosesMenu:).
Sourcepub fn consume_outside_tap(self, consume_outside_tap: bool) -> MenuAnchor
pub fn consume_outside_tap(self, consume_outside_tap: bool) -> MenuAnchor
Dart MenuAnchor(consumeOutsideTap:).
Sourcepub fn on_open(self, on_open: VoidCallback) -> MenuAnchor
pub fn on_open(self, on_open: VoidCallback) -> MenuAnchor
Dart MenuAnchor(onOpen:).
Sourcepub fn on_close(self, on_close: VoidCallback) -> MenuAnchor
pub fn on_close(self, on_close: VoidCallback) -> MenuAnchor
Dart MenuAnchor(onClose:).
Sourcepub fn cross_axis_unconstrained(
self,
cross_axis_unconstrained: bool,
) -> MenuAnchor
pub fn cross_axis_unconstrained( self, cross_axis_unconstrained: bool, ) -> MenuAnchor
Dart MenuAnchor(crossAxisUnconstrained:).
Sourcepub fn use_root_overlay(self, use_root_overlay: bool) -> MenuAnchor
pub fn use_root_overlay(self, use_root_overlay: bool) -> MenuAnchor
Dart MenuAnchor(useRootOverlay:).
Sourcepub fn animated(self, animated: bool) -> MenuAnchor
pub fn animated(self, animated: bool) -> MenuAnchor
Dart MenuAnchor(animated:).
Sourcepub fn on_animation_status_changed(
self,
on_animation_status_changed: ValueChanged<AnimationStatus>,
) -> MenuAnchor
pub fn on_animation_status_changed( self, on_animation_status_changed: ValueChanged<AnimationStatus>, ) -> MenuAnchor
Dart MenuAnchor(onAnimationStatusChanged:).
Sourcepub fn builder(
self,
builder: impl Fn(&mut App, BuildContext, AnyMenuController, Option<&WidgetRef>) -> WidgetRef + 'static,
) -> MenuAnchor
pub fn builder( self, builder: impl Fn(&mut App, BuildContext, AnyMenuController, Option<&WidgetRef>) -> WidgetRef + 'static, ) -> MenuAnchor
Dart MenuAnchor(builder:).
Sourcepub fn semantic_label(self, semantic_label: impl Into<String>) -> MenuAnchor
pub fn semantic_label(self, semantic_label: impl Into<String>) -> MenuAnchor
Dart MenuAnchor(semanticLabel:).
Sourcepub fn child<K>(self, child: impl IntoWidget<K>) -> MenuAnchor
pub fn child<K>(self, child: impl IntoWidget<K>) -> MenuAnchor
Dart MenuAnchor(child:).
Trait Implementations§
Source§impl Debug for MenuAnchor
impl Debug for MenuAnchor
Source§impl StatefulWidget for MenuAnchor
impl StatefulWidget for MenuAnchor
Source§type State = MenuAnchorState
type State = MenuAnchorState
Source§fn debug_fill_properties(
&self,
app: &App,
properties: &mut DiagnosticPropertiesBuilder,
)
fn debug_fill_properties( &self, app: &App, properties: &mut DiagnosticPropertiesBuilder, )
debugFillProperties: the properties a dump shows for this widget, in Dart’s
order. Dart’s Widget base only sets the dense tree style, which the framework does.Source§fn create_state(&self) -> MenuAnchorState
fn create_state(&self) -> MenuAnchorState
Source§fn as_preferred_size_widget(
&self,
) -> Option<&(dyn PreferredSizeWidget + 'static)>
fn as_preferred_size_widget( &self, ) -> Option<&(dyn PreferredSizeWidget + 'static)>
Source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
Widget::type_name. A stateful form another widget kind becomes (an animated or
status transition widget) names the widget it wraps.Auto Trait Implementations§
impl !RefUnwindSafe for MenuAnchor
impl !Send for MenuAnchor
impl !Sync for MenuAnchor
impl !UnwindSafe for MenuAnchor
impl Forget for MenuAnchor
impl Freeze for MenuAnchorwhere
*const RcInner<dyn Key> is !null: Freeze,
PhantomData<RcInner<dyn Key>>: Freeze,
NonZero<u32>: Freeze,
&'static MenuControllerVTable: Freeze,
*const RcInner<Keep> is !null: Freeze,
PhantomData<RcInner<Keep>>: Freeze,
&'static FocusNodeVTable: Freeze,
*const RcInner<dyn WidgetStateProperty<Option<Color>>> is !null: Freeze,
PhantomData<RcInner<dyn WidgetStateProperty<Option<Color>>>>: Freeze,
*const RcInner<dyn WidgetStateProperty<Option<f64>>> is !null: Freeze,
PhantomData<RcInner<dyn WidgetStateProperty<Option<f64>>>>: Freeze,
*const RcInner<dyn WidgetStateProperty<Option<EdgeInsetsGeometry>>> is !null: Freeze,
PhantomData<RcInner<dyn WidgetStateProperty<Option<EdgeInsetsGeometry>>>>: Freeze,
*const RcInner<dyn WidgetStateProperty<Option<Size>>> is !null: Freeze,
PhantomData<RcInner<dyn WidgetStateProperty<Option<Size>>>>: Freeze,
*const RcInner<dyn WidgetStateProperty<Option<BorderSide>>> is !null: Freeze,
PhantomData<RcInner<dyn WidgetStateProperty<Option<BorderSide>>>>: Freeze,
*const RcInner<dyn WidgetStateProperty<Option<OutlinedBorderRef>>> is !null: Freeze,
PhantomData<RcInner<dyn WidgetStateProperty<Option<OutlinedBorderRef>>>>: Freeze,
*const RcInner<dyn WidgetStateProperty<Option<Rc<dyn MouseCursor>>>> is !null: Freeze,
PhantomData<RcInner<dyn WidgetStateProperty<Option<Rc<dyn MouseCursor>>>>>: Freeze,
PhantomData<fn() -> LayerLink>: Freeze,
*const RcInner<dyn Fn(&mut App)> is !null: Freeze,
PhantomData<RcInner<dyn Fn(&mut App)>>: Freeze,
*const RcInner<dyn Fn(&mut App, AnimationStatus)> is !null: Freeze,
PhantomData<RcInner<dyn Fn(&mut App, AnimationStatus)>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<Rc<dyn Widget>>: Freeze,
*const RcInner<dyn Fn(&mut App, AnyElement, AnyMenuController, Option<&Rc<dyn Widget>>) -> Rc<dyn Widget>> is !null: Freeze,
PhantomData<RcInner<dyn Fn(&mut App, AnyElement, AnyMenuController, Option<&Rc<dyn Widget>>) -> Rc<dyn Widget>>>: Freeze,
PhantomData<u8>: Freeze,
*const RcInner<dyn Widget> is !null: Freeze,
PhantomData<RcInner<dyn Widget>>: Freeze,
impl Move for MenuAnchor
impl Unpin for MenuAnchorwhere
Rc<dyn Key>: Unpin,
NonZero<u32>: Unpin,
&'static MenuControllerVTable: Unpin,
Rc<Keep>: Unpin,
&'static FocusNodeVTable: Unpin,
Rc<dyn WidgetStateProperty<Option<Color>>>: Unpin,
Rc<dyn WidgetStateProperty<Option<f64>>>: Unpin,
Rc<dyn WidgetStateProperty<Option<EdgeInsetsGeometry>>>: Unpin,
Rc<dyn WidgetStateProperty<Option<Size>>>: Unpin,
Rc<dyn WidgetStateProperty<Option<BorderSide>>>: Unpin,
Rc<dyn WidgetStateProperty<Option<OutlinedBorderRef>>>: Unpin,
Rc<dyn WidgetStateProperty<Option<Rc<dyn MouseCursor>>>>: Unpin,
Rc<dyn Fn(&mut App)>: Unpin,
Rc<dyn Fn(&mut App, AnimationStatus)>: Unpin,
*const u8 is !null: Unpin,
Rc<dyn Widget>: Unpin,
Rc<dyn Fn(&mut App, AnyElement, AnyMenuController, Option<&Rc<dyn Widget>>) -> Rc<dyn Widget>>: Unpin,
impl UnsafeUnpin for MenuAnchorwhere
*const RcInner<dyn Key> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Key>>: UnsafeUnpin,
NonZeroU32Inner: UnsafeUnpin,
&'static MenuControllerVTable: UnsafeUnpin,
*const RcInner<Keep> is !null: UnsafeUnpin,
PhantomData<RcInner<Keep>>: UnsafeUnpin,
&'static FocusNodeVTable: UnsafeUnpin,
*const RcInner<dyn WidgetStateProperty<Option<Color>>> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn WidgetStateProperty<Option<Color>>>>: UnsafeUnpin,
*const RcInner<dyn WidgetStateProperty<Option<f64>>> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn WidgetStateProperty<Option<f64>>>>: UnsafeUnpin,
*const RcInner<dyn WidgetStateProperty<Option<EdgeInsetsGeometry>>> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn WidgetStateProperty<Option<EdgeInsetsGeometry>>>>: UnsafeUnpin,
*const RcInner<dyn WidgetStateProperty<Option<Size>>> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn WidgetStateProperty<Option<Size>>>>: UnsafeUnpin,
*const RcInner<dyn WidgetStateProperty<Option<BorderSide>>> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn WidgetStateProperty<Option<BorderSide>>>>: UnsafeUnpin,
*const RcInner<dyn WidgetStateProperty<Option<OutlinedBorderRef>>> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn WidgetStateProperty<Option<OutlinedBorderRef>>>>: UnsafeUnpin,
*const RcInner<dyn WidgetStateProperty<Option<Rc<dyn MouseCursor>>>> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn WidgetStateProperty<Option<Rc<dyn MouseCursor>>>>>: UnsafeUnpin,
PhantomData<fn() -> LayerLink>: UnsafeUnpin,
*const RcInner<dyn Fn(&mut App)> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Fn(&mut App)>>: UnsafeUnpin,
*const RcInner<dyn Fn(&mut App, AnimationStatus)> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Fn(&mut App, AnimationStatus)>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<Rc<dyn Widget>>: UnsafeUnpin,
*const RcInner<dyn Fn(&mut App, AnyElement, AnyMenuController, Option<&Rc<dyn Widget>>) -> Rc<dyn Widget>> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Fn(&mut App, AnyElement, AnyMenuController, Option<&Rc<dyn Widget>>) -> Rc<dyn Widget>>>: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
*const RcInner<dyn Widget> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Widget>>: UnsafeUnpin,
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<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
impl<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.