pub trait OutlineViewer: View {
Show 13 methods
// Required methods
fn ov(&self) -> &OutlineViewerState;
fn ov_mut(&mut self) -> &mut OutlineViewerState;
fn get_root(&self) -> Option<&Node>;
fn get_next<'a>(&'a self, node: &'a Node) -> Option<&'a Node>;
fn get_child<'a>(&'a self, node: &'a Node, i: i32) -> Option<&'a Node>;
fn get_num_children(&self, node: &Node) -> i32;
fn get_text<'a>(&'a self, node: &'a Node) -> &'a str;
fn is_expanded(&self, node: &Node) -> bool;
fn has_children(&self, node: &Node) -> bool;
fn adjust(&mut self, pos: i32, expand: bool);
// Provided methods
fn focused_item(&mut self, i: i32) { ... }
fn is_selected(&self, i: i32) -> bool { ... }
fn selected(&mut self, _i: i32) { ... }
}Expand description
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.
Intentionally not object-safe (the 'a-bound getters) — that is fine,
concrete widgets are Box<dyn View> and OutlineViewer is only ever a generic
bound behind a concrete type (same as ListViewer).
Wiring caveat (no compile-time enforcement): a concrete outline widget MUST
delegate the relevant View methods to this module’s free functions: ov_draw,
ov_handle_event, ov_set_state, and View::as_any_mut
(the cross-view broker downcasts through it).
§Turbo Vision heritage
The trait half of TOutlineViewer (toutline.cpp): its overridable
tree-navigation virtuals, with the data members in OutlineViewerState and
the shared logic in this module’s free functions.
Required Methods§
Sourcefn ov(&self) -> &OutlineViewerState
fn ov(&self) -> &OutlineViewerState
Borrow the embedded OutlineViewerState.
Sourcefn ov_mut(&mut self) -> &mut OutlineViewerState
fn ov_mut(&mut self) -> &mut OutlineViewerState
Mutably borrow the embedded OutlineViewerState.
Sourcefn get_root(&self) -> Option<&Node>
fn get_root(&self) -> Option<&Node>
Return the root node of the tree, or None if the tree is empty.
Called at the start of every traversal (draw, update, expand-all). The
concrete widget returns the root of its owned tree; the lifetime 'a
ties the returned reference to &'a self so that callers can keep it
alive while iterating.
Sourcefn get_next<'a>(&'a self, node: &'a Node) -> Option<&'a Node>
fn get_next<'a>(&'a self, node: &'a Node) -> Option<&'a Node>
Return node’s next sibling, or None if node is the last sibling.
The traversal walks siblings by repeatedly calling this method; 'a
ties the returned node to the same lifetime as node (which is itself
already tied to &'a self at the call site).
Sourcefn get_child<'a>(&'a self, node: &'a Node, i: i32) -> Option<&'a Node>
fn get_child<'a>(&'a self, node: &'a Node, i: i32) -> Option<&'a Node>
Return the i-th child of node (0-based), or None if out of range.
The traversal calls this with i = 0 to obtain the first child, then
follows get_next for subsequent siblings. A concrete
widget that stores children in a Vec may use children.get(i as usize).
Sourcefn get_num_children(&self, node: &Node) -> i32
fn get_num_children(&self, node: &Node) -> i32
Return the number of direct children of node.
Used by the traversal and by ov_update to decide whether to recurse.
Must agree with has_children: return 0 iff
has_children returns false.
Sourcefn get_text<'a>(&'a self, node: &'a Node) -> &'a str
fn get_text<'a>(&'a self, node: &'a Node) -> &'a str
Return the display text for node, borrowed from self.
Displayed verbatim in the outline row to the right of the graph prefix.
The lifetime 'a allows returning a &str into the node’s own storage
without copying.
Sourcefn is_expanded(&self, node: &Node) -> bool
fn is_expanded(&self, node: &Node) -> bool
Return true if node’s children are currently shown.
The traversal recurses into node only when both has_children and
is_expanded return true. For Outline, this reads
Node::expanded. Override to store the expanded state externally (for
example in a HashMap<NodeId, bool>).
Sourcefn has_children(&self, node: &Node) -> bool
fn has_children(&self, node: &Node) -> bool
Return true if node has at least one child.
Determines whether the graph prefix shows an expand/collapse indicator
and whether the traversal may recurse. Must agree with
get_num_children.
Sourcefn adjust(&mut self, pos: i32, expand: bool)
fn adjust(&mut self, pos: i32, expand: bool)
Set the expanded state of the node at DFS position pos in the
currently visible tree (0-based, same numbering as
foc).
Called by the keyboard handler (+/-/* keys) and by the mouse
handler when the user clicks the graph prefix column. After adjust
returns, the caller invokes ov_update to recount visible nodes and
republish scrollbar limits.
The contract is keyed by DFS position rather than a node reference,
because the shared free functions only hold &self; the concrete widget
resolves pos to the owned node mutably.
Provided Methods§
Sourcefn focused_item(&mut self, i: i32)
fn focused_item(&mut self, i: i32)
Notify the concrete widget that node at DFS position i received focus.
The default writes i to OutlineViewerState::foc. Override to
maintain additional per-item focus state, such as a selection set.
Always call self.ov_mut().foc = i (or super) to keep the default
rendering consistent.
Sourcefn is_selected(&self, i: i32) -> bool
fn is_selected(&self, i: i32) -> bool
Return true if DFS position i should be drawn in the selected color.
The default returns i == foc (single-selection mode). Override in a
multi-select widget to highlight a range or set of positions in addition
to the focused one.
Sourcefn selected(&mut self, _i: i32)
fn selected(&mut self, _i: i32)
The user committed to DFS position i (double-click or Enter key).
The default does nothing. Override to react — for example, broadcast
Command::OUTLINE_ITEM_SELECTED so that an enclosing dialog can read
the focused node and act on it.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".