Tree
虚拟化层级集合,支持展开、选择和键盘导航。
正在加载交互演示…
TreeState::new(nodes)
.element("files")#导入
从 quickgui 导入 Tree。
use quickgui::*;#用法
TreeState::new(nodes)
.element("files")#结构
Tree::rootTree::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—
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>—
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—
set_layoutpub 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—
visible_countpub fn visible_count(&self) -> usize—
root_countpub const fn root_count(&self) -> usize—
selected_idpub fn selected_id(&self) -> Option<ElementId>—
selected_valuepub fn selected_value(&self) -> Option<&T>—
rowpub fn row(&self, visible_index: usize) -> Option<TreeRow<'_, T>>—
visible_rowspub fn visible_rows(&self) -> std::ops::Range<usize>—
list_statepub 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—
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.
