Skip to content

Sidebar

alikit:sidebar is the P0 Sidebar shape: a vertical, icon-led navigation rail with expanded and collapsed presentations. It publishes one List_Box with List_Box_Option routes, one Tab stop, roving Up/Down/Home/End focus, and one proposed route change on activation.

Native navigation rail window in the collapsed icon-only presentation, with a Files content pane and a Collapse rail checkbox
Native SDL_GPU capture of examples/sidebar at Alicorn 47c9d4a, shown collapsed. Collapsing changes width and omits visible labels; semantic IDs, selected state, and focus ownership do not change.
Interactive WebGPU preview is a later catalog step. The capture is the real native rail; route content and routing stay application-owned.
LayerResponsibility
AlicornLayout, focus, pointer hit testing, retained Button activation, List_Box/List_Box_Option semantics, and the roving model.
sidebarRail and row drawing, expanded/collapsed presentations, roving index proposal, selected/current presentation, namespaced surface recipe, and one selection event.
ApplicationAccepted route, route content, router/history, badges, and disabled policy.

A tree-style sidebar with nested sections is a later variant. This package deliberately implements the flat navigation rail first: stable route identity, one focus representative, and no second navigation model.

Files: sidebar/sidebar.odin, sidebar/sidebar_test.odin, examples/sidebar/main.odin, examples/sidebar/theme.json.

import alicorn "alicorn:runtime"
import ui "alicorn:ui"
import sidebar "alikit:sidebar"
ROUTES := [2]sidebar.Item{
{key=1, label="Overview", icon=.Info, detail="Workspace summary"},
{key=2, label="Files", icon=.Folder_Closed, detail="Browse workspace files"},
}
App :: struct {
rail: sidebar.State,
selected_key: u64,
collapsed: bool,
}
render :: proc(app: ^App, ctx: ^ui.UI) {
if event := sidebar.rail(
ctx,
&app.rail,
ROUTES[:],
app.selected_key,
sidebar.Options{accessible_label="Workspace navigation", collapsed=app.collapsed},
key=alicorn.key_string("workspace-rail"),
instance_id=1,
); event.kind == .Selection_Proposed {
app.selected_key = event.key
// Navigate the application route here. The rail does not own a router.
}
}

Call sidebar.request_focus(&state) when an application interaction should move focus to the rail. The next description focuses the rail after layout.

PartIdentityWhat can be omitted or replaced
Railrail_semantic_id(instance_id)rail_begin/rail_end; always present, one Tab stop and List_Box collection.
Route rowitem_semantic_id(instance_id, key)item_begin/item_end owns List_Box_Option, Selected/Current/Disabled, and roving participation.
Row surfacestable child keyrow_surface is optional; custom rows draw their own background.
Icon / label / badgestable child keys under the row ownerOptional default parts. Collapsed presentation omits visible label/badge; the accessible label remains.
Selected indicator.Selected_Indicatorindicator is optional; replace drawing and keep selected state.

rail() is a convenience wrapper over the exact public parts. A custom row can omit every visual part and draw any ordinary Alicorn layout inside the semantic Button owner. Rail_Item exposes item, index, count, selected, focused, focus_visible, disabled, and visible.

Three examples cover the paths: the default themed rail (examples/sidebar), custom rows (examples/sidebar_parts), and a rail + Segmented settings shell (examples/sidebar_composition).

Route key 0, zero instance ID, and duplicate keys are invalid. Selected and Current identity follow the stable key across reorder. Removing the active key repairs focus with the selected key first, then the nearest enabled route, then the first enabled route. The accent indicator and label weight make selection visible without relying on color alone.

Recipe declares three optional namespaced surface roles:

FieldCore fallback
rail_surface_roleSurface
item_surface_roleSurface
selected_surface_roleSelection

Zero roles need no theme registration. Configured roles are validated with theme_contract_default, theme_contract_check, theme_contract_satisfied, and theme_contract_missing_required. The example registers vendor.alikit.sidebar.* and activates the theme. A missing configured role falls back to the core role at render time after setup validation, so the rail remains usable.

Style carries corner radius, selected-indicator width, and focus-ring width. Options carries collapsed state, rail/expanded width, item height, gap, padding, icon size, label size, and wrap. Collapsing changes width and omits the visible label; it does not change semantic IDs, selected state, or focus ownership. There is no motion: navigation selection is immediately readable.

InputResult
TabReaches the rail once. Rows are not separate Tab stops.
Up / DownPrevious/next enabled route.
Home / EndFirst/last enabled route.
Return / SpacePropose the active route.
pointerOrdinary Button activation proposes the clicked route.
semantic SelectThe same proposal through List_Box_Option.
  • Navigation stops at the ends by default; set Options.wrap to wrap.
  • Arrow navigation alone does not change selection.
  • Disabled routes are skipped, publish Disabled, and do not advertise Select/Focus.
  • The rail publishes List_Box, its accessible name, logical route count, selected_id, and current_id. Rows publish List_Box_Option, label, description (detail), Selected, Current, and Select + Focus when enabled.
  • The rail is the focus representative; rows are intentionally non-focusable. Semantic Focus on a row may be rejected by the runtime’s realized-action eligibility rule, a recorded core gap shared with the icon picker. The rail’s own Focus action remains valid.
  • Not claimed: nested sections, expand/collapse route groups, a router, history, or drag reorder.

sidebar/sidebar_test.odin covers:

  • List_Box/List_Box_Option semantics, selected/current identity, disabled action rejection, and parent structure;
  • Down skipping a disabled route, Return activation, pointer activation, and semantic Select parity;
  • the .Roving_List pattern with a container focus representative, disabled skipping, no wrap, Home/End, and selection activation;
  • collapsed/expanded width changes with identical semantic identity and selected state;
  • reorder keeping selection attached to its stable key;
  • the theme contract.
Terminal window
odin test sidebar -define:ODIN_TEST_THREADS=1 -collection:alicorn=<alicorn> -collection:alikit=.
./out/sidebar_example.exe --smoke

The .Roving_List check is a real positive conformance run. Its negative controls are covered by Alicorn’s own testui fixture; this package does not duplicate the core fixture.

DeclarationNotes
ItemRoute key, label, icon, detail, optional badge, disabled.
OptionsCollapsed state, widths, item height, gap, padding, icon/label size, wrap.
Recipe / StyleOptional namespaced surface roles and visual geometry.
StateActive roving key, focus request, pending proposal.
Rail / Rail_ItemPer-description rail and row contexts.
Event / Event_KindOne-shot Selection_Proposed carrying key.
rail_begin, item_begin, item_end, rail_endPublic parts.
row_surface, indicator, icon, label, badgeOptional default visuals.
railConvenience wrapper built from the parts.
request_focusFocus the rail after layout.
recipe_default, style_defaultCore-role defaults.
theme_contract_default, theme_contract_checkSetup-time validation.
rail_semantic_id, item_semantic_id, instance_from_keyStable semantic identities.
  • The rail is flat. A nested sidebar needs a tree projection and is a separate P1 component.
  • Collapsed rows show icons only. Provide a meaningful icon and accessible label; there is no built-in tooltip.
  • The application owns route content, routing, history, and any shortcut that jumps directly to a route.
  • Headless tests do not prove a physical screen-reader session, pixel output, or native route focus.
Pin: built and captured against Alicorn 47c9d4a7cd1f637876190fec899daeeac00a30ae. See Compatibility and pinning.