Skip to content

Tree

A virtualized hierarchical collection with expansion, selection, and keyboard navigation.

Loading interactive demo…

#Import

Import Tree from quickgui.

use quickgui::*;

#Usage

TreeState::new(nodes)
    .element("files")

#Anatomy

  • Tree::root
  • Tree::row

#API reference

Expand an entry for its description and complete signature. A dash means no declaration default is documented.

TreeState

View source
pub fn new(nodes: impl IntoIterator<Item = TreeNode<T>>) -> Result<Self, TreeError>
with_layoutpub fn with_layout(mut self, layout: TreeLayout) -> Self—

Configures with layout for this part.

pub fn with_layout(mut self, layout: TreeLayout) -> Self
View source
with_loading_labelpub fn with_loading_label(mut self, label: impl Into<Arc<str>>) -> Self—

Replace the accessible name of the placeholder row shown while children load. Longer text than [`MAX_TREE_LABEL_BYTES`] keeps [`DEFAULT_TREE_LOADING_LABEL`].

pub fn with_loading_label(mut self, label: impl Into<Arc<str>>) -> Self
View source
loading_labelpub fn loading_label(&self) -> &Arc<str>—

Configures loading label for this part.

pub fn loading_label(&self) -> &Arc<str>
View source
is_loadingpub fn is_loading(&self, id: impl Into<ElementId>) -> bool—

Whether one branch is expanded with its children still outstanding.

pub fn is_loading(&self, id: impl Into<ElementId>) -> bool
View source
is_pendingpub fn is_pending(&self, id: impl Into<ElementId>) -> bool—

Whether one branch still has to load its children.

pub fn is_pending(&self, id: impl Into<ElementId>) -> bool
View source
layoutpub const fn layout(&self) -> TreeLayout—

Configures layout for this part.

pub const fn layout(&self) -> TreeLayout
View source
set_layoutpub fn set_layout(&mut self, layout: TreeLayout) -> bool—

Configures set layout for this part.

pub fn set_layout(&mut self, layout: TreeLayout) -> bool
View source
set_nodespub fn set_nodes( &mut self, nodes: impl IntoIterator<Item = TreeNode<T>>, ) -> Result<(), TreeError>—

Configures set nodes for this part.

pub fn set_nodes( &mut self, nodes: impl IntoIterator<Item = TreeNode<T>>, ) -> Result<(), TreeError>
View source
node_countpub fn node_count(&self) -> usize—

Configures node count for this part.

pub fn node_count(&self) -> usize
View source
visible_countpub fn visible_count(&self) -> usize—

Configures visible count for this part.

pub fn visible_count(&self) -> usize
View source
root_countpub const fn root_count(&self) -> usize—

Configures root count for this part.

pub const fn root_count(&self) -> usize
View source
selected_idpub fn selected_id(&self) -> Option<ElementId>—

Configures selected id for this part.

pub fn selected_id(&self) -> Option<ElementId>
View source
selected_valuepub fn selected_value(&self) -> Option<&T>—

Configures selected value for this part.

pub fn selected_value(&self) -> Option<&T>
View source
rowpub fn row(&self, visible_index: usize) -> Option<TreeRow<'_, T>>—

Configures row for this part.

pub fn row(&self, visible_index: usize) -> Option<TreeRow<'_, T>>
View source
visible_rowspub fn visible_rows(&self) -> std::ops::Range<usize>—

Configures visible rows for this part.

pub fn visible_rows(&self) -> std::ops::Range<usize>
View source
list_statepub fn list_state(&self) -> &ListState—

Configures list state for this part.

pub fn list_state(&self) -> &ListState
View source
is_expandedpub fn is_expanded(&self, id: impl Into<ElementId>) -> bool—

Configures is expanded for this part.

pub fn is_expanded(&self, id: impl Into<ElementId>) -> bool
View source
set_expandedpub fn set_expanded(&mut self, id: impl Into<ElementId>, expanded: bool) -> bool—

Configures set expanded for this part.

pub fn set_expanded(&mut self, id: impl Into<ElementId>, expanded: bool) -> bool
View source
toggle_expandedpub fn toggle_expanded(&mut self, id: impl Into<ElementId>) -> bool—

Configures toggle expanded for this part.

pub fn toggle_expanded(&mut self, id: impl Into<ElementId>) -> bool
View source
selectpub fn select(&mut self, id: impl Into<ElementId>) -> bool—

Configures select for this part.

pub fn select(&mut self, id: impl Into<ElementId>) -> bool
View source
focus_handlepub fn focus_handle(id: impl Into<ElementId>) -> FocusHandle—

Configures focus handle for this part.

pub fn focus_handle(id: impl Into<ElementId>) -> FocusHandle
View source
row_idpub fn row_id(id: impl Into<ElementId>, node: ElementId) -> ElementId—

Configures row id for this part.

pub fn row_id(id: impl Into<ElementId>, node: ElementId) -> ElementId
View source
disclosure_idpub fn disclosure_id(id: impl Into<ElementId>, node: ElementId) -> ElementId—

Configures disclosure id for this part.

pub fn disclosure_id(id: impl Into<ElementId>, node: ElementId) -> ElementId
View source
loading_row_idpub fn loading_row_id(id: impl Into<ElementId>, node: ElementId) -> ElementId—

The stable identity of the placeholder row mounted while one branch loads.

pub fn loading_row_id(id: impl Into<ElementId>, node: ElementId) -> ElementId
View source
set_childrenpub fn set_children( &mut self, id: impl Into<ElementId>, children: impl IntoIterator<Item = TreeNode<T>>, ) -> Result<bool, TreeError>—

Supply the children of a pending branch in one atomic, validated splice. The replacement is built and validated before any live state changes: an over-deep, oversize, or duplicate-ID payload leaves the tree exactly as it was. On success the branch stops being pending, its placeholder row disappears, and selection, expansion, and the logical scroll anchor are preserved. An unknown node ID reports `Ok(false)`.

pub fn set_children( &mut self, id: impl Into<ElementId>, children: impl IntoIterator<Item = TreeNode<T>>, ) -> Result<bool, TreeError>
View source

TreeState::element

View source
pub fn element<V, E, RenderRow, Activate>( &mut self, cx: &mut ViewContext<'_, V>, id: impl Into<ElementId>, access: fn(&mut V) -> &mut TreeState<T>, render_row: RenderRow, activate: Activate, ) -> Element where V: 'static, T: 'static, E: IntoElement, RenderRow: FnMut(TreeRow<'_, T>, Option<Element>) -> E, Activate: Fn(&mut V, ElementId, &mut EventContext) + Clone + 'static,

Build a complete unstyled virtualized, expandable, keyboard-navigable tree. `render_row` runs only for mounted rows and receives an optional behavior-decorated, appearance-free disclosure element. The caller decides where to place that control and owns the complete row layout and paint. QuickGUI decorates the returned row with fixed virtual geometry, tree semantics, selection, and pointer behavior. `activate` receives the selected application value by stable node ID; the tree retains no closure or scheduler afterward.

TreeState::element_with

View source
pub fn element_with<V, E, RenderRow, Activate>( &mut self, cx: &mut ViewContext<'_, V>, id: impl Into<ElementId>, access_source: StateAccessor<V, TreeState<T>>, mut render_row: RenderRow, activate: Activate, ) -> Element where V: 'static, T: 'static, E: IntoElement, RenderRow: FnMut(TreeRow<'_, T>, Option<Element>) -> E, Activate: Fn(&mut V, ElementId, &mut EventContext) + Clone + 'static,

Build the tree against a per-instance retained-state accessor. A host that renders many declared trees through one view passes an accessor that captures which [`TreeState`] each registered listener resolves.