Skip to content

Menu

alikit:menu is an anchored, component-level dropdown built from public parts: a trigger, a transparent modal popup, Menu_Item row owners, separators, optional ad-hoc groups, and optional default row visuals. It owns roving Up/Down/Home/End navigation, checked and disabled publication, Escape/outside dismissal, and trigger focus restoration. The application owns items, command identity, checked state, custom rows, and dispatch.

Native menu window with an anchored actions menu, checked item, separators, and shortcut hints
Native SDL_GPU capture pending. The example passes the SDL_GPU smoke run; the default menu has an anchored quiet trigger and a bordered popup panel.
The capture shows the default closed menu example. The parts example adds custom two-line rows and a danger group.
LayerResponsibility
AlicornModal overlay containment, pointer/wheel/focus confinement, placement, Menu/Menu_Item roles, scroll region, buttons, theme roles.
menuTrigger, anchored popup, placement, active-row navigation, reveal, outside/Escape dismissal, checked/disabled/separator publication, group scaffolding, focus restoration.
ApplicationItems, command identity, dispatch, checked state, custom row content, and submenu composition.

State keeps only ephemeral open/anchor/panel/scroll nodes, the active roving identity, focus requests, and one chosen command key.

Files: menu/menu.odin, menu/menu_test.odin, menu/menu_parts_test.odin, examples/menu/main.odin, examples/menu_parts/main.odin, examples/menu_composition/main.odin.

ITEMS: [3]menu.Item = {
{key=1, label="Rename", shortcut="F2"},
{key=2, label="Show grid", checked=true},
{key=3, kind=.Separator},
}
// In the ordinary root:
_ = menu.trigger(ctx, &app.menu, "Actions", menu.Options{accessible_label="Actions"},
key=alicorn.key_string("actions-trigger"))
// In render_overlays:
visible, chosen := menu.popup_begin(ctx, &app.menu, ITEMS[:],
menu.Options{accessible_label="Actions"}, key=alicorn.key_string("actions-popup"),
instance_id=1)
if !visible {
if chosen != 0 { app.run(chosen) }
return
}
for item, index in ITEMS {
if menu.item(ctx, &app.menu, item, index) { app.run(item.key) }
}
menu.popup_end(ctx, &app.menu)

A custom trigger calls open_from_node(&state, runtime, trigger_node).

PartIdentityWhat can be omitted or replaced
Triggerapplication keyStock Button; custom triggers use open_from_node.
Popupmenu_semantic_id(instance_id)Transparent overlay, panel, Menu group, row scroll.
Rowitem_semantic_id(instance_id, item_key)item_begin/item_end owns Menu_Item; draw any content.
Row surfacestable child keyrow_surface optional.
Check/label/shortcut/detailstable child keysOptional default visuals; custom rows omit them.
Separatorno identityVisual row, skipped by navigation.
Groupgroup_semantic_id(instance_id, key)Optional ad-hoc nested Menu group; not a collection.

item() is a convenience wrapper over item_begin, row_surface, check, label, shortcut, and item_end. A custom row keeps the semantic owner and can render a label/detail/shortcut, checked mark, icon, or any ordinary Alicorn layout.

Alicorn’s pinned semantic_collection_begin still rejects .Menu, so groups publish ad-hoc nested Menu semantics without a count (#241 remains open). Groups are single-level and do not add navigation slots.

Submenus are not implemented in v1. The single overlay, panel scroll, active-row index, and trigger focus restoration do not contain a nested open/parent-focus coordination model. Applications that need a submenu compose a second menu State; the package does not duplicate overlay policy.

Recipe has optional panel, item, and active-item surface roles plus a core check color. Style carries corner radius, focus width, and check slot width. Options carries popup width, row height, padding, maximum visible rows, placement margin, and keep_open_on_select. The popup uses a transparent backdrop and a themed surface panel. Keyboard-active rows are revealed through an inner hidden-scrollbar scroll region. There is no component motion.

InputResult
Trigger activationOpen/close; publishes Expanded while open.
Up / DownMove the active row, skipping separators and disabled rows.
Home / EndFirst/last enabled row.
Return / SpaceChoose the active row and close (unless keep_open_on_select).
EscapeClose and restore trigger focus.
pointerRow activation; outside pointer down dismisses.

Rows publish Menu_Item with label, value, description, Checked/Disabled/Current, and Focus/Select/Press when enabled. The popup publishes one Menu with the accessible label.

Not claimed: submenus, type-ahead, multi-select, composite menu collection count/position, or native menu integration.

menu/menu_test.odin covers the default wrapper: identities, theme contract, trigger semantics, checked/disabled states, navigation and activation, Escape/focus restoration, pointer selection, outside dismissal, bottom-edge placement flip, and viewport containment. menu/menu_parts_test.odin covers custom rows, groups, keyboard/pointer/escape/outside paths, and placement.

Terminal window
odin test menu -define:ODIN_TEST_THREADS=1 -collection:alicorn=<alicorn> -collection:alikit=.
./out/menu_example.exe --smoke
./out/menu_parts_example.exe --smoke
./out/menu_composition_example.exe --smoke

There is no dropdown-menu pattern kind in testui; explicit drive assertions are used.

DeclarationNotes
Item / Item_KindCommand identity, label/detail/shortcut, .Item or .Separator, disabled/checked.
OptionsPopup geometry, max visible rows, placement margin, keep_open_on_select.
Recipe / StyleOptional surface roles and visual geometry.
State / MenuItemRetained popup state and per-description row context.
EventPending chosen command key.
trigger, popup_begin, popup_endAnchored shell.
item_begin, item_end, separator, group_begin, group_end, itemRow/group parts and convenience.
row_surface, check, label, shortcut, detailOptional default visuals.
open_from_node, close, take_chosenCustom trigger, close, pending key.
menu_semantic_id, item_semantic_id, group_semantic_idStable semantic identities.
  • Headless tests do not prove a physical screen-reader menu session or pixels.
  • Long menus scroll inside the popup but do not use a composite collection.
  • Submenus are application-composed from a second State.
  • Menu groups are ad-hoc nested semantics, not a counted collection.
Pin: built against Alicorn 47c9d4a7cd1f637876190fec899daeeac00a30ae. See Compatibility and pinning.