TreeView
The TreeView is an IMGUI control that lets you create tree views, list views and multi-column tables for Editor tools.
Read time 9 minutesLast updated 6 days ago
Definition
- Type: Class
- Namespace: UnityEditor.IMGUI.Controls
- Assembly: UnityEditor.CoreModule
- Inherits from: TreeViewInternal
public abstract class TreeView : TreeViewInternal
Remarks
It is customizable with regards to row content rendering, dragging logic, selection logic, searching, sorting and renaming of items. To ensure consistency between TreeViews the following features are not customizable: Foldout arrow rendering, selection rendering, drag markers rendering.
A good place to start is TreeView.BuildRoot.
Constructors
Constructor | Description |
|---|---|
| TreeView(UnityEditor.IMGUI.Controls.TreeViewState) | The TreeView is always constructed with a state object and optionally a multi-column header object if a header is needed. |
| TreeView(UnityEditor.IMGUI.Controls.TreeViewState,UnityEditor.IMGUI.Controls.MultiColumnHeader) | The TreeView is always constructed with a state object and optionally a multi-column header object if a header is needed. |
Properties
Property | Description |
|---|---|
| getNewSelectionOverride | Register a callback to this field to override how the TreeView handles selection changes in response to keys and mouse clicks. |
| hoveredItem | Use this property to detect which TreeViewItem the mouse cursor is currently hovering over in the TreeView. This property is only valid if the enableItemHovering property has been set to true. |
| rootItem | The hidden root item of the TreeView (it is never rendered). |
| state | The state of the TreeView (expanded state, selection, scroll etc.) |
Methods
Method | Description |
|---|---|
| AddExpandedRows | Adds the expanded rows of the full tree to the input list. Only use this method if a full tree was built in BuildRoot. |
| BeginRename | Shows the rename overlay for a TreeViewItem. |
| BuildRoot | Abstract method that is required to be implemented. By default this method should create the full tree of TreeViewItems and return the root. |
| BuildRows | Override this method to take control of how the rows are generated. |
| CanBeParent | Override this method to control which items are allowed to be parents. |
| CanChangeExpandedState | Override this method to control whether an item can be expanded or collapsed by key or mouse. |
| CanMultiSelect | Override this method to control whether the item can be part of a multiselection. |
| CanRename | Override this method to control whether the item can be renamed using a keyboard shortcut or when clicking an already selected item. |
| CanStartDrag | This function is called whenever a TreeViewItem is clicked and dragged. It returns false by default. |
| DoesItemMatchSearch | Override this function to extend or change the search behavior. |
| FindItem | Finds a TreeViewItem by an ID. |
| FindRowOfItem | Returns the row of the given TreeViewItem. |
| FindRows | Useful for converting from TreeViewItem IDs to TreeViewItems using the current rows. |
| GetContentIndent | Returns the horizontal content offset for an item. This is where the content should begin (after the foldout arrow). |
| GetCustomRowHeight | Override to control individual row heights. |
| GetFoldoutIndent | Returns the horizontal foldout offset for an item. This is where the foldout arrow is rendered. |
| GetRenameRect | Override this method if custom GUI handling are used in TreeView.RowGUI. This method for controls where the rename overlay appears. |
| GetRows | This is the list of TreeViewItems that have been built in TreeView.BuildRows. |
| HandleDragAndDrop | Override this function to control the drag and drop behavior of the TreeView. |
| RowGUI | Override this method to add custom GUI content for the rows in the TreeView. |
| SelectionClick | Use this method in TreeView.RowGUI to peform the logic of a mouse click. |
Static Methods
Method | Description |
|---|---|
| CreateChildListForCollapsedParent | Creates a dummy TreeViewItem list. Useful when overriding TreeView.BuildRows to prevent building a full tree of items. |
| IsChildListForACollapsedParent | Utility method for checking if the |
| SetupDepthsFromParentsAndChildren | Utility method using the depth of the input TreeViewItem to set the correct depths for all its descendant TreeViewItems. |
| SetupParentsAndChildrenFromDepths | Utility method for initializing all the parent and children properties of the rows using the order and the depths values that have been set. |
Structs
Struct | Description |
|---|---|
| TreeView.CanStartDragArgs | Method arguments for the TreeView.CanStartDrag virtual method. |
| TreeView.DragAndDropArgs | Method arguments for the TreeView.HandleDragAndDrop virtual method. |
| TreeView.RowGUIArgs | Method arguments for the virtual method TreeView.RowGUI. |
Delegates
Delegate | Description |
|---|---|
| TreeView.GetNewSelectionFunction | A callback which determines how TreeView handles selection changes in response to keys and mouse clicks. |