amenui
en·中 github ↗ v0.0.1
01docs 02components 03lab 04works
en·中github ↗
×

docs / components / navigation / nested menu docs / components / navigation /

nested menu

04.32
On this page ▾
  1. Installation
  2. Usage
  3. API
  4. Keyboard and accessibility

A menu whose rows open submenus, steered by where the pointer heads: moving toward an open submenu inside the triangle from its previous position to the submenu's near corners does not switch rows (each move waits close_delay_ms again, 200 ms); outside it, a row takes over after submenu_delay_ms (120 ms).

Arrow keys, Enter, Esc; the triangle can be drawn (annotation layer).

drawn by amenuiopen ↗

Installation

Components are distributed as source. Copy it and what it depends on into your project, then change it as you need:

sh
cargo run --release --bin amenui -- add nested_menu --to ../my-app

Files copied: src/widgets/nested_menu.rs, src/widgets/mod.rs

Usage

rust
use amenui::widgets::{nested_menu};

fn view() -> El<Msg> {
    let mut m = Menu::new(vec![
        MenuItem::sub("新建", vec![MenuItem::leaf("文档"), MenuItem::leaf("表格"), MenuItem::leaf("文件夹")]),
        MenuItem::sub("打开最近", vec![MenuItem::leaf("报告"), MenuItem::leaf("草稿")]),
        MenuItem::leaf("关闭"),
    ]);
    m.update(MenuMsg::Press(0, 0), 0.0);
    nested_menu("nm1", &m, Msg::Menu)
}

API

Functionsnested_menu
Propskey, menu (Menu: items, submenu_delay_ms, close_delay_ms, row_h, width, show_safe_zone), msg.
Filessrc/widgets/nested_menu.rs
Depends onbase
Response to frontsnudge (a control: pushed as one piece by fronts, held and condensing at most to Look::legible_cap)
Recompositionkeyed labels recompose when their text changes

Keyboard and accessibility

Statesclosed, open (a row hot, submenus open along a path), a switch pending (after submenu_delay_ms, or close_delay_ms while the pointer is inside the safe zone); role menu, rows menuitem.
Keys and messagesmsg(MenuMsg) for pointer moves over the menu, presses on rows and keys; the application calls Menu::update (which returns the path of a chosen item) and Menu::step on every tick while Menu::waiting().

On the web every control is mirrored into the page as an element with its role and name, so screen readers and the browser's own focus see it (DESIGN.md §1.14).

Recipes: A menu with submenus and a safe zone