跳到正文

Tree

虚拟化层级集合,支持展开、选择和键盘导航。

正在加载交互演示…

#导入

从 quickgui 导入 Tree。

use quickgui::*;

#用法

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

#结构

  • Tree::root
  • Tree::row

#API 参考

展开条目查看说明和完整签名。短横线表示声明中未记录默认值。

TreeState

查看源码
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
查看源码
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
查看源码
loading_labelpub fn loading_label(&self) -> &Arc<str>—

Configures loading label for this part.

pub fn loading_label(&self) -> &Arc<str>
查看源码
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
查看源码
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
查看源码
layoutpub const fn layout(&self) -> TreeLayout—

Configures layout for this part.

pub const fn layout(&self) -> TreeLayout
查看源码
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
查看源码
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>
查看源码
node_countpub fn node_count(&self) -> usize—

Configures node count for this part.

pub fn node_count(&self) -> usize
查看源码
visible_countpub fn visible_count(&self) -> usize—

Configures visible count for this part.

pub fn visible_count(&self) -> usize
查看源码
root_countpub const fn root_count(&self) -> usize—

Configures root count for this part.

pub const fn root_count(&self) -> usize
查看源码
selected_idpub fn selected_id(&self) -> Option<ElementId>—

Configures selected id for this part.

pub fn selected_id(&self) -> Option<ElementId>
查看源码
selected_valuepub fn selected_value(&self) -> Option<&T>—

Configures selected value for this part.

pub fn selected_value(&self) -> Option<&T>
查看源码
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>>
查看源码
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>
查看源码
list_statepub fn list_state(&self) -> &ListState—

Configures list state for this part.

pub fn list_state(&self) -> &ListState
查看源码
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
查看源码
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
查看源码
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
查看源码
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
查看源码
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
查看源码
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
查看源码
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
查看源码
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
查看源码
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>
查看源码

TreeState::element

查看源码
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

查看源码
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.