use std::cell::RefCell;
use std::collections::HashMap;
use std::hash::{DefaultHasher, Hash, Hasher};
use std::rc::{Rc, Weak};
use objc2::rc::Retained;
use objc2::runtime::{AnyObject, NSObject, NSObjectProtocol, ProtocolObject};
use objc2::{DefinedClass, MainThreadMarker, MainThreadOnly, define_class, msg_send};
use objc2_app_kit::{
NSControlTextEditingDelegate, NSImage, NSImageView, NSOutlineView, NSOutlineViewDataSource, NSOutlineViewDelegate,
NSScrollView, NSTableCellView, NSTableColumn, NSTableViewStyle, NSTextField, NSUserInterfaceItemIdentification, NSView,
};
use objc2_foundation::{NSIndexSet, NSInteger, NSNotification, NSString};
use crate::signal::{Effect, Signal, untrack};
use crate::view::{Cx, Identifiable, Kind, Node, Size, View};
#[derive(Debug, Clone)]
pub struct TreeNode<T> {
pub value: T,
pub children: Vec<TreeNode<T>>,
}
impl<T> TreeNode<T> {
pub fn leaf(value: T) -> Self {
TreeNode { value, children: Vec::new() }
}
pub fn branch(value: T, children: Vec<TreeNode<T>>) -> Self {
TreeNode { value, children }
}
}
struct Entry {
key: u64,
title: String,
icon: Option<(String, Option<crate::Color>)>,
badge: Option<String>,
columns: Vec<String>,
children: Vec<usize>,
expandable: bool,
}
#[derive(Default)]
struct State {
entries: Vec<Entry>,
roots: Vec<usize>,
items: Vec<Retained<OutlineItem>>,
by_key: HashMap<u64, Retained<OutlineItem>>,
group_roots: bool,
on_select: Option<Box<dyn Fn(Option<usize>)>>,
on_expand: Option<Rc<dyn Fn(usize)>>,
quiet: bool,
}
define_class!(
#[unsafe(super(NSObject))]
#[thread_kind = MainThreadOnly]
#[name = "FerrokitOutlineItem"]
#[ivars = std::cell::Cell<usize>]
struct OutlineItem;
);
impl OutlineItem {
fn new(mtm: MainThreadMarker, index: usize) -> Retained<Self> {
let this = Self::alloc(mtm).set_ivars(std::cell::Cell::new(index));
unsafe { msg_send![super(this), init] }
}
}
define_class!(
#[unsafe(super(NSObject))]
#[thread_kind = MainThreadOnly]
#[name = "FerrokitOutlineSource"]
#[ivars = RefCell<Weak<RefCell<State>>>]
struct Source;
unsafe impl NSObjectProtocol for Source {}
unsafe impl NSControlTextEditingDelegate for Source {}
unsafe impl NSOutlineViewDataSource for Source {
#[unsafe(method(outlineView:numberOfChildrenOfItem:))]
fn count(&self, _ov: &NSOutlineView, item: Option<&AnyObject>) -> NSInteger {
crate::failure::guard("an outline (count)", 0, || {
self.with(|s| match index_of(item) {
None => s.roots.len(),
Some(i) => s.entries.get(i).map_or(0, |e| e.children.len()),
}) as NSInteger
})
}
#[unsafe(method_id(outlineView:child:ofItem:))]
fn child(&self, _ov: &NSOutlineView, index: NSInteger, item: Option<&AnyObject>) -> Retained<AnyObject> {
let found = crate::failure::guard("an outline (child)", None, || {
let state = self.ivars().borrow().upgrade()?;
let s = state.borrow();
let list = match index_of(item) {
None => &s.roots,
Some(i) => &s.entries.get(i)?.children,
};
s.items.get(*list.get(index as usize)?).cloned()
});
match found {
Some(item) => Retained::into_super(Retained::into_super(item)),
None => Retained::into_super(NSObject::new()),
}
}
#[unsafe(method(outlineView:isItemExpandable:))]
fn expandable(&self, _ov: &NSOutlineView, item: &AnyObject) -> bool {
crate::failure::guard("an outline (expandable)", false, || {
self.with(|s| index_of(Some(item)).and_then(|i| s.entries.get(i)).is_some_and(|e| e.expandable))
})
}
}
unsafe impl NSOutlineViewDelegate for Source {
#[unsafe(method_id(outlineView:viewForTableColumn:item:))]
fn view_for(&self, ov: &NSOutlineView, column: Option<&NSTableColumn>, item: &AnyObject) -> Option<Retained<NSView>> {
crate::failure::guard("an outline (view_for)", None, || {
let extra = column.and_then(|c| {
let id = c.identifier().to_string();
let (kind, n) = id.split_once('.')?;
Some((kind == "column-right", n.parse::<usize>().ok()?))
});
if let Some((right, n)) = extra {
let text = self.with(|s| index_of(Some(item)).and_then(|i| s.entries.get(i)).and_then(|e| e.columns.get(n).cloned()));
text.map(|t| column_cell(ov, &t, right))
} else {
self.tree_cell(ov, item)
}
})
}
#[unsafe(method(outlineView:isGroupItem:))]
fn is_group(&self, _ov: &NSOutlineView, item: &AnyObject) -> bool {
crate::failure::guard("an outline (is_group)", false, || {
self.with(|s| s.group_roots && index_of(Some(item)).is_some_and(|i| s.roots.contains(&i)))
})
}
#[unsafe(method(outlineView:shouldSelectItem:))]
fn should_select(&self, _ov: &NSOutlineView, item: &AnyObject) -> bool {
crate::failure::guard("an outline (should_select)", false, || {
!self.with(|s| s.group_roots && index_of(Some(item)).is_some_and(|i| s.roots.contains(&i)))
})
}
#[unsafe(method(outlineViewItemWillExpand:))]
fn will_expand(&self, notification: &NSNotification) {
let item = notification.userInfo().and_then(|u| u.objectForKey(&NSString::from_str("NSObject")));
let Some(index) = index_of(item.as_deref()) else { return };
let Some(state) = self.ivars().borrow().upgrade() else { return };
let s = state.borrow();
if s.quiet || s.entries.get(index).is_none_or(|e| !e.children.is_empty()) {
return;
}
if let Some(load) = s.on_expand.clone() {
let (key, state) = (s.entries[index].key, state.clone());
crate::later(move || {
let index = state.borrow().entries.iter().position(|e| e.key == key);
if let Some(index) = index {
crate::failure::entry("an outline's children", (), || crate::batch(|| load(index)));
}
});
}
}
#[unsafe(method(outlineViewSelectionDidChange:))]
fn selection_did_change(&self, notification: &NSNotification) {
let Some(ov) = notification.object().and_then(|o| o.downcast::<NSOutlineView>().ok()) else { return };
let Some(state) = self.ivars().borrow().upgrade() else { return };
if state.borrow().quiet {
return;
}
let row = ov.selectedRow();
let index = (row >= 0).then(|| ov.itemAtRow(row)).flatten().and_then(|i| index_of(Some(&i)));
let cb = state.borrow_mut().on_select.take();
if let Some(cb) = &cb {
crate::failure::entry("an outline's selection", (), || cb(index));
}
let mut s = state.borrow_mut();
if s.on_select.is_none() {
s.on_select = cb;
}
}
}
);
impl Source {
fn new(mtm: MainThreadMarker, state: &Rc<RefCell<State>>) -> Retained<Self> {
let this = Self::alloc(mtm).set_ivars(RefCell::new(Rc::downgrade(state)));
unsafe { msg_send![super(this), init] }
}
fn tree_cell(&self, ov: &NSOutlineView, item: &AnyObject) -> Option<Retained<NSView>> {
let found = self.with(|s| {
index_of(Some(item)).and_then(|i| {
s.entries.get(i).map(|e| (e.title.clone(), e.icon.clone(), e.badge.clone(), s.group_roots && s.roots.contains(&i)))
})
});
found.map(|(title, icon, badge, group)| cell(ov, &title, icon.as_ref().map(|(n, c)| (n.as_str(), *c)), badge.as_deref(), group))
}
fn with<R: Default>(&self, f: impl FnOnce(&State) -> R) -> R {
self.ivars().borrow().upgrade().map(|s| f(&s.borrow())).unwrap_or_default()
}
}
fn index_of(item: Option<&AnyObject>) -> Option<usize> {
item.and_then(|i| i.downcast_ref::<OutlineItem>()).map(|i| i.ivars().get())
}
const BADGE_TAG: isize = 0x0bad6e;
fn cell(ov: &NSOutlineView, title: &str, icon: Option<(&str, Option<crate::Color>)>, badge: Option<&str>, group: bool) -> Retained<NSView> {
let mtm = MainThreadMarker::from(ov);
let ident = NSString::from_str(if group { "group" } else if icon.is_some() { "icon" } else { "plain" });
let reused = unsafe { ov.makeViewWithIdentifier_owner(&ident, None) }.and_then(|v| v.downcast::<NSTableCellView>().ok());
let view = reused.unwrap_or_else(|| {
let v = NSTableCellView::new(mtm);
v.setIdentifier(Some(&ident));
let text = NSTextField::labelWithString(&NSString::new(), mtm);
text.setLineBreakMode(objc2_app_kit::NSLineBreakMode::ByTruncatingTail);
if group {
text.setFont(Some(&objc2_app_kit::NSFont::boldSystemFontOfSize(objc2_app_kit::NSFont::smallSystemFontSize())));
text.setTextColor(Some(&objc2_app_kit::NSColor::secondaryLabelColor()));
}
v.addSubview(&text);
unsafe { v.setTextField(Some(&text)) };
let center = |sub: &NSView| {
sub.setTranslatesAutoresizingMaskIntoConstraints(false);
sub.centerYAnchor().constraintEqualToAnchor(&v.centerYAnchor()).setActive(true);
};
center(&text);
if group {
text.trailingAnchor().constraintLessThanOrEqualToAnchor_constant(&v.trailingAnchor(), -2.0).setActive(true);
} else {
let badge = NSTextField::labelWithString(&NSString::new(), mtm);
badge.setTag(BADGE_TAG);
badge.setFont(Some(&objc2_app_kit::NSFont::monospacedDigitSystemFontOfSize_weight(objc2_app_kit::NSFont::smallSystemFontSize(), 0.0)));
badge.setTextColor(Some(&objc2_app_kit::NSColor::secondaryLabelColor()));
badge.setAlignment(objc2_app_kit::NSTextAlignment::Right);
badge.setHidden(true);
v.addSubview(&badge);
center(&badge);
badge.trailingAnchor().constraintEqualToAnchor_constant(&v.trailingAnchor(), -6.0).setActive(true);
badge.setContentCompressionResistancePriority_forOrientation(750.0, objc2_app_kit::NSLayoutConstraintOrientation::Horizontal);
text.trailingAnchor().constraintLessThanOrEqualToAnchor_constant(&badge.leadingAnchor(), -6.0).setActive(true);
}
text.setContentCompressionResistancePriority_forOrientation(250.0, objc2_app_kit::NSLayoutConstraintOrientation::Horizontal);
if icon.is_some() {
let image = NSImageView::new(mtm);
objc2_app_kit::NSAccessibility::setAccessibilityElement(&*image, false);
if let Some(cell) = image.cell() {
let () = unsafe { objc2::msg_send![&*cell, setAccessibilityElement: false] };
}
v.addSubview(&image);
unsafe { v.setImageView(Some(&image)) };
center(&image);
image.leadingAnchor().constraintEqualToAnchor_constant(&v.leadingAnchor(), 2.0).setActive(true);
image.widthAnchor().constraintEqualToConstant(20.0).setActive(true);
text.leadingAnchor().constraintEqualToAnchor_constant(&image.trailingAnchor(), 6.0).setActive(true);
} else {
text.leadingAnchor().constraintEqualToAnchor_constant(&v.leadingAnchor(), 2.0).setActive(true);
}
v
});
if let Some(t) = unsafe { view.textField() } {
t.setStringValue(&NSString::from_str(title));
}
if let Some(b) = view.viewWithTag(BADGE_TAG).and_then(|b| b.downcast::<NSTextField>().ok()) {
b.setStringValue(&NSString::from_str(badge.unwrap_or_default()));
b.setHidden(badge.is_none_or(str::is_empty));
}
if let (Some((name, tint)), Some(iv)) = (icon, unsafe { view.imageView() }) {
iv.setImage(NSImage::imageWithSystemSymbolName_accessibilityDescription(&NSString::from_str(name), None).as_deref());
iv.setContentTintColor(tint.map(|c| c.ns()).as_deref());
}
Retained::into_super(view)
}
fn column_cell(ov: &NSOutlineView, text: &str, right: bool) -> Retained<NSView> {
let mtm = MainThreadMarker::from(ov);
let ident = NSString::from_str(if right { "column-right" } else { "column" });
let reused = unsafe { ov.makeViewWithIdentifier_owner(&ident, None) }.and_then(|v| v.downcast::<NSTableCellView>().ok());
let view = reused.unwrap_or_else(|| {
let v = NSTableCellView::new(mtm);
v.setIdentifier(Some(&ident));
let field = NSTextField::labelWithString(&NSString::new(), mtm);
field.setLineBreakMode(objc2_app_kit::NSLineBreakMode::ByTruncatingTail);
field.setTextColor(Some(&objc2_app_kit::NSColor::secondaryLabelColor()));
if right {
field.setAlignment(objc2_app_kit::NSTextAlignment::Right);
field.setFont(Some(&objc2_app_kit::NSFont::monospacedDigitSystemFontOfSize_weight(objc2_app_kit::NSFont::systemFontSize(), 0.0)));
}
v.addSubview(&field);
unsafe { v.setTextField(Some(&field)) };
field.setTranslatesAutoresizingMaskIntoConstraints(false);
field.centerYAnchor().constraintEqualToAnchor(&v.centerYAnchor()).setActive(true);
field.leadingAnchor().constraintEqualToAnchor_constant(&v.leadingAnchor(), 2.0).setActive(true);
field.trailingAnchor().constraintEqualToAnchor_constant(&v.trailingAnchor(), -2.0).setActive(true);
field.setContentCompressionResistancePriority_forOrientation(250.0, objc2_app_kit::NSLayoutConstraintOrientation::Horizontal);
v
});
if let Some(t) = unsafe { view.textField() } {
t.setStringValue(&NSString::from_str(text));
}
Retained::into_super(view)
}
fn key_of<K: Hash>(id: &K) -> u64 {
let mut h = DefaultHasher::new();
id.hash(&mut h);
h.finish()
}
type Roots<T> = Box<dyn Fn() -> Vec<TreeNode<T>>>;
type IconFn<T> = dyn Fn(&T) -> Option<String>;
type TintFn<T> = dyn Fn(&T) -> Option<crate::Color>;
type BadgeFn<T> = dyn Fn(&T) -> Option<String>;
type TextFn<T> = dyn Fn(&T) -> String;
type HasFn<T> = dyn Fn(&T) -> bool;
type Lazy<T> = (Rc<HasFn<T>>, Rc<dyn Fn(<T as Identifiable>::Id)>);
type LookFn<T> = dyn Fn(&T) -> Option<(String, Option<crate::Color>)>;
pub struct Outline<T: Identifiable + 'static> {
roots: Roots<T>,
title: Rc<dyn Fn(&T) -> String>,
icon: Option<Rc<IconFn<T>>>,
tint: Option<Rc<TintFn<T>>>,
badge: Option<Rc<BadgeFn<T>>>,
columns: Vec<OutlineColumn<T>>,
lazy: Option<Lazy<T>>,
selection: Option<Signal<Option<T::Id>>>,
sidebar: bool,
expanded: bool,
transparent: bool,
}
struct OutlineColumn<T> {
title: String,
width: f64,
right: bool,
value: Rc<TextFn<T>>,
}
impl<T: Identifiable + 'static> Outline<T> {
pub fn expanded(mut self) -> Self {
self.expanded = true;
self
}
pub fn transparent_background(mut self) -> Self {
self.transparent = true;
self
}
pub fn icon(mut self, f: impl Fn(&T) -> Option<String> + 'static) -> Self {
self.icon = Some(Rc::new(f));
self
}
pub fn icon_color(mut self, f: impl Fn(&T) -> Option<crate::Color> + 'static) -> Self {
self.tint = Some(Rc::new(f));
self
}
pub fn badge(mut self, f: impl Fn(&T) -> Option<String> + 'static) -> Self {
self.badge = Some(Rc::new(f));
self
}
pub fn column(mut self, title: &str, width: f64, value: impl Fn(&T) -> String + 'static) -> Self {
self.columns.push(OutlineColumn { title: title.into(), width, right: false, value: Rc::new(value) });
self
}
pub fn number_column(mut self, title: &str, width: f64, value: impl Fn(&T) -> String + 'static) -> Self {
self.columns.push(OutlineColumn { title: title.into(), width, right: true, value: Rc::new(value) });
self
}
pub fn lazy_children(mut self, has_children: impl Fn(&T) -> bool + 'static, load: impl Fn(T::Id) + 'static) -> Self {
self.lazy = Some((Rc::new(has_children), Rc::new(load)));
self
}
pub fn selection(mut self, selected: &Signal<Option<T::Id>>) -> Self {
self.selection = Some(*selected);
self
}
}
impl<T: Identifiable + 'static> View for Outline<T> {
fn build(self, cx: &mut Cx) -> Node {
let mtm = cx.mtm;
let ov = NSOutlineView::new(mtm);
let column = NSTableColumn::initWithIdentifier(NSTableColumn::alloc(mtm), &NSString::from_str("title"));
ov.addTableColumn(&column);
unsafe { ov.setOutlineTableColumn(Some(&column)) };
if self.columns.is_empty() {
ov.setHeaderView(None);
} else {
column.setTitle(&NSString::from_str(&crate::t("Name")));
column.setWidth(220.0);
column.setMinWidth(80.0);
for (n, c) in self.columns.iter().enumerate() {
let kind = if c.right { "column-right" } else { "column" };
let extra = NSTableColumn::initWithIdentifier(NSTableColumn::alloc(mtm), &NSString::from_str(&format!("{kind}.{n}")));
extra.setTitle(&NSString::from_str(&c.title));
extra.setWidth(c.width);
extra.setMinWidth(40.0);
ov.addTableColumn(&extra);
}
ov.setColumnAutoresizingStyle(objc2_app_kit::NSTableViewColumnAutoresizingStyle::FirstColumnOnlyAutoresizingStyle);
}
if self.sidebar {
ov.setStyle(NSTableViewStyle::SourceList);
ov.setFloatsGroupRows(false);
ov.setRowSizeStyle(objc2_app_kit::NSTableViewRowSizeStyle::Default);
}
let scroll = NSScrollView::new(mtm);
scroll.setDocumentView(Some(&ov));
scroll.setHasVerticalScroller(true);
scroll.setAutohidesScrollers(true);
if self.sidebar || self.transparent {
scroll.setDrawsBackground(false);
}
if self.transparent {
ov.setBackgroundColor(&objc2_app_kit::NSColor::clearColor());
}
let state = Rc::new(RefCell::new(State { group_roots: self.sidebar, ..State::default() }));
let source = Source::new(mtm, &state);
unsafe {
ov.setDataSource(Some(ProtocolObject::from_ref(&*source)));
ov.setDelegate(Some(ProtocolObject::from_ref(&*source)));
}
let ids: Rc<RefCell<Vec<T::Id>>> = Rc::default();
if let Some(sel) = &self.selection {
let (sel, ids) = (*sel, ids.clone());
state.borrow_mut().on_select = Some(Box::new(move |i| {
sel.set(i.and_then(|i| ids.borrow().get(i).cloned()));
}));
}
let lazy = self.lazy.clone();
if let Some((_, load)) = &self.lazy {
let (load, ids) = (load.clone(), ids.clone());
state.borrow_mut().on_expand = Some(Rc::new(move |i| {
let id = ids.borrow().get(i).cloned();
if let Some(id) = id {
load(id);
}
}));
}
let (mut node, _) = Node::leaf(cx, Retained::into_super(scroll), (true, true), Size { w: 160.0, h: 120.0 });
if let Kind::Leaf(l) = &node.kind {
l.content.set(Some(Size { w: 160.0, h: 120.0 }));
}
let restore: Rc<dyn Fn()> = {
let (st, ids, ov3, sel) = (state.clone(), ids.clone(), ov.clone(), self.selection);
Rc::new(move || {
let Some(sel) = &sel else { return };
let want = sel.get();
untrack(|| {
let index = want.and_then(|id| ids.borrow().iter().position(|x| *x == id));
let item = index.and_then(|i| st.borrow().items.get(i).cloned());
let row = item.map_or(-1, |it| unsafe { ov3.rowForItem(Some(&it)) });
if ov3.selectedRow() != row {
st.borrow_mut().quiet = true;
if row >= 0 {
ov3.selectRowIndexes_byExtendingSelection(&NSIndexSet::indexSetWithIndex(row as usize), false);
} else {
unsafe { ov3.deselectAll(None) };
}
st.borrow_mut().quiet = false;
}
});
})
};
let (roots_fn, title, sidebar, expanded) = (self.roots, self.title, self.sidebar, self.expanded);
let tint = self.tint;
let badge = self.badge;
let columns: Vec<Rc<TextFn<T>>> = self.columns.iter().map(|c| c.value.clone()).collect();
let has_children: Option<Rc<HasFn<T>>> = lazy.map(|(h, _)| h);
let icon: Option<Rc<LookFn<T>>> = self.icon.map(|f| Rc::new(move |v: &T| f(v).map(|name| (name, tint.as_ref().and_then(|t| t(v))))) as Rc<LookFn<T>>);
let (st, ids2, ov2, restore2) = (state.clone(), ids.clone(), ov.clone(), restore.clone());
node.own(Effect::new(move || {
let roots = roots_fn();
untrack(|| {
let shown: Vec<(u64, Retained<OutlineItem>)> = {
let s = st.borrow();
s.entries.iter().zip(&s.items).map(|(e, it)| (e.key, it.clone())).collect()
};
let open: std::collections::HashSet<u64> = shown
.into_iter()
.filter(|(_, it)| unsafe { ov2.isItemExpanded(Some(it)) })
.map(|(key, _)| key)
.collect();
let mut s = st.borrow_mut();
let old = std::mem::take(&mut s.by_key);
let (mut entries, mut items, mut keys, mut typed) = (Vec::new(), Vec::new(), HashMap::new(), Vec::new());
struct Look<'a, T> {
title: &'a dyn Fn(&T) -> String,
icon: Option<&'a LookFn<T>>,
badge: Option<&'a BadgeFn<T>>,
columns: &'a [Rc<TextFn<T>>],
has_children: Option<&'a HasFn<T>>,
}
fn walk<T: Identifiable>(n: TreeNode<T>, out: &mut Vec<Entry>, typed: &mut Vec<T::Id>, look: &Look<T>) -> usize {
let index = out.len();
let id = n.value.id();
out.push(Entry {
key: key_of(&id),
title: (look.title)(&n.value),
icon: look.icon.and_then(|f| f(&n.value)),
badge: look.badge.and_then(|f| f(&n.value)),
columns: look.columns.iter().map(|f| f(&n.value)).collect(),
children: Vec::new(),
expandable: !n.children.is_empty() || look.has_children.is_some_and(|f| f(&n.value)),
});
typed.push(id);
let kids: Vec<usize> = n.children.into_iter().map(|c| walk(c, out, typed, look)).collect();
out[index].children = kids;
index
}
let look = Look { title: &*title, icon: icon.as_deref(), badge: badge.as_deref(), columns: &columns, has_children: has_children.as_deref() };
let root_idx: Vec<usize> = roots.into_iter().map(|r| walk(r, &mut entries, &mut typed, &look)).collect();
for (i, e) in entries.iter().enumerate() {
let item = old.get(&e.key).cloned().unwrap_or_else(|| OutlineItem::new(mtm, i));
item.ivars().set(i);
keys.insert(e.key, item.clone());
items.push(item);
}
s.entries = entries;
s.roots = root_idx;
s.items = items;
s.by_key = keys;
*ids2.borrow_mut() = typed;
s.quiet = true;
drop(s);
ov2.reloadData();
let again: Vec<_> = {
let s = st.borrow();
s.entries.iter().zip(&s.items).filter(|(e, _)| open.contains(&e.key)).map(|(_, it)| it.clone()).collect()
};
for it in again {
unsafe { ov2.expandItem(Some(&it)) };
}
if expanded {
unsafe { ov2.expandItem_expandChildren(None, true) };
} else if sidebar {
let roots: Vec<_> = {
let s = st.borrow();
s.roots.iter().filter(|&&i| !old.contains_key(&s.entries[i].key)).map(|&i| s.items[i].clone()).collect()
};
for r in roots {
unsafe { ov2.expandItem(Some(&r)) };
}
}
st.borrow_mut().quiet = false;
untrack(|| restore2());
});
}));
if self.selection.is_some() {
node.own(Effect::new(move || restore()));
}
node.keep(Retained::into_super(source));
node.hold(state);
node
}
}
pub fn outline<T: Identifiable + 'static>(
roots: impl Fn() -> Vec<TreeNode<T>> + 'static,
title: impl Fn(&T) -> String + 'static,
) -> Outline<T> {
Outline { roots: Box::new(roots), title: Rc::new(title), icon: None, tint: None, badge: None, columns: Vec::new(), lazy: None, selection: None, sidebar: false, expanded: false, transparent: false }
}
pub fn sidebar<T: Identifiable + 'static>(
sections: impl Fn() -> Vec<TreeNode<T>> + 'static,
title: impl Fn(&T) -> String + 'static,
) -> Outline<T> {
Outline { sidebar: true, ..outline(sections, title) }
}