pub struct MenuState { /* private fields */ }Expand description
Bounded controlled state for one unstyled menu surface built from Base UI’s compound parts.
PopoverMenu is the row model — items, highlighting, typeahead, activation. MenuState is
the surface around it: the controlled open flag, Base UI’s Menu.Root props, the anchored
in-window placement its popup uses, and the exact hover deadlines an openOnHover trigger or a
submenu trigger needs. Compose the two by mounting Self::popup_with and putting the model’s
PopoverMenu::element tree inside it.
QuickGUI owns the trigger’s semantics and relationships, portal/positioner anchoring with flip and shift, the resolved-placement report the arrow follows, Escape and outside-press dismissal, focus restoration, and modal focus containment. The application owns every visual declaration.
A closed menu owns no task, timer, observer, or idle scheduler source. An open one owns at most a single pending hover deadline.
Implementations§
Source§impl MenuState
impl MenuState
Sourcepub fn new(
trigger_id: impl Into<ElementId>,
popup_id: impl Into<ElementId>,
) -> Self
pub fn new( trigger_id: impl Into<ElementId>, popup_id: impl Into<ElementId>, ) -> Self
Create a closed menu over caller-owned trigger and popup identities.
Sourcepub fn with_open(self, open: bool) -> Self
pub fn with_open(self, open: bool) -> Self
Declare the menu open or closed, Base UI’s Root open prop.
A disabled menu stays closed.
Sourcepub const fn modal(self, modal: bool) -> Self
pub const fn modal(self, modal: bool) -> Self
Contain Tab focus inside the popup and expect a mounted backdrop, Base UI’s modal.
Sourcepub const fn orientation(self, orientation: MenuOrientation) -> Self
pub const fn orientation(self, orientation: MenuOrientation) -> Self
Move the highlight along the other axis, Base UI’s Root orientation.
Sourcepub const fn loop_focus(self, loop_focus: bool) -> Self
pub const fn loop_focus(self, loop_focus: bool) -> Self
Wrap the highlight at the ends of the list, Base UI’s Root loop.
Sourcepub const fn close_parent_on_esc(self, close_parent: bool) -> Self
pub const fn close_parent_on_esc(self, close_parent: bool) -> Self
Close the level above too when Escape dismisses this one, Base UI’s closeParentOnEsc.
Sourcepub const fn open_on_hover(self, open_on_hover: bool) -> Self
pub const fn open_on_hover(self, open_on_hover: bool) -> Self
Open the menu when the pointer rests on its trigger, Base UI’s Trigger openOnHover.
Sourcepub fn delay(self, delay: Duration) -> Self
pub fn delay(self, delay: Duration) -> Self
Set how long a hovered trigger waits before opening, Base UI’s delay.
Sourcepub fn close_delay(self, close_delay: Duration) -> Self
pub fn close_delay(self, close_delay: Duration) -> Self
Set how long the menu waits before closing once the pointer leaves, Base UI’s closeDelay.
Defaults to DEFAULT_MENU_CLOSE_DELAY so the pointer can cross into a submenu popup.
Sourcepub const fn hoverable_popup(self, hoverable: bool) -> Self
pub const fn hoverable_popup(self, hoverable: bool) -> Self
Choose whether hovering the popup itself keeps a hover-opened menu open.
Sourcepub const fn placement(self, placement: AnchorPlacement) -> Self
pub const fn placement(self, placement: AnchorPlacement) -> Self
Prefer a full placement for the popup, Base UI’s Positioner side plus align.
Sourcepub const fn side(self, side: AnchorSide) -> Self
pub const fn side(self, side: AnchorSide) -> Self
Prefer one side of the anchor, Base UI’s Positioner side.
Sourcepub const fn align(self, align: AnchorAlign) -> Self
pub const fn align(self, align: AnchorAlign) -> Self
Prefer a cross-axis alignment, Base UI’s Positioner align.
Sourcepub fn side_offset(self, offset: f32) -> Self
pub fn side_offset(self, offset: f32) -> Self
Set the distance between the anchor and the positioner, Base UI’s sideOffset.
Sourcepub fn align_offset(self, offset: f32) -> Self
pub fn align_offset(self, offset: f32) -> Self
Shift the popup along its cross axis before collision handling, Base UI’s alignOffset.
Sourcepub fn collision_padding(self, padding: f32) -> Self
pub fn collision_padding(self, padding: f32) -> Self
Set the collision padding kept inside the viewport, Base UI’s collisionPadding.
Sourcepub const fn sticky(self, sticky: bool) -> Self
pub const fn sticky(self, sticky: bool) -> Self
Keep the popup clamped inside the viewport, Base UI’s sticky.
Sourcepub fn arrow_size(self, size: f32) -> Self
pub fn arrow_size(self, size: f32) -> Self
Declare the edge length of a caller-painted arrow so QuickGUI can centre it.
Sourcepub fn arrow_padding(self, padding: f32) -> Self
pub fn arrow_padding(self, padding: f32) -> Self
Keep a centred arrow clear of the popup’s corners.
pub const fn is_open(&self) -> bool
pub const fn is_disabled(&self) -> bool
pub const fn is_modal(&self) -> bool
pub const fn orientation_value(&self) -> MenuOrientation
pub const fn loops_focus(&self) -> bool
pub const fn closes_parent_on_esc(&self) -> bool
pub const fn opens_on_hover(&self) -> bool
Sourcepub const fn is_pending(&self) -> bool
pub const fn is_pending(&self) -> bool
Whether a hover deadline is currently outstanding.
pub const fn trigger_id(&self) -> ElementId
pub const fn popup_id(&self) -> ElementId
pub fn positioner_id(&self) -> ElementId
pub fn backdrop_id(&self) -> ElementId
pub fn arrow_id(&self) -> ElementId
Sourcepub fn popover(&self) -> Popover
pub fn popover(&self) -> Popover
The composed popover descriptor, for callers that need its remaining parts directly.
Sourcepub fn resolved_side(&self) -> AnchorSide
pub fn resolved_side(&self) -> AnchorSide
The side the popup actually opened on, or the declared preference before the first frame.
Sourcepub fn resolved_align(&self) -> AnchorAlign
pub fn resolved_align(&self) -> AnchorAlign
The cross-axis alignment the popup actually used, or the declared preference.
Sourcepub fn state(&self) -> MenuPartState
pub fn state(&self) -> MenuPartState
A copyable render-state snapshot the application styles from.
Sourcepub fn set_open(&mut self, open: bool) -> bool
pub fn set_open(&mut self, open: bool) -> bool
Force the open value, cancelling any outstanding deadline. Returns whether it changed.
A disabled menu never opens.
Sourcepub fn cancel_pending(&mut self)
pub fn cancel_pending(&mut self)
Drop any outstanding hover deadline without changing the open state.
Sourcepub fn root_with(&self, root: Element) -> Element
pub fn root_with(&self, root: Element) -> Element
Decorate the optional application-owned structural wrapper, Base UI’s Menu.Root.
Sourcepub fn root(&self) -> Element
pub fn root(&self) -> Element
Create the unstyled root part. Use Self::root_with to supply an existing element.
Decorate a nested level’s structural wrapper, Base UI’s Menu.SubmenuRoot.
Create the unstyled submenu root part. Use Self::submenu_root_with to supply an existing element.
Sourcepub fn trigger_with<V: 'static, Change>(
&self,
cx: &mut ViewContext<'_, V>,
access: fn(&mut V) -> &mut Self,
on_open_change: Change,
trigger: Element,
) -> Element
pub fn trigger_with<V: 'static, Change>( &self, cx: &mut ViewContext<'_, V>, access: fn(&mut V) -> &mut Self, on_open_change: Change, trigger: Element, ) -> Element
Decorate a caller-owned trigger, Base UI’s Menu.Trigger.
Clicking toggles the menu. With Self::open_on_hover the pointer opens it after
Self::delay and closes it after Self::close_delay, both exact one-shot deadlines: a
pointer that returns before the deadline cancels it rather than reopening, and a zero delay
applies the change in the same controlled update with no task at all.
Sourcepub fn trigger<V: 'static, Change>(
&self,
cx: &mut ViewContext<'_, V>,
access: fn(&mut V) -> &mut Self,
on_open_change: Change,
) -> Element
pub fn trigger<V: 'static, Change>( &self, cx: &mut ViewContext<'_, V>, access: fn(&mut V) -> &mut Self, on_open_change: Change, ) -> Element
Create the unstyled trigger part. Use Self::trigger_with to supply an existing element.
Sourcepub fn trigger_with_accessor<V: 'static, Change>(
&self,
cx: &mut ViewContext<'_, V>,
access: StateAccessor<V, Self>,
on_open_change: Change,
trigger: Element,
) -> Element
pub fn trigger_with_accessor<V: 'static, Change>( &self, cx: &mut ViewContext<'_, V>, access: StateAccessor<V, Self>, on_open_change: Change, trigger: Element, ) -> Element
Decorate a caller-owned trigger through a per-instance accessor.
Decorate a caller-owned submenu trigger, Base UI’s Menu.SubmenuTrigger.
A submenu trigger is a row of its parent menu, so it keeps menuitem semantics rather than
button semantics. Declare Self::open_on_hover for the native dwell-to-open behavior.
Create the unstyled submenu trigger part. Use Self::submenu_trigger_with to supply an existing element.
Decorate a caller-owned submenu trigger through a per-instance accessor.
Sourcepub fn portal_with(&self, portal: Element) -> Element
pub fn portal_with(&self, portal: Element) -> Element
Decorate the caller-owned portal boundary, Base UI’s Menu.Portal.
QuickGUI’s retained overlay node is itself the portal, so this is the same boundary as
Self::positioner_with; mount exactly one of them.
Sourcepub fn portal(&self) -> Element
pub fn portal(&self) -> Element
Create the unstyled portal part. Use Self::portal_with to supply an existing element.
Sourcepub fn positioner_with(&self, positioner: Element) -> Element
pub fn positioner_with(&self, positioner: Element) -> Element
Decorate the caller-owned positioner, Base UI’s Menu.Positioner.
The positioner publishes the placement it resolved to, so Self::arrow_with and
Self::state follow the real side after a flip instead of the declared preference.
Sourcepub fn positioner(&self) -> Element
pub fn positioner(&self) -> Element
Create the unstyled positioner part. Use Self::positioner_with to supply an existing element.
Sourcepub fn backdrop_with(&self, backdrop: Element) -> Element
pub fn backdrop_with(&self, backdrop: Element) -> Element
Decorate an optional caller-painted viewport backdrop, Base UI’s Menu.Backdrop.
Sourcepub fn backdrop(&self) -> Element
pub fn backdrop(&self) -> Element
Create the unstyled backdrop part. Use Self::backdrop_with to supply an existing element.
Sourcepub fn arrow_with(&self, arrow: Element) -> Element
pub fn arrow_with(&self, arrow: Element) -> Element
Position a caller-owned arrow on the edge the popup actually opened against.
Sourcepub fn arrow(&self) -> Element
pub fn arrow(&self) -> Element
Create the unstyled arrow part. Use Self::arrow_with to supply an existing element.
Sourcepub fn popup_with<V: 'static, Change>(
&self,
cx: &mut ViewContext<'_, V>,
access: fn(&mut V) -> &mut Self,
on_open_change: Change,
popup: Element,
) -> Element
pub fn popup_with<V: 'static, Change>( &self, cx: &mut ViewContext<'_, V>, access: fn(&mut V) -> &mut Self, on_open_change: Change, popup: Element, ) -> Element
Decorate the caller-owned popup, Base UI’s Menu.Popup.
Sourcepub fn popup<V: 'static, Change>(
&self,
cx: &mut ViewContext<'_, V>,
access: fn(&mut V) -> &mut Self,
on_open_change: Change,
) -> Element
pub fn popup<V: 'static, Change>( &self, cx: &mut ViewContext<'_, V>, access: fn(&mut V) -> &mut Self, on_open_change: Change, ) -> Element
Create the unstyled popup part. Use Self::popup_with to supply an existing element.
Sourcepub fn popup_with_accessor<V: 'static, Change>(
&self,
cx: &mut ViewContext<'_, V>,
access: StateAccessor<V, Self>,
on_open_change: Change,
popup: Element,
) -> Element
pub fn popup_with_accessor<V: 'static, Change>( &self, cx: &mut ViewContext<'_, V>, access: StateAccessor<V, Self>, on_open_change: Change, popup: Element, ) -> Element
Decorate the caller-owned popup through a per-instance accessor.
The popup dismisses on Escape and on an outside press and restores trigger focus. When
Self::close_parent_on_esc is set it additionally dispatches MenuCloseParent, which
travels the focus path to the level above and closes it too.
Sourcepub fn dismiss_listener<V: 'static, Change>(
&self,
cx: &mut ViewContext<'_, V>,
access: fn(&mut V) -> &mut Self,
on_open_change: Change,
) -> DismissListener<V>
pub fn dismiss_listener<V: 'static, Change>( &self, cx: &mut ViewContext<'_, V>, access: fn(&mut V) -> &mut Self, on_open_change: Change, ) -> DismissListener<V>
Build the popup’s dismissal behavior for Escape and outside presses.
Self::popup_with attaches this already; build it directly only when the application
composes the popup element itself.
Sourcepub fn dismiss_listener_with<V: 'static, Change>(
&self,
cx: &mut ViewContext<'_, V>,
access: StateAccessor<V, Self>,
on_open_change: Change,
) -> DismissListener<V>
pub fn dismiss_listener_with<V: 'static, Change>( &self, cx: &mut ViewContext<'_, V>, access: StateAccessor<V, Self>, on_open_change: Change, ) -> DismissListener<V>
Build the popup’s dismissal behavior against a per-instance accessor.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for MenuState
impl !Send for MenuState
impl !Sync for MenuState
impl !UnwindSafe for MenuState
impl Forget for MenuState
impl Freeze for MenuState
impl Move 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.