Skip to content

Tree View

alikit:tree_view renders and navigates a stable, preorder projection of visible tree rows. The application owns the hierarchy, expansion and loading policy, mutations, selection policy, and commands. AliKit owns fixed-row virtualization, indentation, focus reveal, keyboard traversal, Tree semantics, and optional row-anchored context menus.

Native tree view window showing src, main.odin, ui, theme.odin, and README.md rows with folder and file icons
Native SDL_GPU capture of examples/tree_view at Alicorn 47c9d4a. Expanded folders are application state; the row projection is rebuilt after each expansion event.
Interactive WebGPU preview is a later catalog step. The capture is the real native window; no tree behavior is recreated in JavaScript.
LayerResponsibility
AlicornLayout, retained scroll region, focus, pointer hit testing, Tree/Tree_Item semantics, virtual row realization, and rendering.
tree_view / tree_modelVisible-window validation, stable row focus/selection, indentation, keyboard traversal, reveal, and context-menu targeting.
ApplicationHierarchy, visible preorder projection, expansion/loading policy, mutation, selection policy, activation, and context-menu commands.

Files: tree_view/tree_view.odin, tree_model/model.odin, tree_view/tree_view_test.odin, tree_model/model_test.odin, examples/tree_view/main.odin.

import alicorn "alicorn:runtime"
import ui "alicorn:ui"
import tree_view "alikit:tree_view"
import model "alikit:tree_model"
SOURCE_ROWS := [3]model.Item{
{id=model.Item_ID(1), label="src", depth=0, expandable=true},
{id=model.Item_ID(2), parent_id=model.Item_ID(1), label="main.odin", depth=1},
{id=model.Item_ID(3), label="README.md", depth=0},
}
App :: struct {
view: tree_view.State,
rows: [3]tree_view.Item,
row_count: int,
revision: u64,
}
render :: proc(app: ^App, ctx: ^ui.UI) {
window := tree_view.Window{
total_count=app.row_count,
revision=app.revision,
items=app.rows[:app.row_count],
}
event := tree_view.build(ctx, &app.view, window,
alicorn.key_string("project-tree"),
tree_view.Options{accessible_label="Project files", selection_enabled=true})
if event.kind == .Expand_Requested {
// Update application expansion state and rebuild the visible projection.
}
}

The component allocates nothing. Keep tree_view.State with the consuming view. With ui.run, the tree registers a scoped input owner during build; the next description applies queued navigation to fresh application rows.

PartIdentityWhat can be omitted or replaced
Tree scroll ownerretained scroll nodeAlways present; one focus representative.
Rowstable Item_IDThe application supplies the row slice. Removing an item keeps remaining IDs.
Indentation / disclosurestable child keysSet hide_disclosure when folder icons communicate expansion.
IconOptions.icon_procReturn any Alicorn icon; return 0 to omit.
Labelstable child keylabel_color_proc and label_paint_proc customize color and decorations.
Context menurow semantic IDcontext_menu_enabled adds secondary-click and keyboard targeting.

IDs must be nonzero, unique within the supplied window, and stable while the logical item exists. Window.total_count is the logical row count; offset is the first supplied row. A paged consumer receives Range_Requested with an absolute logical index when navigation reaches outside the loaded window.

Options carries row height, padding, gap, indent width, chevron size, icon size, labels, scroll restore, and callbacks. The view uses Alicorn core roles (Text, Muted_Text, Selection, Focus, Border) and has no component theme contract.

  • icon_proc runs during build; it must not retain the borrowed item.
  • label_color_proc receives the current UI context for application-specific colors.
  • row_hook_proc may attach Alicorn drag/drop behavior to the realized row.
  • label_paint_proc receives the realized label node for decorations such as an active-file underline.
  • There is no tree animation: focus and reveal are immediate, and the tree does not own a timer.
InputResult
Up / DownMove through visible rows, skipping disabled rows.
Home / EndFirst/last visible row.
Page Up / Page DownMove by the visible row window.
LeftCollapse an expanded item, or focus its visible parent.
RightExpand a collapsed item, or focus its first enabled visible child.
ReturnActivate the focused row.
Shift+F10, MenuRequest a row context menu when enabled.
pointerPress selects when selection_enabled; secondary click requests a context menu.
  • Publishes Tree and Tree_Item roles with logical count, realized window, Expanded, Selected, Current, and Disabled as applicable.
  • Focus is tracked separately from selection. select_on_focus can make navigation change selection; the application still owns the selection policy.
  • Semantic focus synchronizes the keyboard cursor from the stable semantic identity before the next key is handled.
  • When a focused item disappears, reconcile the model against the new revision and preserve the nearest valid position where the complete projection is available.
  • Not claimed: a filesystem, hierarchy storage, loading policy, type-ahead, multi-select, or drag reorder.

tree_model/model_test.odin and tree_view/tree_view_test.odin cover:

  • window validation, duplicate/invalid IDs, depth and parent rules;
  • Up/Down, Home/End, Page Up/Page Down, Left/Right expansion and parent/child focus, disabled skipping, and stable identity across reorder;
  • pointer press, selection versus focus, semantic rows, and focus reveal;
  • paged windows and Range_Requested reconciliation;
  • context-menu targeting and target identity;
  • idle return after navigation settles.
Terminal window
odin test tree_model -define:ODIN_TEST_THREADS=1
odin test tree_view -define:ODIN_TEST_THREADS=1 -collection:alicorn=<alicorn> -collection:alikit=.
./out/tree_view_example.exe --smoke

No testui tree pattern fits at the pinned revision. The suite uses explicit semantic and drive assertions instead of claiming .Roving_List (which requires a List_Box container).

DeclarationNotes
StateModel cursor, retained tree/scroll nodes, semantic namespace, and context target/anchor.
Item / WindowRe-exported from tree_model; the window is a borrowed contiguous projection.
OptionsLabels, geometry, callbacks, hide_disclosure, selection_enabled, select_on_focus, context_menu_enabled, scroll_restore, and semantic_namespace.
Event / Event_KindPressed, Activated, Expand_Requested, Collapse_Requested, Parent_Focus_Requested, Context_Menu_Requested, Range_Requested, and Focus_Changed.
buildDescribe the tree and process queued input against the supplied window.
handle_key, pointerLower-level host path.
open_context_menu, context_target, context_anchorAnchored context-menu support.
semantic_idStable identity for an application row.
  • The application must supply the visible preorder projection; the component does not own a filesystem or expansion policy.
  • A paged consumer must retain its own revision checks and load policy.
  • Headless tests do not prove a physical screen-reader traversal or pixels.
  • Context-menu actions must revalidate the target ID because the row may change while the menu is open.
Pin: built and captured against Alicorn 47c9d4a7cd1f637876190fec899daeeac00a30ae. See Compatibility and pinning.