Guide API
Skip to main content

Module menu

Module menu 

Source
Expand description

Menus: the data tree and the views that present it.

MenuItem/Menu/MenuBuilder are the pure data — define a menu tree fluently with the builder. MenuBar, MenuBox, and the menu session (see menu_view, menu_bar, menu_box, menu_session) draw it and run the interactive open/navigate/select loop.

§The item model

A MenuItem is one of three things, made explicit and type-safe by the enum’s three variants:

  • a separator — a horizontal divider with no label or behaviour;
  • a submenu — a label that opens a nested Menu;
  • a command item — a label that emits a Command when chosen, with an optional accelerator key and optional shortcut display text such as "Alt-X".

A command and a submenu are mutually exclusive: an item can never hold both a command and a nested menu. The fields common to commands and submenus (name, key_code, help_ctx, disabled) are read uniformly via or-patterns, e.g. Command { disabled, .. } | SubMenu { disabled, .. } => ….

A Menu is a Vec of items plus a default selection given as an index into that vector (any valid index, or None). The MenuBuilder produces the usual convention: default is Some(0) (the first item) for a non-empty menu and None for an empty one.

Guide: Menus, status line & help.

§Turbo Vision heritage

Ports TMenuItem, TSubMenu, and TMenu (menus.h/menu.cpp). The implicit name/command-tagged union becomes a 3-variant enum and the linked list becomes a Vec with an index default (deviation D1).

Re-exports§

pub use menu_bar::MenuBar;
pub use menu_box::MenuBox;
pub use menu_session::MenuSession;
pub use menu_session::popup_menu;
pub use menu_view::MenuColors;
pub use menu_view::MenuView;
pub use menu_view::MenuViewState;

Modules§

menu_bar
The horizontal menu bar.
menu_box
The drop-down / pop-up menu box.
menu_session
The interactive menu layer — opening, navigating, and selecting menus — driven by one MenuSession capture handler on the single event loop.
menu_view
The shared, non-interactive layer behind the menu bar and menu boxes: MenuViewState (the data every menu view holds) plus the free functions for command-graying and passive accelerator dispatch.

Structs§

Menu
An ordered list of MenuItems with an optional default selection.
MenuBuilder
A fluent builder for a Menu.

Enums§

MenuItem
A single menu entry: a Separator, a Command item, or a SubMenu.

Functions§

alt
Build an Alt+<char> KeyEvent for use as a menu accelerator.