Skip to main content

tree_view

Function tree_view 

Source
pub fn tree_view<M, F, E>(model: M, row: F) -> Stateful<Expanded>
where M: TreeModel + 'static, M::Item: Clone + 'static, F: Fn(&M::Item, &Row) -> E + 'static, E: Into<Element>,
Expand description

model’s nodes as an indented, virtualized list; the arrow before a node with children expands or collapses it. row draws the rest of each line.

§Example

use dfui::Element;
use dfui::model::{Keyed, Tree};
use dfui::widgets::{Styled, column, text, tree_view};

#[derive(Clone)]
struct Entry(u64, &'static str);

impl Keyed for Entry {
    fn key(&self) -> u64 {
        self.0
    }
}

fn files() -> Tree<Entry> {
    let mut t = Tree::new();
    let src = t.push(None, Entry(1, "src"));
    t.push(Some(src), Entry(2, "lib.rs"));
    let widgets = t.push(Some(src), Entry(3, "widgets"));
    t.push(Some(widgets), Entry(4, "button.rs"));
    t.push(Some(widgets), Entry(5, "list.rs"));
    t.push(None, Entry(6, "README.md"));
    t
}

fn view() -> Element {
    let tree = tree_view(files(), |e: &Entry, _| text(e.1));
    column([tree.fill().into()]).fill().padding(16.0).into()
}

fn main() {
    dfui::run(view);
}