Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Module Mosaic_ui.Tree
Hierarchical tree with expandable nodes, guide lines, and selection.
Hierarchical tree with expand/collapse navigation.
A focusable, keyboard-navigable tree widget that displays items in a hierarchy with optional guide lines. Each node can be expanded or collapsed to show or hide its children. The widget automatically scrolls to keep the selected node visible.
Navigation
Keyboard bindings:
Up/Down arrows move the selection. Shift moves by fast_scroll_step items.
j/k move the selection by one item.
Right expands the focused node or moves to its first child.
Left collapses the focused node or moves to its parent.
Space toggles expand/collapse of the focused node.
Enter/KP_enter activates the focused node (fires on_activate).
Mouse bindings:
Left click on the icon area toggles expand/collapse.
Left click on the label area selects the node.
Scroll wheel navigates through the list.
Guide lines
When show_guides is true, Unicode box-drawing characters render the tree structure. The character set is controlled by guide_style, which accepts any Grid.Border.t preset (single, rounded, heavy, etc.). When show_guides is false (the default), only indentation is used.
set_items t items replaces the item tree with items. Resets the expansion state according to expand_depth, clamps the selection to a valid index, and triggers a re-render.
set_fast_scroll_step t n sets the number of rows to skip with Shift+Up/Down to n. n is clamped to a minimum of 1.
Callbacks
val set_on_change : t->(int -> unit) option-> unit
set_on_change t cb registers cb to be called when the selected index changes. cb receives the new selected index.
val set_on_activate : t->(int -> unit) option-> unit
set_on_activate t cb registers cb to be called when the focused node is activated via Enter. cb receives the activated visible index.
val set_on_expand : t->(int ->bool -> unit) option-> unit
set_on_expand t cb registers cb to be called when a node is expanded or collapsed. cb receives the visible index and the new expanded state (true for expanded, false for collapsed).