跳到正文

ContextMenu

在触发器上按下次要按钮时打开模型驱动的原生菜单。

#导入

从 quickgui 导入 ContextMenuState。

use quickgui::*;

#用法

ContextMenuState::new()
    .trigger().child(text("Right-click me"))

#结构

  • ContextMenuState::root
  • ContextMenuState::trigger

#API 参考

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

ContextMenuState

查看源码
pub const fn new() -> Self
popover_windowpub const fn popover_window(self) -> Option<WindowHandle>—

Configures popover window for this part.

pub const fn popover_window(self) -> Option<WindowHandle>
查看源码
is_openpub const fn is_open(self) -> bool—

Configures is open for this part.

pub const fn is_open(self) -> bool
查看源码
item_statepub fn item_state( menu: &PopoverMenu, index: usize, submenu_open: bool, ) -> Option<MenuItemPartState>—

The Base UI-named render snapshot for one row of an open context menu. The native popover surface resolves its own placement against the display work area, so a context menu publishes row state rather than the popup's side and alignment.

pub fn item_state( menu: &PopoverMenu, index: usize, submenu_open: bool, ) -> Option<MenuItemPartState>
查看源码
closepub fn close(&mut self, cx: &mut EventContext) -> bool—

Close the current root context-menu surface synchronously from application state.

pub fn close(&mut self, cx: &mut EventContext) -> bool
查看源码

ContextMenuState::target_with

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

Decorate a caller-owned target with context-menu semantics without changing appearance, focusability, pointer cursor, drag-region behavior, layout, or ordinary click handling.

ContextMenuState::target

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

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

ContextMenuState::trigger_with

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

Decorate a caller-owned target, Base UI's `ContextMenu.Trigger`. This is the Base UI-named alias of [`Self::target_with`]; both names decorate the same element identically.

ContextMenuState::trigger

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

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

ContextMenuState::backdrop_with

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

Decorate an optional caller-painted backdrop, Base UI's `ContextMenu.Backdrop`. The native popover surface already takes the pointer grab, so this layer exists only for a caller-painted dimming pass inside the owner window. It is hidden from assistive technology and carries no appearance of its own. Mount it only while [`Self::is_open`] is true.

ContextMenuState::backdrop

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

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

ContextMenuState::element

查看源码
pub fn element<V, BuildMenu, RenderRoot, RenderItem>( self, cx: &mut ViewContext<'_, V>, id: impl Into<ElementId>, access: fn(&mut V) -> &mut ContextMenuState, target: Element, layout: ContextMenuLayout, build_menu: BuildMenu, render_root: RenderRoot, render_item: RenderItem, ) -> Element where V: 'static, BuildMenu: Fn(&mut V, &ContextMenuEvent) -> Option<PopoverMenu> + 'static, RenderRoot: Fn() -> Element + 'static, RenderItem: Fn(&PopoverMenuItem, PopoverMenuItemState) -> Element + 'static,

Attach a complete cursor-point popover-menu interaction to a caller-owned target. `build_menu` runs only on a secondary click and may return `None` to suppress the popover. `render_root` and `render_item` own all appearance. The framework owns only bounded model behavior, structural geometry, point placement, separate-surface lifetime, keyboard focus, dismissal, submenu parenting, and exact native-close synchronization.

ContextMenuState::element_with

查看源码
pub fn element_with<V, BuildMenu, RenderRoot, RenderItem>( self, cx: &mut ViewContext<'_, V>, id: impl Into<ElementId>, access_source: StateAccessor<V, ContextMenuState>, target: Element, layout: ContextMenuLayout, build_menu: BuildMenu, render_root: RenderRoot, render_item: RenderItem, ) -> Element where V: 'static, BuildMenu: Fn(&mut V, &ContextMenuEvent) -> Option<PopoverMenu> + 'static, RenderRoot: Fn() -> Element + 'static, RenderItem: Fn(&PopoverMenuItem, PopoverMenuItemState) -> Element + 'static,

Attach the cursor-point popover-menu interaction against a per-instance state accessor. A host that owns one [`ContextMenuState`] per declared target passes an accessor that captures which state this target opens into.