Guide API
Skip to main content

Module outline

Module outline 

Source
Expand description

A collapsible tree view: Node, OutlineViewer, and Outline.

§A trait, not a concrete struct

An outline viewer’s overridable methods (get_root/get_next/get_child/get_text/is_expanded/has_children/adjust) are called from inside the base’s own draw/handle_event/update — the same constraint that made ListViewer a trait rather than an embedded struct. So it follows the same shape: OutlineViewer carries the overridable methods, OutlineViewerState carries the data members, and the shared draw / event / traversal logic lives as free functions generic over <L: OutlineViewer + ?Sized> so a concrete widget’s View impl reuses them verbatim.

§The cross-view scrollbar read-sync

An outline viewer holds only &mut Context during dispatch and so can neither read nor mutate its window-frame sibling scroll bars. The pump is the broker: on a SCROLL_BAR_CHANGED broadcast naming one of its bars as source, the viewer requests Deferred::ScrollSync; the pump reads both bars’ values and calls apply_scroll_sync, which writes the resulting (dx, dy) into the viewer’s delta. This read-sync is read-only (no focus write-back), so it terminates without a change-guard.

§Mouse press-and-hold

A mouse-down arms the mouse-track capture; the subsequent move/auto/up events route the hold loop, auto-scrolling when the mouse moves out of view. A dragged gate distinguishes a click (which toggles the node’s expand state) from a drag.

§Colors

Each role is a Role: Role::OutlineNormal / Role::OutlineSurface / Role::OutlineFocused / Role::OutlineSelected / Role::OutlineNotExpanded. The normal row uses the shared three-surface rule (DrawCtx::content_surface): OutlineNormal/OutlineSurface/OutlineInactive cross owner_active with the outline’s own focus and selectability.

§Construction

Building an outline does not publish its scroll-bar parameters, because that needs a Context that is not available at construction. The consumer calls ov_update once after inserting the outline into a group (the same constraint the scroller and list-viewer constructors hit — see Outline::new).

§Turbo Vision heritage

Ports TNode, TOutlineViewer, and TOutline (toutline.cpp). The viewer’s abstract-class inheritance becomes a trait plus a state struct plus generic free functions (D2), because the base’s draw must call back into the subclass’s overrides. Owner back-pointers to the sibling scroll bars become ViewId handles brokered by the event loop (D3), and the palette becomes Roles. The node’s recursive destructor becomes the automatic Box<Node> drop.

Structs§

Node
One outline tree node.
Outline
A collapsible tree widget backed by an owned Node tree.
OutlineViewerState
The shared state of every outline viewer. A concrete outline widget embeds one and exposes it via OutlineViewer::ov/OutlineViewer::ov_mut.

Traits§

OutlineViewer
The abstract outline-viewer base, as a trait of overridable methods. Concrete outline widgets implement ov/ov_mut (the data accessors) and the tree-navigation methods; the shared draw / event / traversal logic (the free functions in this module) is generic over L: OutlineViewer and calls back into these.

Functions§

adjust_focus
Clamp new_focus, focus it, and scroll it into view.
create_graph
Build the box-drawing prefix string for one outline row.
ov_draw
Render every visible node.
ov_expand_all
Expand the node at DFS position pos and all of its descendants.
ov_get_graph
Return the default box-drawing prefix for one outline row.
ov_get_node_info
Return the (level, lines, flags) of the node at DFS position pos, or None if pos is out of range.
ov_handle_event
The scrollbar broadcast filter (inherited from the scroller), mouse hold-tracking, and the keyboard nav switch.
ov_set_state
Apply a view-state flag change to an outline viewer.
ov_update
Recount the visible nodes, republish the scrollbar limits, and re-clamp the focus.
traverse
DFS-visit every currently visible node, calling action for each.