pub struct Tree<T: 'static = (), K: 'static = (), R = RowRender<T>> { /* private fields */ }Expand description
A virtualised tree of rows, shown by the platform’s own tree control, which draws the disclosures and indents the levels.
Tree::new(move || folders.get(), |f| f.path.clone(), |f| f.children(), |f| FolderRow(f))
.expanded(open) // Signal<Vec<K>>: the open rows' keys
.selected(selected) // Signal<Vec<K>>: the selected keys
.on_activate(|path| open(path))
.grow(1.0)children is None for a row that never opens (a file) and Some for
one that does (a folder, empty or not yet read). It’s called for each
row that shows, so keep it cheap; signals it reads are tracked, so
children that load later show when they come. Rows are keyed as a
List’s, and everything a List has works the same way.
Rows are read by screen readers (and found by tests) as tree items named by their text, with their level and whether they’re open.
The type’s defaults make Tree alone name the widget, for
Tweak<Tree>.
Implementations§
Source§impl<T: 'static, K: 'static, R> Tree<T, K, R>
impl<T: 'static, K: 'static, R> Tree<T, K, R>
Sourcepub fn on_move(
self,
moves: RowMoves,
handler: impl Fn(Vec<K>, RowDrop<K>) + 'static,
) -> Self
pub fn on_move( self, moves: RowMoves, handler: impl Fn(Vec<K>, RowDrop<K>) + 'static, ) -> Self
Rows can be dragged within the tree, with the platform’s own row
drag (the selection, when a selected row is dragged), and dropped
where moves says, as a List’s on_move:
onto a row (into a folder), before one (at its place among its
folder’s rows), or at the end (after the top rows). A folder can’t
be dropped inside itself. handler gets the rows, in the tree’s
order, and where; the tree shows nothing moved until the app moves
its data. Offer another way too (a Move command): dragging isn’t
reachable from the keyboard or assistive technology.
Sourcepub fn loading(self, loading: impl Fn(&T) -> bool + 'static) -> Self
pub fn loading(self, loading: impl Fn(&T) -> bool + 'static) -> Self
Which rows’ children are being read: a folder whose files take a
moment to come, as on a network share. Once loading has said so
for half a second, the platform’s spinner shows where the row’s
disclosure is, as Finder shows one in place of a folder’s triangle;
a folder read quicker opens without one flashing. Signals it reads
are tracked, as children’s are. The tree doesn’t read children
itself: the app says when they’re read, and children gives them.
Sourcepub fn expanded(self, expanded: Signal<Vec<K>>) -> Self
pub fn expanded(self, expanded: Signal<Vec<K>>) -> Self
Binds which rows are open, as their keys, both ways: the user opens and closes rows (the disclosure, the platform’s keys, assistive technology), and the app can too. A key stays while its row is in a closed folder, so reopening the folder shows the row open again. Without it, the tree keeps its own, every row closed at first.
Sourcepub fn drag_files(self, file: impl Fn(&T) -> Option<PathBuf> + 'static) -> Self
pub fn drag_files(self, file: impl Fn(&T) -> Option<PathBuf> + 'static) -> Self
Rows can be dragged out of the app, carrying the files their items
stand for, as a List’s drag_files.
Sourcepub fn selected(self, selected: Signal<Vec<K>>) -> Self
pub fn selected(self, selected: Signal<Vec<K>>) -> Self
Binds the selection, as the selected rows’ keys, both ways. Trees
with a selection bound select one row at a time unless
selection_mode says otherwise. Closing a
folder deselects its rows.
Sourcepub fn selection_mode(self, mode: impl IntoValue<SelectionMode>) -> Self
pub fn selection_mode(self, mode: impl IntoValue<SelectionMode>) -> Self
How many rows can be selected, as a List’s
selection_mode.
Sourcepub fn list_style(self, style: ListStyle) -> Self
pub fn list_style(self, style: ListStyle) -> Self
How the tree sits in its surroundings, as a List’s
list_style.
Sourcepub fn on_activate(self, handler: impl Fn(K) + 'static) -> Self
pub fn on_activate(self, handler: impl Fn(K) + 'static) -> Self
Called with a row’s key when it’s activated: double-clicked, or Enter pressed on it. It opens nothing: what a folder’s activation does is the app’s.
Sourcepub fn on_key(
self,
key: impl Into<Shortcut>,
handler: impl Fn() + 'static,
) -> Self
pub fn on_key( self, key: impl Into<Shortcut>, handler: impl Fn() + 'static, ) -> Self
Runs handler when key is pressed while the tree, or a control
inside it, has keyboard focus, and the focused control doesn’t use
the key itself (the arrows, the keys that open and close rows, and
what else the platform’s tree takes), as a List’s
on_key.
Sourcepub fn estimated_row_height(self, height: impl Into<Length>) -> Self
pub fn estimated_row_height(self, height: impl Into<Length>) -> Self
How high rows are likely to be, for platforms that size rows before they’re shown (AppKit). By default, the rows shown so far tell.
Sourcepub fn handle(self, handle: ListHandle<K>) -> Self
pub fn handle(self, handle: ListHandle<K>) -> Self
Connects a ListHandle, to scroll the tree from code. A row in a
closed folder doesn’t show, so it’s scrolled to once its folders are
open (expanded).
Trait Implementations§
Source§impl<T: 'static, K: 'static, R> ElementBuilder for Tree<T, K, R>
impl<T: 'static, K: 'static, R> ElementBuilder for Tree<T, K, R>
fn element(&mut self) -> &mut Element
Source§fn style(self, f: impl FnOnce(&mut Style)) -> Self
fn style(self, f: impl FnOnce(&mut Style)) -> Self
Source§fn style_with(self, f: impl Fn(&mut Style) + 'static) -> Self
fn style_with(self, f: impl Fn(&mut Style) + 'static) -> Self
f re-runs whenever the
signals it reads change, and must set every field it cares about.fn width(self, value: impl IntoValue<Length>) -> Self
fn height(self, value: impl IntoValue<Length>) -> Self
fn min_width(self, value: impl IntoValue<Length>) -> Self
fn min_height(self, value: impl IntoValue<Length>) -> Self
fn max_width(self, value: impl IntoValue<Length>) -> Self
fn max_height(self, value: impl IntoValue<Length>) -> Self
fn aspect_ratio(self, value: impl IntoValue<f32>) -> Self
fn padding(self, value: impl IntoValue<Length>) -> Self
fn padding_x(self, value: impl IntoValue<Length>) -> Self
fn padding_y(self, value: impl IntoValue<Length>) -> Self
fn padding_start(self, value: impl IntoValue<Length>) -> Self
fn padding_end(self, value: impl IntoValue<Length>) -> Self
fn padding_top(self, value: impl IntoValue<Length>) -> Self
fn padding_bottom(self, value: impl IntoValue<Length>) -> Self
fn margin(self, value: impl IntoValue<Length>) -> Self
fn margin_x(self, value: impl IntoValue<Length>) -> Self
fn margin_y(self, value: impl IntoValue<Length>) -> Self
fn margin_start(self, value: impl IntoValue<Length>) -> Self
fn margin_end(self, value: impl IntoValue<Length>) -> Self
fn margin_top(self, value: impl IntoValue<Length>) -> Self
fn margin_bottom(self, value: impl IntoValue<Length>) -> Self
fn grow(self, value: impl IntoValue<f32>) -> Self
fn shrink(self, value: impl IntoValue<f32>) -> Self
fn basis(self, value: impl IntoValue<Length>) -> Self
fn align_self(self, value: impl IntoValue<Align>) -> Self
Source§fn justify_self(self, value: impl IntoValue<Align>) -> Self
fn justify_self(self, value: impl IntoValue<Align>) -> Self
Source§fn top(self, value: impl IntoValue<Length>) -> Self
fn top(self, value: impl IntoValue<Length>) -> Self
absolute()).fn bottom(self, value: impl IntoValue<Length>) -> Self
Source§fn start(self, value: impl IntoValue<Length>) -> Self
fn start(self, value: impl IntoValue<Length>) -> Self
fn end(self, value: impl IntoValue<Length>) -> Self
fn grid_column(self, value: impl IntoValue<GridPlacement>) -> Self
fn grid_row(self, value: impl IntoValue<GridPlacement>) -> Self
fn direction(self, value: impl IntoValue<TextDirection>) -> Self
display the node had.fn size( self, width: impl IntoValue<Length>, height: impl IntoValue<Length>, ) -> Self
Source§fn tooltip(self, text: impl IntoValue<String>) -> Self
fn tooltip(self, text: impl IntoValue<String>) -> Self
entries, and built again whenever what it
reads changes, as Menu::children_with builds its entries.entries each time the platform opens it,
for a menu that depends on what’s selected or under the pointer at
that moment: a table row’s menu acting on the selection. What it
reads is read then, not followed.