Skip to main content

Module tree_slice

Module tree_slice 

Source
Expand description

TreeSlice — per-view flattened projection of a TreeModel.

TreeSlice<T> wraps a TreeModel<T> and maintains an independent expand/collapse set so two TreeView widgets sharing the same model have independent visible rows — dual-pane file managers, overview/detail splits, and search results panels are each one TreeSlice::new(model.clone()). The slice re-flattens automatically whenever the underlying model emits a TreeChange, and bumps a version_signal Signal<u64> that views bind at BindingLevel::Rebuild.

A lightweight TreeSliceHandle (created via TreeSlice::handle) shares all Rc-based internals and is usable in closures without keeping the tree-change observer alive.

TreeSlice implements TreeDataSource and is the built-in source for TreeView / TreeTableView.

§Example

let tree = TreeModel::new();
let root = tree.insert_root(0, "root");
let child = tree.insert_child(root, 0, "child");

let slice1 = TreeSlice::new(tree.clone());
let slice2 = TreeSlice::new(tree.clone());

slice1.expand(root);
assert_eq!(slice1.visible_count(), 2); // root + child visible
assert_eq!(slice2.visible_count(), 1); // still collapsed in slice2

// Inserting into the model notifies both slices.
tree.insert_child(root, 1, "child2");
assert_eq!(slice1.visible_count(), 3); // child2 also visible in the expanded slice

Structs§

TreeSlice
Per-view flattened projection of a TreeModel<T>.
TreeSliceHandle
Lightweight handle to a TreeSlice’s shared state, usable in closures.