TreeView

class in UnityEditor.IMGUI.Controls

Cambiar al Manual

Descripción

The TreeView is an IMGUI control that lets you create tree views, list views and multi-column tables for Editor tools.

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 BuildRoot.

Variables

baseIndentIndent used for all rows before the tree foldout arrows and content.
cellMarginWhen using a MultiColumnHeader this value adjusts the cell rects provided for all columns except the tree foldout column.
columnIndexForTreeFoldoutsWhen using a MultiColumnHeader this value should be set to the column index in which the foldout arrows should appear.
customFoldoutYOffsetCustom vertical offset of the foldout arrow.
depthIndentWidthValue that returns how far the foldouts are indented for each increasing depth value.
extraSpaceBeforeIconAndLabelValue to control the spacing before the default icon and label. Can be used e.g for placing a toggle button to the left of the content.
foldoutOverrideRegister a callback to this property to override the Foldout button in the TreeView.
foldoutWidthWidth of the built-in foldout arrow.
getNewSelectionOverrideRegister a callback to this field to override how the TreeView handles selection changes in response to keys and mouse clicks.
hasSearchThe current search state of the TreeView.
isDraggingTrue if the user is currently dragging one or more items in the TreeView, and false otherwise.
isInitializedThe TreeView is initialized by calling Reload(). Therefore returns false until Reload() is called the first time.
multiColumnHeaderGet the MultiColumnHeader of the TreeView. Can be null if the TreeView was created without a MultiColumnHeader.
rootItemThe hidden root item of the TreeView (it is never rendered).
rowHeightThe fixed height used for each row in the TreeView if GetCustomRowHeight have not been overridden.
searchStringCurrent search string of the TreeView.
showAlternatingRowBackgroundsEnable this to show alternating row background colors.
showBorderEnable this to show a border around the TreeView.
showingHorizontalScrollBarReturns true if the horizontal scroll bar is showing, otherwise false.
showingVerticalScrollBarReturns true if the vertical scroll bar is showing, otherwise false.
stateThe state of the TreeView (expanded state, selection, scroll etc.)
totalHeightReturns the sum of the TreeView row heights, the MultiColumnHeader height (if used) and the border (if used).
treeViewControlIDThe controlID used by the TreeView to obtain keyboard control focus.
treeViewRectThe Rect the TreeView is being rendered to.
useScrollViewWhen drawing the TreeView contents, will it be enclosed within a ScrollView?

Constructores

TreeViewThe TreeView is always constructed with a state object and optionally a multi-column header object if a header is needed.

Funciones Públicas

BeginRenameShows the rename overlay for a TreeViewItem.
CollapseAllCollapse all expanded items in the TreeView.
EndRenameEnds renaming if the rename overlay is shown. If called while the rename overlay is not being shown, this method does nothing.
ExpandAllExpand all collapsed items in the TreeView.
FrameItemThis will reveal the item with ID id (by expanding the ancestors of that item) and will make sure it is visible in the ScrollView.
GetExpandedReturns a list of TreeViewItem IDs that are currently expanded in the TreeView.
GetRowsThis is the list of TreeViewItems that have been built in BuildRows.
GetSelectionReturns the list of TreeViewItem IDs that are currently selected.
HasFocusReturns true if the TreeView and its EditorWindow have keyboard focus.
HasSelectionReturns true if the TreeView has a selection.
IsExpandedReturns true if the TreeViewItem with ID id is currently expanded.
IsSelectedReturns true if the TreeViewItem with ID id is currently selected.
OnGUIThis is the main GUI method of the TreeView, where the TreeViewItems are processed and drawn.
ReloadCall this to force the TreeView to reload its data. This in turn causes BuildRoot and BuildRows to be called.
RepaintRequest a repaint of the window that the TreeView is rendered in.
SelectAllRowsSelects all rows in the TreeView.
SetExpandedSet a single TreeViewItem to be expanded or collapsed.
SetExpandedRecursiveExpand or collapse all items under item with id.
SetFocusCalling this function changes the keyboard focus to the TreeView.
SetFocusAndEnsureSelectedItemCalling this function changes the keyboard focus to the TreeView and ensures an item is selected. Use this function to enable key navigation of the TreeView.
SetSelectionSet the selected items of the TreeView.

Funciones Protegidas

AddExpandedRowsAdds the expanded rows of the full tree to the input list. Only use this method if a full tree was built in BuildRoot.
AfterRowsGUIThis is called after all rows have their RowGUI called.
BeforeRowsGUIThis is called before any rows have their RowGUI called.
BuildRootAbstract method that is required to be implemented. By default this method should create the full tree of TreeViewItems and return the root.
BuildRowsOverride this method to take control of how the rows are generated.
CanBeParentOverride this method to control which items are allowed to be parents.
CanChangeExpandedStateOverride this method to control whether an item can be expanded or collapsed by key or mouse.
CanMultiSelectOverride this method to control whether the item can be part of a multiselection.
CanRenameOverride this method to control whether the item can be renamed using a keyboard shortcut or when clicking an already selected item.
CanStartDragThis function is called whenever a TreeViewItem is clicked and dragged. It returns false by default.
CenterRectUsingSingleLineHeightModifies the input rect so it is centered and have a height equal to EditorGUIUtility.singleLineHeight.
CommandEventHandlingThis function is called automatically and handles the ExecuteCommand events for “SelectAll” and “FrameSelection”. Override this function to extend or avoid Command events.
ContextClickedOverride this method to handle context clicks outside any items (but still in the TreeView rect).
ContextClickedItemOverride this method to handle a context click on an item with ID TreeViewItem.id.
DoesItemMatchSearchOverride this function to extend or change the search behavior.
DoubleClickedItemOverride this method to handle double click events on an item.
ExpandedStateChangedOverride to get notified when items are expanded or collapsed. This is a general notification that the expanded state has changed.
FindItemFinds a TreeViewItem by an ID.
FindRowOfItemReturns the row of the given TreeViewItem.
FindRowsUseful for converting from TreeViewItem IDs to TreeViewItems using the current rows.
GetAncestorsThis method is e.g. used for revealing items that are currently under a collapsed item.
GetCellRectForTreeFoldoutsUtility for multi column setups. This method will clip the input rowRect against the column rect defined by columnIndexForTreeFoldouts to get the cell rect where the the foldout arrows appear.
GetContentIndentReturns the horizontal content offset for an item. This is where the content should begin (after the foldout arrow).
GetCustomRowHeightOverride to control individual row heights.
GetDescendantsThatHaveChildrenReturns all descendants for the item with ID id that have children.
GetFirstAndLastVisibleRowsReturns the first and the last indices of the rows that are visible in the scroll view of the TreeView.
GetFoldoutIndentReturns the horizontal foldout offset for an item. This is where the foldout arrow is rendered.
GetRenameRectOverride this method if custom GUI handling are used in RowGUI. This method for controls where the rename overlay appears.
GetRowRectGet the rect for a row.
HandleDragAndDropOverride this function to control the drag and drop behavior of the TreeView.
KeyEventOverride this method to handle events when the TreeView has keyboard focus.
RefreshCustomRowHeightsRefreshes the cache of custom row rects based on the heights returned by GetCustomRowHeight.
RenameEndedCalled when rename ends either by the user completing the renaming process, when the rename overlay loses focus or is closed using EndRename.
RowGUIOverride this method to add custom GUI content for the rows in the TreeView.
SearchChangedOverride the method to get notified of search string changes.
SelectionChangedOverride the method to get notified of selection changes.
SelectionClickUse this method in RowGUI to peform the logic of a mouse click.
SetupDragAndDropThis function is called when CanStartDrag returns true.
SingleClickedItemOverride this method to handle single click events on an item.
SortItemIDsInRowOrderReturns a list sorted in the order in which they are shown in the TreeView.

Funciones Estáticas

CreateChildListForCollapsedParentCreates a dummy TreeViewItem list. Useful when overriding BuildRows to prevent building a full tree of items.
IsChildListForACollapsedParentUtility method for checking if the childList is identical to the one returned by the CreateChildListForCollapsedParent method.
SetupDepthsFromParentsAndChildrenUtility method using the depth of the input TreeViewItem to set the correct depths for all its descendant TreeViewItems.
SetupParentsAndChildrenFromDepthsUtility method for initializing all the parent and children properties of the rows using the order and the depths values that have been set.

Delegados

DoFoldoutCallbackCallback signature used to override the TreeView foldout. See foldoutOverride.
GetNewSelectionFunctionA callback which determines how TreeView handles selection changes in response to keys and mouse clicks.