Source/Interface/Views/Tree Views

= Tree-Views =



Available via:

This kind of view is made for showing data that is hierarchical. Items support:
 * Custom layouts
 * Renaming
 * Activating
 * Custom drag & drop controllers
 * Custom context menus
 * Collapsing parent items

Building tree UIs becomes much simpler as the UI code does a lot of the heavy lifting. The tree is built by first defining a number of items and child items, then each visible item is built into a row layout.

Creating a Tree-View
Defining a new tree can be done as simple as this:

Each item added to the tree will be displayed as a row (if it is visible), nested under its parent. Parent items are collapsible. In the example above, the items are of type `ui::BasicTreeViewItem`, which is a predefined item type for simple tree rows. Each row only contains an icon and a label. For more control over what goes into a row, custom item types can be defined in a similar fashion: Different item types can be mixed in a tree.

Lastly, the actual instance of the tree-view can be created for a `uiBlock`:

For a more complex real-life example, check the asset catalog tree-view code: https://developer.blender.org/diffusion/B/browse/master/source/blender/editors/space_file/asset_catalog_tree_view.cc

Design Notes

 * Every row has a tree-row button (`UI_BTYPE_TREEROW`). An overlapping layout is used to place it underneath the customizable row layout of each item.

`BasicTreeViewItem`: Custom Activation Behavior
To not have to create a sub-class of `ui::BasicTreeViewItem` just to customize its activation behavior, it offers a different way to set the custom behavior:

Improvements/To-Do's
For general view system To-Do's, see.


 * Support reordering or changing the hierarchy via drag & drop (the generic parts of it, like finding and visualizing the item to insert into/before/after, drop polls, reinsert callbacks, etc.)
 * Avoid `O(n^2)` complexity of state reconstruction, more precisely `AbstractTreeView::update_children_from_old_recursive`.
 * Draw hierarchy lines.