Expand description
A live tree over a source the application implements.
Experimental: may change in any release
(docs/stability.md).
- Lazy, asynchronous: a branch’s children are asked for the
first time it is expanded (
TreeSource::load); the source answers now or later, from any thread, through theSinkit is given. Meanwhile the branch shows a loading row; a failure shows the reason and a retry button. - Live: the application inserts, removes, moves, renames or
reloads nodes at any time through a
TreeHandle; the selection and the expansion are keyed by node, so they survive. - Selection (single or multiple), keyboard (arrows, Page Up/Down, Home/End, Left/Right to close, open or move to the parent, Space, Ctrl+A, Enter, F2, type-ahead), drag and drop (before, after or inside a node), rename in place.
- Rows are list items: an icon
(
TreeView::icon), weak text on the right (TreeView::trailing), action buttons shown on hover (TreeView::actions), indent guides (TreeView::guides) and widgets of the application’s at their right end (TreeView::row_widgets) that act on their row without selecting it, and a context menu for the row clicked (TreeView::context_menu,TreeView::context_ui). - Virtualised: rows are flattened once per change and only the rows in view are built, so 100 000 nodes cost a screenful.
- Each moment is a step (
tree.load,tree.expand,tree.select,tree.drop,tree.rename,tree.activate,tree.context, seecrate::steps) and aSignalin the output.
use egui_pop_views::tree::{Node, Sink, TreeSource, TreeState, TreeView};
/// Folders named by their path, two levels deep.
struct Folders;
impl TreeSource<String> for Folders {
fn load(&self, parent: Option<&String>, sink: Sink<String>) {
// A real source answers from a thread.
let base = parent.cloned().unwrap_or_default();
let depth = base.matches('/').count();
sink.deliver(
(0..3)
.map(|i| {
let key = format!("{base}/{i}");
if depth < 1 { Node::branch(key, format!("Folder {i}")) } else { Node::leaf(key, format!("File {i}")) }
})
.collect(),
);
}
}
fn ui(ui: &mut egui::Ui, state: &mut TreeState<String>) {
let out = TreeView::new("folders").label("Folders").show(ui, state, &Folders);
for signal in out.signals {
// Apply drops and renames to the application's data...
let _ = signal;
}
}Re-exports§
pub use filter::FilterField;pub use filter::Query;pub use model::Children;pub use model::Edit;pub use model::Model;pub use model::Node;pub use model::Position;pub use model::Row;
Modules§
- filter
- A tree’s filter: the query, how a node matches it, and the field that
types it (
FilterField). - model
- The tree’s model: what the view knows of the application’s tree.
Structs§
- Sink
- Where a source answers one request.
- Tree
Handle - The application’s hand on a tree’s view: edits from any thread, applied at the next pass (which they wake).
- Tree
Output - What
TreeView::showreturns. - Tree
State - A tree’s state between passes: the cache, the selection, where it is scrolled.
- Tree
View - The tree widget.
Enums§
- Signal
- What happened in a tree this pass.
Constants§
- EDITS_
WAITING - How many edits wait at most for a tree’s next pass. A tree its host
no longer draws (a tab behind another) still receives its source’s
and the application’s edits; past this many, they are dropped and
the tree loads every branch again at its next pass
(
TreeState::droppedcounts them, and atree.overflowedevent says so on the journal when the view has the application).
Traits§
- Tree
Source - What the application implements: a branch’s children, on demand.