UI Toolbox logoUI Toolbox

DataTree

DataTree in UIToolbox shows a tree of any objects. It wraps the native TreeView, so the rows are virtual. You give it the root objects and a function that gives the children of an object. You do not build TreeViewItemData or ids.

<tb:DataTree name="scene" style="height: 260px;" />
var tree = root.Q<DataTree>("scene");
tree.SetRoots(scene.GetRootGameObjects(), item => ((GameObject)item).transform.Cast<Transform>().Select(t => t.gameObject),
    item => ((GameObject)item).name);
searchField.RegisterValueChangedCallback(evt => tree.SearchText = evt.newValue);
tree.SelectionChanged += items => Debug.Log(tree.SelectedItem);
Member Description
SetRoots(roots, children, text) The root objects, the children of an object (null for a leaf), and the row text (default ToString).
Refresh() Reads the items again after code adds, removes or changes them.
SearchText Shows the items whose text contains it, in any case, with their parents, all expanded. The match is marked. Empty shows all items.
SelectedItems, SelectedItem, ClearSelection, SelectionChanged The selection as objects.
ItemsChosen A double click or Enter on items.
RowHeight (row-height, 20) The fixed row height.
Select(item) Expands the parents, selects the item and scrolls to it. False when the item is not shown.
SetExpanded(item, expanded), IsExpanded(item), ParentOf(item) The expanded state and the parent of a shown item.
View The native TreeView, for the settings that the tree does not wrap, such as selectionType, ExpandAll or a custom makeItem and bindItem.

Styling

Class Element
tb-data-tree The tree (grows; surface background, border). The variable --tb-data-tree-match on it is the mark color of search matches; it must let the text show through.
tb-data-tree__view The native TreeView. The workspace theme colors its rows, arrows and selection.
tb-data-tree__label The text of a row (ellipsis).