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).
Installation
Components are distributed as source. Copy it and what it depends on into your project, then change it as you need:
cargo run --release --bin amenui -- add nested_menu --to ../my-appFiles copied: src/widgets/nested_menu.rs, src/widgets/mod.rs
Usage
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
| Functions | nested_menu |
|---|---|
| Props | key, menu (Menu: items, submenu_delay_ms, close_delay_ms, row_h, width, show_safe_zone), msg. |
| Files | src/widgets/nested_menu.rs |
| Depends on | base |
| Response to fronts | nudge (a control: pushed as one piece by fronts, held and condensing at most to Look::legible_cap) |
| Recomposition | keyed labels recompose when their text changes |
Keyboard and accessibility
| States | closed, 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 messages | msg(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