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.
Preview
Section titled “Preview”
Responsibility split
Section titled “Responsibility split”| Layer | Responsibility |
|---|---|
| Alicorn | Layout, retained scroll region, focus, pointer hit testing, Tree/Tree_Item semantics, virtual row realization, and rendering. |
tree_view / tree_model | Visible-window validation, stable row focus/selection, indentation, keyboard traversal, reveal, and context-menu targeting. |
| Application | Hierarchy, visible preorder projection, expansion/loading policy, mutation, selection policy, activation, and context-menu commands. |
Copyable implementation
Section titled “Copyable implementation”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.
Parts and identities
Section titled “Parts and identities”| Part | Identity | What can be omitted or replaced |
|---|---|---|
| Tree scroll owner | retained scroll node | Always present; one focus representative. |
| Row | stable Item_ID | The application supplies the row slice. Removing an item keeps remaining IDs. |
| Indentation / disclosure | stable child keys | Set hide_disclosure when folder icons communicate expansion. |
| Icon | Options.icon_proc | Return any Alicorn icon; return 0 to omit. |
| Label | stable child key | label_color_proc and label_paint_proc customize color and decorations. |
| Context menu | row semantic ID | context_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.
Styling, motion, and theme
Section titled “Styling, motion, and theme”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_procruns duringbuild; it must not retain the borrowed item.label_color_procreceives the current UI context for application-specific colors.row_hook_procmay attach Alicorn drag/drop behavior to the realized row.label_paint_procreceives 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.
Keyboard and accessibility contract
Section titled “Keyboard and accessibility contract”| Input | Result |
|---|---|
Up / Down | Move through visible rows, skipping disabled rows. |
Home / End | First/last visible row. |
Page Up / Page Down | Move by the visible row window. |
Left | Collapse an expanded item, or focus its visible parent. |
Right | Expand a collapsed item, or focus its first enabled visible child. |
Return | Activate the focused row. |
Shift+F10, Menu | Request a row context menu when enabled. |
| pointer | Press selects when selection_enabled; secondary click requests a context menu. |
- Publishes
TreeandTree_Itemroles with logical count, realized window,Expanded,Selected,Current, andDisabledas applicable. - Focus is tracked separately from selection.
select_on_focuscan 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.
Conformance tests
Section titled “Conformance tests”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_Requestedreconciliation; - context-menu targeting and target identity;
- idle return after navigation settles.
odin test tree_model -define:ODIN_TEST_THREADS=1odin test tree_view -define:ODIN_TEST_THREADS=1 -collection:alicorn=<alicorn> -collection:alikit=../out/tree_view_example.exe --smokeNo 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).
API reference
Section titled “API reference”| Declaration | Notes |
|---|---|
State | Model cursor, retained tree/scroll nodes, semantic namespace, and context target/anchor. |
Item / Window | Re-exported from tree_model; the window is a borrowed contiguous projection. |
Options | Labels, geometry, callbacks, hide_disclosure, selection_enabled, select_on_focus, context_menu_enabled, scroll_restore, and semantic_namespace. |
Event / Event_Kind | Pressed, Activated, Expand_Requested, Collapse_Requested, Parent_Focus_Requested, Context_Menu_Requested, Range_Requested, and Focus_Changed. |
build | Describe the tree and process queued input against the supplied window. |
handle_key, pointer | Lower-level host path. |
open_context_menu, context_target, context_anchor | Anchored context-menu support. |
semantic_id | Stable identity for an application row. |
Limits
Section titled “Limits”- 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.
Compatibility
Section titled “Compatibility”47c9d4a7cd1f637876190fec899daeeac00a30ae. See
Compatibility and pinning.