Skip to main content

MenuState

Struct MenuState 

Source
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

Source

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.

Source

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.

Source

pub const fn modal(self, modal: bool) -> Self

Contain Tab focus inside the popup and expect a mounted backdrop, Base UI’s modal.

Source

pub const fn orientation(self, orientation: MenuOrientation) -> Self

Move the highlight along the other axis, Base UI’s Root orientation.

Source

pub const fn loop_focus(self, loop_focus: bool) -> Self

Wrap the highlight at the ends of the list, Base UI’s Root loop.

Source

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.

Source

pub fn disabled(self, disabled: bool) -> Self

Refuse to open at all, Base UI’s Root disabled.

Source

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.

Source

pub fn delay(self, delay: Duration) -> Self

Set how long a hovered trigger waits before opening, Base UI’s delay.

Source

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.

Source

pub const fn hoverable_popup(self, hoverable: bool) -> Self

Choose whether hovering the popup itself keeps a hover-opened menu open.

Source

pub const fn placement(self, placement: AnchorPlacement) -> Self

Prefer a full placement for the popup, Base UI’s Positioner side plus align.

Source

pub const fn side(self, side: AnchorSide) -> Self

Prefer one side of the anchor, Base UI’s Positioner side.

Source

pub const fn align(self, align: AnchorAlign) -> Self

Prefer a cross-axis alignment, Base UI’s Positioner align.

Source

pub fn side_offset(self, offset: f32) -> Self

Set the distance between the anchor and the positioner, Base UI’s sideOffset.

Source

pub fn align_offset(self, offset: f32) -> Self

Shift the popup along its cross axis before collision handling, Base UI’s alignOffset.

Source

pub fn collision_padding(self, padding: f32) -> Self

Set the collision padding kept inside the viewport, Base UI’s collisionPadding.

Source

pub const fn sticky(self, sticky: bool) -> Self

Keep the popup clamped inside the viewport, Base UI’s sticky.

Source

pub fn arrow_size(self, size: f32) -> Self

Declare the edge length of a caller-painted arrow so QuickGUI can centre it.

Source

pub fn arrow_padding(self, padding: f32) -> Self

Keep a centred arrow clear of the popup’s corners.

Source

pub const fn is_open(&self) -> bool

Source

pub const fn is_disabled(&self) -> bool

Source

pub const fn is_modal(&self) -> bool

Source

pub const fn orientation_value(&self) -> MenuOrientation

Source

pub const fn loops_focus(&self) -> bool

Source

pub const fn closes_parent_on_esc(&self) -> bool

Source

pub const fn opens_on_hover(&self) -> bool

Source

pub const fn is_pending(&self) -> bool

Whether a hover deadline is currently outstanding.

Source

pub const fn trigger_id(&self) -> ElementId

Source

pub const fn popup_id(&self) -> ElementId

Source

pub fn positioner_id(&self) -> ElementId

Source

pub fn backdrop_id(&self) -> ElementId

Source

pub fn arrow_id(&self) -> ElementId

Source

pub fn popover(&self) -> Popover

The composed popover descriptor, for callers that need its remaining parts directly.

Source

pub fn resolved_side(&self) -> AnchorSide

The side the popup actually opened on, or the declared preference before the first frame.

Source

pub fn resolved_align(&self) -> AnchorAlign

The cross-axis alignment the popup actually used, or the declared preference.

Source

pub fn state(&self) -> MenuPartState

A copyable render-state snapshot the application styles from.

Source

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.

Source

pub fn open_now(&mut self) -> bool

Open immediately, cancelling any outstanding deadline.

Source

pub fn close_now(&mut self) -> bool

Close immediately, cancelling any outstanding deadline.

Source

pub fn toggle(&mut self) -> bool

Toggle immediately, cancelling any outstanding deadline.

Source

pub fn cancel_pending(&mut self)

Drop any outstanding hover deadline without changing the open state.

Source

pub fn root_with(&self, root: Element) -> Element

Decorate the optional application-owned structural wrapper, Base UI’s Menu.Root.

Source

pub fn root(&self) -> Element

Create the unstyled root part. Use Self::root_with to supply an existing element.

Source

pub fn submenu_root_with(&self, root: Element) -> Element

Decorate a nested level’s structural wrapper, Base UI’s Menu.SubmenuRoot.

Source

pub fn submenu_root(&self) -> Element

Create the unstyled submenu root part. Use Self::submenu_root_with to supply an existing element.

Source

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
where Change: Fn(&mut V, bool, &mut EventContext) + Clone + 'static,

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.

Source

pub fn trigger<V: 'static, Change>( &self, cx: &mut ViewContext<'_, V>, access: fn(&mut V) -> &mut Self, on_open_change: Change, ) -> Element
where Change: Fn(&mut V, bool, &mut EventContext) + Clone + 'static,

Create the unstyled trigger part. Use Self::trigger_with to supply an existing element.

Source

pub fn trigger_with_accessor<V: 'static, Change>( &self, cx: &mut ViewContext<'_, V>, access: StateAccessor<V, Self>, on_open_change: Change, trigger: Element, ) -> Element
where Change: Fn(&mut V, bool, &mut EventContext) + Clone + 'static,

Decorate a caller-owned trigger through a per-instance accessor.

Source

pub fn submenu_trigger_with<V: 'static, Change>( &self, cx: &mut ViewContext<'_, V>, access: fn(&mut V) -> &mut Self, on_open_change: Change, trigger: Element, ) -> Element
where Change: Fn(&mut V, bool, &mut EventContext) + Clone + 'static,

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.

Source

pub fn submenu_trigger<V: 'static, Change>( &self, cx: &mut ViewContext<'_, V>, access: fn(&mut V) -> &mut Self, on_open_change: Change, ) -> Element
where Change: Fn(&mut V, bool, &mut EventContext) + Clone + 'static,

Create the unstyled submenu trigger part. Use Self::submenu_trigger_with to supply an existing element.

Source

pub fn submenu_trigger_with_accessor<V: 'static, Change>( &self, cx: &mut ViewContext<'_, V>, access: StateAccessor<V, Self>, on_open_change: Change, trigger: Element, ) -> Element
where Change: Fn(&mut V, bool, &mut EventContext) + Clone + 'static,

Decorate a caller-owned submenu trigger through a per-instance accessor.

Source

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.

Source

pub fn portal(&self) -> Element

Create the unstyled portal part. Use Self::portal_with to supply an existing element.

Source

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.

Source

pub fn positioner(&self) -> Element

Create the unstyled positioner part. Use Self::positioner_with to supply an existing element.

Source

pub fn backdrop_with(&self, backdrop: Element) -> Element

Decorate an optional caller-painted viewport backdrop, Base UI’s Menu.Backdrop.

Source

pub fn backdrop(&self) -> Element

Create the unstyled backdrop part. Use Self::backdrop_with to supply an existing element.

Source

pub fn arrow_with(&self, arrow: Element) -> Element

Position a caller-owned arrow on the edge the popup actually opened against.

Source

pub fn arrow(&self) -> Element

Create the unstyled arrow part. Use Self::arrow_with to supply an existing element.

Source

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
where Change: Fn(&mut V, bool, &mut EventContext) + Clone + 'static,

Decorate the caller-owned popup, Base UI’s Menu.Popup.

Source

pub fn popup<V: 'static, Change>( &self, cx: &mut ViewContext<'_, V>, access: fn(&mut V) -> &mut Self, on_open_change: Change, ) -> Element
where Change: Fn(&mut V, bool, &mut EventContext) + Clone + 'static,

Create the unstyled popup part. Use Self::popup_with to supply an existing element.

Source

pub fn popup_with_accessor<V: 'static, Change>( &self, cx: &mut ViewContext<'_, V>, access: StateAccessor<V, Self>, on_open_change: Change, popup: Element, ) -> Element
where Change: Fn(&mut V, bool, &mut EventContext) + Clone + 'static,

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.

Source

pub fn dismiss_listener<V: 'static, Change>( &self, cx: &mut ViewContext<'_, V>, access: fn(&mut V) -> &mut Self, on_open_change: Change, ) -> DismissListener<V>
where Change: Fn(&mut V, bool, &mut EventContext) + 'static,

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.

Source

pub fn dismiss_listener_with<V: 'static, Change>( &self, cx: &mut ViewContext<'_, V>, access: StateAccessor<V, Self>, on_open_change: Change, ) -> DismissListener<V>
where Change: Fn(&mut V, bool, &mut EventContext) + 'static,

Build the popup’s dismissal behavior against a per-instance accessor.

Trait Implementations§

Source§

impl Debug for MenuState

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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 for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more