跳到正文

Menu

可完全组合的菜单,支持子菜单、分组、链接、复选项和单选项。

正在加载交互演示…

#导入

从 quickgui 导入 PopoverMenu。

use quickgui::*;

#用法

let menu = PopoverMenu::new("actions", &state);
menu.root().child(menu.trigger().child("Actions"))

#结构

  • PopoverMenu::root
  • PopoverMenu::trigger
  • PopoverMenu::portal
  • PopoverMenu::backdrop
  • PopoverMenu::positioner
  • PopoverMenu::popup
  • PopoverMenu::arrow
  • PopoverMenu::item
  • PopoverMenu::link_item
  • PopoverMenu::submenu_root
  • PopoverMenu::submenu_trigger
  • PopoverMenu::group
  • PopoverMenu::group_label
  • PopoverMenu::radio_group
  • PopoverMenu::radio_item
  • PopoverMenu::radio_item_indicator
  • PopoverMenu::checkbox_item
  • PopoverMenu::checkbox_item_indicator
  • PopoverMenu::separator

#API 参考

展开条目查看说明和完整签名。短横线表示声明中未记录默认值。

PopoverMenu

查看源码
pub fn new(items: impl IntoIterator<Item = PopoverMenuItem>) -> Result<Self, PopoverMenuError>
itemspub fn items(&self) -> &[PopoverMenuItem]—

Configures items for this part.

pub fn items(&self) -> &[PopoverMenuItem]
查看源码
active_indexpub const fn active_index(&self) -> Option<usize>—

Configures active index for this part.

pub const fn active_index(&self) -> Option<usize>
查看源码
active_itempub fn active_item(&self) -> Option<&PopoverMenuItem>—

Configures active item for this part.

pub fn active_item(&self) -> Option<&PopoverMenuItem>
查看源码
loops_focuspub const fn loops_focus(&self) -> bool—

Configures loops focus for this part.

pub const fn loops_focus(&self) -> bool
查看源码
loop_focuspub const fn loop_focus(mut self, enabled: bool) -> Self—

Configures loop focus for this part.

pub const fn loop_focus(mut self, enabled: bool) -> Self
查看源码
orientation_valuepub const fn orientation_value(&self) -> MenuOrientation—

The axis this menu's roving highlight moves along, Base UI's Root `orientation`.

pub const fn orientation_value(&self) -> MenuOrientation
查看源码
orientationpub const fn orientation(mut self, orientation: MenuOrientation) -> Self—

Move the roving highlight along the other axis, Base UI's Root `orientation`. A horizontal menu installs [`POPOVER_MENU_HORIZONTAL_KEY_CONTEXT`] instead of [`POPOVER_MENU_KEY_CONTEXT`], so Left and Right move between top-level triggers and Down opens the highlighted submenu. Nothing else about the model changes.

pub const fn orientation(mut self, orientation: MenuOrientation) -> Self
查看源码
set_orientationpub const fn set_orientation(&mut self, orientation: MenuOrientation) -> bool—

Replace the orientation in place, reporting whether it changed.

pub const fn set_orientation(&mut self, orientation: MenuOrientation) -> bool
查看源码
radio_valuepub fn radio_value(&self, group: impl Into<ElementId>) -> Option<ElementId>—

The item currently checked in one radio group, Base UI's `Menu.RadioGroup` `value`.

pub fn radio_value(&self, group: impl Into<ElementId>) -> Option<ElementId>
查看源码
set_radio_valuepub fn set_radio_value( &mut self, group: impl Into<ElementId>, value: impl Into<ElementId>, ) -> bool—

Check exactly one item in a radio group, Base UI's `Menu.RadioGroup` `onValueChange`. Every other item in the group is unchecked in the same update, so a group can never retain two checked values. Returns whether anything changed; an item ID that is not a radio item in `group` changes nothing.

pub fn set_radio_value( &mut self, group: impl Into<ElementId>, value: impl Into<ElementId>, ) -> bool
查看源码
set_itemspub fn set_items( &mut self, items: impl IntoIterator<Item = PopoverMenuItem>, ) -> Result<bool, PopoverMenuError>—

Atomically replace the menu contents while preserving the highlighted stable ID.

pub fn set_items( &mut self, items: impl IntoIterator<Item = PopoverMenuItem>, ) -> Result<bool, PopoverMenuError>
查看源码
highlightpub fn highlight(&mut self, index: usize) -> bool—

Configures highlight for this part.

pub fn highlight(&mut self, index: usize) -> bool
查看源码
unhighlightpub fn unhighlight(&mut self, index: usize) -> bool—

Drop the highlight from `index` when the pointer leaves it, returning whether it changed. A native menu shows no highlighted row once the pointer has left the surface, so a row the pointer lit up goes dark when it leaves; a highlight the keyboard moved elsewhere in the meantime is left alone.

pub fn unhighlight(&mut self, index: usize) -> bool
查看源码
select_previouspub fn select_previous(&mut self) -> bool—

Configures select previous for this part.

pub fn select_previous(&mut self) -> bool
查看源码
select_nextpub fn select_next(&mut self) -> bool—

Configures select next for this part.

pub fn select_next(&mut self) -> bool
查看源码
select_firstpub fn select_first(&mut self) -> bool—

Configures select first for this part.

pub fn select_first(&mut self) -> bool
查看源码
select_lastpub fn select_last(&mut self) -> bool—

Configures select last for this part.

pub fn select_last(&mut self) -> bool
查看源码
typeaheadpub fn typeahead(&mut self, value: &str, now: Instant) -> bool—

Update bounded typeahead state and highlight the next prefix match. `now` is supplied by the caller so deterministic tests do not depend on wall-clock sleeps. The return value reports whether the highlighted item changed.

pub fn typeahead(&mut self, value: &str, now: Instant) -> bool
查看源码
activate_activepub fn activate_active(&mut self) -> Option<PopoverMenuActivation>—

Configures activate active for this part.

pub fn activate_active(&mut self) -> Option<PopoverMenuActivation>
查看源码
activatepub fn activate(&mut self, index: usize) -> Option<PopoverMenuActivation>—

Configures activate for this part.

pub fn activate(&mut self, index: usize) -> Option<PopoverMenuActivation>
查看源码
item_statepub fn item_state(&self, index: usize) -> Option<PopoverMenuItemState>—

Configures item state for this part.

pub fn item_state(&self, index: usize) -> Option<PopoverMenuItemState>
查看源码
item_element_idpub fn item_element_id( &self, menu_id: impl Into<ElementId>, index: usize, ) -> Option<ElementId>—

Resolve the retained element identity for an interactive item or structural group label. Interactive identity follows the application's stable item ID. A group label has no command identity, so its accessibility-only identity is derived from the menu root and bounded structural index. Separators intentionally remain anonymous.

pub fn item_element_id( &self, menu_id: impl Into<ElementId>, index: usize, ) -> Option<ElementId>
查看源码
item_render_statepub fn item_render_state(&self, index: usize, submenu_open: bool) -> Option<MenuItemPartState>—

The Base UI-named render snapshot for one row. Returns `None` for an index outside the retained model. `submenu_open` reports whether this row's submenu is currently mounted; it is ignored for rows that have none.

pub fn item_render_state(&self, index: usize, submenu_open: bool) -> Option<MenuItemPartState>
查看源码

PopoverMenu::root_with

查看源码
pub fn root_with(&self, id: impl Into<ElementId>, root: Element) -> Element

Decorate a caller-owned menu root with focus, keyboard, drag-region, and accessibility semantics without adding any appearance.

PopoverMenu::root

查看源码
pub fn root(&self, id: impl Into<ElementId>) -> Element

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

PopoverMenu::item_with

查看源码
pub fn item_with( &self, menu_id: impl Into<ElementId>, index: usize, item_root: Element, ) -> Option<Element>

Decorate one caller-owned row with its exact menu-item semantics and stable derived ID.

PopoverMenu::item

查看源码
pub fn item(&self, menu_id: impl Into<ElementId>, index: usize) -> Option<Element>

Create the unstyled item part. Use [`Self::item_with`] to supply an existing element.

PopoverMenu::group_with

查看源码
pub fn group_with(group: Element) -> Element

Decorate an application-composed wrapper around a related item group.

PopoverMenu::group

查看源码
pub fn group() -> Element

Create the unstyled group part. Use [`Self::group_with`] to supply an existing element.

PopoverMenu::labeled_group_with

查看源码
pub fn labeled_group_with( &self, menu_id: impl Into<ElementId>, label_index: usize, group: Element, ) -> Option<Element>

Decorate a caller-composed item group and name it from one mounted group-label row. Returns `None` when `label_index` is not a group label. The caller owns visual nesting and layout; this helper adds only the native group role and mounted `labelled-by` relationship.

PopoverMenu::labeled_group

查看源码
pub fn labeled_group( &self, menu_id: impl Into<ElementId>, label_index: usize, ) -> Option<Element>

Create the unstyled labeled group part. Use [`Self::labeled_group_with`] to supply an existing element.

PopoverMenu::checkbox_item_with

查看源码
pub fn checkbox_item_with( &self, menu_id: impl Into<ElementId>, index: usize, item_root: Element, ) -> Option<Element>

Decorate a checkbox row, Base UI's `Menu.CheckboxItem`. This is the kind-checked Base UI-named alias of [`Self::item_with`]: it returns `None` when `index` is not a checkbox row, so a composition that renders parts by name cannot silently mount the wrong semantics.

PopoverMenu::checkbox_item

查看源码
pub fn checkbox_item(&self, menu_id: impl Into<ElementId>, index: usize) -> Option<Element>

Create the unstyled checkbox item part. Use [`Self::checkbox_item_with`] to supply an existing element.

PopoverMenu::radio_item_with

查看源码
pub fn radio_item_with( &self, menu_id: impl Into<ElementId>, index: usize, item_root: Element, ) -> Option<Element>

Decorate a radio row, Base UI's `Menu.RadioItem`.

PopoverMenu::radio_item

查看源码
pub fn radio_item(&self, menu_id: impl Into<ElementId>, index: usize) -> Option<Element>

Create the unstyled radio item part. Use [`Self::radio_item_with`] to supply an existing element.

查看源码
pub fn link_item_with( &self, menu_id: impl Into<ElementId>, index: usize, item_root: Element, ) -> Option<Element>

Decorate a link row, Base UI's `Menu.LinkItem`.

查看源码
pub fn link_item(&self, menu_id: impl Into<ElementId>, index: usize) -> Option<Element>

Create the unstyled link item part. Use [`Self::link_item_with`] to supply an existing element.

PopoverMenu::submenu_trigger_with

查看源码
pub fn submenu_trigger_with( &self, menu_id: impl Into<ElementId>, index: usize, open: bool, item_root: Element, ) -> Option<Element>

Decorate a submenu row, Base UI's `Menu.SubmenuTrigger`. The row already declares `has-popup` and `menuitem`; `open` adds the expanded state that Base UI publishes as `data-popup-open` while the child level is mounted.

PopoverMenu::submenu_trigger

查看源码
pub fn submenu_trigger( &self, menu_id: impl Into<ElementId>, index: usize, open: bool, ) -> Option<Element>

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

PopoverMenu::separator_with

查看源码
pub fn separator_with( &self, menu_id: impl Into<ElementId>, index: usize, item_root: Element, ) -> Option<Element>

Decorate a separator row, Base UI's `Menu.Separator`.

PopoverMenu::separator

查看源码
pub fn separator(&self, menu_id: impl Into<ElementId>, index: usize) -> Option<Element>

Create the unstyled separator part. Use [`Self::separator_with`] to supply an existing element.

PopoverMenu::group_label_with

查看源码
pub fn group_label_with( &self, menu_id: impl Into<ElementId>, index: usize, item_root: Element, ) -> Option<Element>

Decorate a group-label row, Base UI's `Menu.GroupLabel`.

PopoverMenu::group_label

查看源码
pub fn group_label(&self, menu_id: impl Into<ElementId>, index: usize) -> Option<Element>

Create the unstyled group label part. Use [`Self::group_label_with`] to supply an existing element.

PopoverMenu::radio_group_with

查看源码
pub fn radio_group_with(group: Element) -> Element

Decorate a caller-composed radio group, Base UI's `Menu.RadioGroup`. The group carries the native radio-group role so assistive technology reports "one of three" for its items. Membership itself stays in the model: every row built with [`PopoverMenuItem::radio`] names the group it belongs to, and [`Self::set_radio_value`] keeps exactly one of them checked.

PopoverMenu::radio_group

查看源码
pub fn radio_group() -> Element

Create the unstyled radio group part. Use [`Self::radio_group_with`] to supply an existing element.

PopoverMenu::labeled_radio_group_with

查看源码
pub fn labeled_radio_group_with( &self, menu_id: impl Into<ElementId>, label_index: usize, group: Element, ) -> Option<Element>

Decorate a caller-composed radio group and name it from one mounted group-label row. Returns `None` when `label_index` is not a group label.

PopoverMenu::labeled_radio_group

查看源码
pub fn labeled_radio_group( &self, menu_id: impl Into<ElementId>, label_index: usize, ) -> Option<Element>

Create the unstyled labeled radio group part. Use [`Self::labeled_radio_group_with`] to supply an existing element.

PopoverMenu::checkbox_item_indicator_with

查看源码
pub fn checkbox_item_indicator_with(indicator: Element) -> Element

Decorate a caller-owned checkbox indicator, Base UI's `Menu.CheckboxItemIndicator`. The indicator is decoration: the row it sits in already carries the checked state, so mounting a second announcement would make assistive technology read the value twice. Mount it only while the row is checked, exactly as Base UI does.

PopoverMenu::checkbox_item_indicator

查看源码
pub fn checkbox_item_indicator() -> Element

Create the unstyled checkbox item indicator part. Use [`Self::checkbox_item_indicator_with`] to supply an existing element.

PopoverMenu::radio_item_indicator_with

查看源码
pub fn radio_item_indicator_with(indicator: Element) -> Element

Decorate a caller-owned radio indicator, Base UI's `Menu.RadioItemIndicator`.

PopoverMenu::radio_item_indicator

查看源码
pub fn radio_item_indicator() -> Element

Create the unstyled radio item indicator part. Use [`Self::radio_item_indicator_with`] to supply an existing element.

PopoverMenu::element

查看源码
pub fn element<V, Render, Dismiss>( &self, cx: &mut ViewContext<'_, V>, id: impl Into<ElementId>, access: fn(&mut V) -> &mut PopoverMenu, root: Element, render_item: Render, dismiss: Dismiss, ) -> Element where V: 'static, Render: Fn(&PopoverMenuItem, PopoverMenuItemState) -> Element, Dismiss: Fn(&mut V, &mut EventContext) + Clone + 'static,

Build the complete unstyled interaction layer for one menu level. `render_item` owns all row geometry, colors, indicators, icons, and typography. Commands dispatch through the popover owner's ordinary typed-action path before `dismiss` runs.

PopoverMenu::element_with_submenus

查看源码
pub fn element_with_submenus<V, Render, Dismiss, OpenSubmenu>( &self, cx: &mut ViewContext<'_, V>, id: impl Into<ElementId>, access: fn(&mut V) -> &mut PopoverMenu, root: Element, render_item: Render, dismiss: Dismiss, open_submenu: OpenSubmenu, ) -> Element where V: 'static, Render: Fn(&PopoverMenuItem, PopoverMenuItemState) -> Element, Dismiss: Fn(&mut V, &mut EventContext) + Clone + 'static, OpenSubmenu: Fn(&mut V, ElementId, PopoverMenu, &mut EventContext) + Clone + 'static,

Build the complete unstyled interaction layer and expose submenu activation to the owner.

PopoverMenu::element_with_submenus_and_hover

查看源码
pub fn element_with_submenus_and_hover<V, Render, Dismiss, OpenSubmenu, HoverItem>( &self, cx: &mut ViewContext<'_, V>, id: impl Into<ElementId>, access: fn(&mut V) -> &mut PopoverMenu, root: Element, render_item: Render, dismiss: Dismiss, open_submenu: OpenSubmenu, hover_item: HoverItem, ) -> Element where V: 'static, Render: Fn(&PopoverMenuItem, PopoverMenuItemState) -> Element, Dismiss: Fn(&mut V, &mut EventContext) + Clone + 'static, OpenSubmenu: Fn(&mut V, ElementId, PopoverMenu, &mut EventContext) + Clone + 'static, HoverItem: Fn(&mut V, usize, bool, &mut EventContext) + Clone + 'static,

Build the complete unstyled interaction layer with owner-controlled hover behavior. This is the native-overflow adapter hook for delayed submenu opening and menu-aim safe corridors. `hover_item` receives entry and exit transitions for enabled interactive rows; it owns highlighting and any delayed work. The ordinary [`Self::element_with_submenus`] method preserves immediate-highlight behavior without allocating a timer.