Class TreeViewItem
A tree view item that can be used directly in a ScrollView or any vertical container.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class TreeViewItem : VisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler
Remarks
A row is composed of, in order: the caret gutter (always reserved, even on a leaf, so icons and labels line up in a column), an optional icon, the label, and an optional trailingContainer pinned to the right edge of the row.
The trailing strip overlays the row. While it is visible — on hover, or permanently when trailingVisible is true — the label reserves exactly the strip's measured width so text stops before the actions instead of running under them. When the row becomes too narrow to keep a readable label next to the actions, the strip collapses to a single overflow button that reopens the very same trailing content in a Popover. Both thresholds are measured from GeometryChangedEvent, and the minimum readable label width comes from a token-driven probe element so it rescales with density.
Examples
<UXML xmlns:ui="Unity.AppUI.UI">
<ui:TreeViewItem label="Assets" icon="folder" show-caret="true" expanded="true">
<ui:TreeViewItem label="Scenes" depth="1" caret-position="End" />
</ui:TreeViewItem>
</UXML>
Constructors
TreeViewItem()
Initializes a new instance of the TreeViewItem class.
Declaration
public TreeViewItem()
Fields
caretButtonUssClassName
The USS class name for the caret button of the TreeViewItem.
Declaration
public const string caretButtonUssClassName = "appui-tree-view-item__caret-button"
Field Value
| Type | Description |
|---|---|
| string |
caretGutterUssClassName
The USS class name for the always-reserved leading caret gutter of the TreeViewItem.
Declaration
public const string caretGutterUssClassName = "appui-tree-view-item__caret-gutter"
Field Value
| Type | Description |
|---|---|
| string |
caretIconUssClassName
The USS class name for the caret icon of the TreeViewItem.
Declaration
public const string caretIconUssClassName = "appui-tree-view-item__caret-icon"
Field Value
| Type | Description |
|---|---|
| string |
caretPositionUssClassName
The USS class name for the TreeViewItem based on its caret position.
Declaration
public const string caretPositionUssClassName = "appui-tree-view-item--caret-"
Field Value
| Type | Description |
|---|---|
| string |
contentContainerUssClassName
The USS class name for the content container of the TreeViewItem.
Declaration
public const string contentContainerUssClassName = "appui-tree-view-item__content-container"
Field Value
| Type | Description |
|---|---|
| string |
contentViewportUssClassName
The USS class name for the content viewport of the TreeViewItem.
Declaration
public const string contentViewportUssClassName = "appui-tree-view-item__content-viewport"
Field Value
| Type | Description |
|---|---|
| string |
depthVariantUssClassName
The USS class name for the TreeViewItem based on its depth.
Declaration
public const string depthVariantUssClassName = "appui-tree-view-item--depth-"
Field Value
| Type | Description |
|---|---|
| string |
draggingVariantUssClassName
The USS class name for the TreeViewItem while it is the row being dragged.
Declaration
public const string draggingVariantUssClassName = "appui-tree-view-item--dragging"
Field Value
| Type | Description |
|---|---|
| string |
dropIndicatorAfterUssClassName
The USS class name for the drop indicator shown below the row.
Declaration
public const string dropIndicatorAfterUssClassName = "appui-tree-view-item__drop-indicator-after"
Field Value
| Type | Description |
|---|---|
| string |
dropIndicatorBeforeUssClassName
The USS class name for the drop indicator shown above the row.
Declaration
public const string dropIndicatorBeforeUssClassName = "appui-tree-view-item__drop-indicator-before"
Field Value
| Type | Description |
|---|---|
| string |
dropPositionUssClassName
The USS class name for the TreeViewItem based on the active drop position.
Declaration
public const string dropPositionUssClassName = "appui-tree-view-item--drop-"
Field Value
| Type | Description |
|---|---|
| string |
expandedVariantUssClassName
The USS class name for the TreeViewItem when it is expanded.
Declaration
public const string expandedVariantUssClassName = "appui-tree-view-item--expanded"
Field Value
| Type | Description |
|---|---|
| string |
headerUssClassName
The USS class name for the header of the TreeViewItem.
Declaration
public const string headerUssClassName = "appui-tree-view-item__header"
Field Value
| Type | Description |
|---|---|
| string |
iconUssClassName
The USS class name for the leading icon of the TreeViewItem.
Declaration
public const string iconUssClassName = "appui-tree-view-item__icon"
Field Value
| Type | Description |
|---|---|
| string |
interactableVariantUssClassName
The USS class name for the TreeViewItem when it is interactable (has a clickable header).
Declaration
public const string interactableVariantUssClassName = "appui-tree-view-item--interactable"
Field Value
| Type | Description |
|---|---|
| string |
labelBadgeUssClassName
The USS class name for the badge that follows the label of the TreeViewItem.
Declaration
public const string labelBadgeUssClassName = "appui-tree-view-item__label-badge"
Field Value
| Type | Description |
|---|---|
| string |
minLabelProbeUssClassName
The USS class name for the hidden probe carrying the minimum readable label width.
Declaration
public const string minLabelProbeUssClassName = "appui-tree-view-item__min-label-probe"
Field Value
| Type | Description |
|---|---|
| string |
overflowButtonUssClassName
The USS class name for the overflow button the trailing strip collapses to on a narrow row.
Declaration
public const string overflowButtonUssClassName = "appui-tree-view-item__overflow-button"
Field Value
| Type | Description |
|---|---|
| string |
overflowPopoverUssClassName
The USS class name for the popover content hosting the trailing strip while it is collapsed.
Declaration
public const string overflowPopoverUssClassName = "appui-tree-view-item__overflow-popover"
Field Value
| Type | Description |
|---|---|
| string |
selectedVariantUssClassName
The USS class name for the TreeViewItem when it is selected.
Declaration
public const string selectedVariantUssClassName = "appui-tree-view-item--selected"
Field Value
| Type | Description |
|---|---|
| string |
titleLabelUssClassName
The USS class name for the title label of the TreeViewItem.
Declaration
public const string titleLabelUssClassName = "appui-tree-view-item__title-label"
Field Value
| Type | Description |
|---|---|
| string |
trailingCollapsedVariantUssClassName
The USS class name for the TreeViewItem while its trailing strip is collapsed into the overflow button.
Declaration
public const string trailingCollapsedVariantUssClassName = "appui-tree-view-item--trailing-collapsed"
Field Value
| Type | Description |
|---|---|
| string |
trailingContainerUssClassName
The USS class name for the trailing container of the TreeViewItem.
Declaration
public const string trailingContainerUssClassName = "appui-tree-view-item__trailing-container"
Field Value
| Type | Description |
|---|---|
| string |
trailingShownVariantUssClassName
The USS class name for the TreeViewItem while its trailing content is showing.
Declaration
public const string trailingShownVariantUssClassName = "appui-tree-view-item--trailing-shown"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The USS class name for the TreeViewItem.
Declaration
public const string ussClassName = "appui-tree-view-item"
Field Value
| Type | Description |
|---|---|
| string |
withCaretVariantUssClassName
The USS class name for the TreeViewItem when it has a caret.
Declaration
public const string withCaretVariantUssClassName = "appui-tree-view-item--with-caret"
Field Value
| Type | Description |
|---|---|
| string |
withIconVariantUssClassName
The USS class name for the TreeViewItem when it has a leading icon.
Declaration
public const string withIconVariantUssClassName = "appui-tree-view-item--with-icon"
Field Value
| Type | Description |
|---|---|
| string |
withLabelBadgeVariantUssClassName
The USS class name for the TreeViewItem when it has a label badge.
Declaration
public const string withLabelBadgeVariantUssClassName = "appui-tree-view-item--with-label-badge"
Field Value
| Type | Description |
|---|---|
| string |
withTrailingVariantUssClassName
The USS class name for the TreeViewItem when it has trailing content.
Declaration
public const string withTrailingVariantUssClassName = "appui-tree-view-item--with-trailing"
Field Value
| Type | Description |
|---|---|
| string |
Properties
caretClickable
Gets or sets the clickable behavior for the caret button of the TreeViewItem.
Declaration
public Pressable caretClickable { get; set; }
Property Value
| Type | Description |
|---|---|
| Pressable |
caretIconElement
The caret glyph element. The tree sets its icon for every row through caretIcon; this is the per-row escape hatch.
Declaration
public Icon caretIconElement { get; }
Property Value
| Type | Description |
|---|---|
| Icon |
caretPosition
Which side of the row the expand/collapse caret sits on. Defaults to Start, matching the registry.
Declaration
[CreateProperty]
[UxmlAttribute]
public CaretPosition caretPosition { get; set; }
Property Value
| Type | Description |
|---|---|
| CaretPosition |
Remarks
The leading caret gutter is reserved on every row, caret or not, so icons and labels stay column-aligned; End keeps that empty gutter and moves the caret itself after the label.
clickable
Gets or sets the clickable behavior for the header of the TreeViewItem.
Declaration
[CreateProperty]
public Pressable clickable { get; set; }
Property Value
| Type | Description |
|---|---|
| Pressable |
contentContainer
Logical container where child elements are added. If a child is added to this element, the child is added to this element's content container instead.
Declaration
public override VisualElement contentContainer { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
Overrides
depth
Gets or sets the depth of the TreeViewItem in the tree view hierarchy. This is used to determine the indentation level of the item.
Declaration
[CreateProperty]
[UxmlAttribute]
public int depth { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
draggable
Whether this specific item can be picked up by a drag. Only meaningful when the owning TreeList has a onReparent handler; a non-draggable item is still a valid drop target.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool draggable { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
dragging
True while this row is the one being dragged. Set by the owning TreeList.
Declaration
public bool dragging { get; }
Property Value
| Type | Description |
|---|---|
| bool |
dropIndicator
Draw this row's drop indicator from the outside, for a drag the tree is not running itself.
Declaration
[CreateProperty]
public Optional<DropPosition> dropIndicator { get; set; }
Property Value
| Type | Description |
|---|---|
| Optional<DropPosition> |
Remarks
A pointer-driven drag produces none of the events the tree's own drag handling watches for, so a tree whose rows are targets for one has no way to reach the built-in indicators. Feeding the position in keeps such a drop looking exactly like a native one instead of growing a second, divergent set of highlight styles.
Ignored while the tree's own drag is targeting this row, so the two can never contradict each other. Unset draws nothing, so a tree that never sees an outside drag is unaffected.
dropPosition
The active drop position for this row while a drag hovers it, or null when it is not the current drop target. Set by the owning TreeList.
Declaration
public DropPosition? dropPosition { get; }
Property Value
| Type | Description |
|---|---|
| DropPosition? |
expanded
Gets or sets whether the TreeViewItem is expanded or collapsed.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool expanded { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
icon
Gets or sets the name of the leading icon shown between the caret gutter and the label. Null or empty hides the icon slot entirely.
Declaration
[CreateProperty]
[UxmlAttribute]
public string icon { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
iconElement
The leading icon element, for callers that need to set a variant or a sprite directly.
Declaration
public Icon iconElement { get; }
Property Value
| Type | Description |
|---|---|
| Icon |
label
Gets or sets the label of the TreeViewItem.
Declaration
[CreateProperty]
[UxmlAttribute]
public string label { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
labelBadge
Gets or sets the name of a small glyph that belongs to the name — a scene's startup star, a dirty marker. Null or empty hides it.
Declaration
[CreateProperty]
[UxmlAttribute]
public string labelBadge { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Remarks
The badge sits immediately after the label text rather than at the row's end, so it follows the name's length; trailingContainer is the slot that pins to the edge. The label ellipsizes before the badge does, and while the trailing strip is showing the badge stops short of it exactly as the label does.
This takes an icon name rather than an element so it is expressible in UXML. Use labelBadgeElement to set a variant or a sprite directly.
labelBadgeElement
The badge element itself, for callers that need to set a variant or a sprite directly.
Declaration
public Icon labelBadgeElement { get; }
Property Value
| Type | Description |
|---|---|
| Icon |
labelBadgeLabel
Gets or sets what labelBadge means, in words, as the badge's tooltip.
Declaration
[CreateProperty]
[UxmlAttribute]
public string labelBadgeLabel { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Remarks
A glyph on its own says nothing to someone who has not seen it before, and the badge is too small to label in place. Text rather than an element: the tooltip is a string, and a caller should not have to build one.
labelElement
The label element itself. Exposed so callers can style a distinguished row by adding their
own USS class to it — the UITK equivalent of the registry's labelClassName.
Declaration
public LocalizedTextElement labelElement { get; }
Property Value
| Type | Description |
|---|---|
| LocalizedTextElement |
overflowButton
The button the trailing strip collapses to on a narrow row.
Declaration
public IconButton overflowButton { get; }
Property Value
| Type | Description |
|---|---|
| IconButton |
selected
Gets or sets whether the TreeViewItem is in selected state.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool selected { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
showCaret
Gets or sets whether the caret is shown for this TreeViewItem.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool showCaret { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
trailingCollapsed
True while the trailing strip has collapsed into the overflow button because the row is too narrow to show a readable label next to it.
Declaration
public bool trailingCollapsed { get; }
Property Value
| Type | Description |
|---|---|
| bool |
trailingContainer
The container for content pinned to the right of the row — visibility toggles, a count badge, and so on. Add your own elements to it; the row handles the reveal, the label reserve and the narrow-row overflow on its own.
Declaration
public VisualElement trailingContainer { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
trailingVisible
Tells the row that some trailing control is permanently visible rather than revealed on hover — an active lock or hidden-eye toggle, for instance — so the label keeps reserving room for it even when the row is not hovered.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool trailingVisible { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
GetCaretPositionUssClassName(CaretPosition)
Declaration
public static string GetCaretPositionUssClassName(CaretPosition enumValue)
Parameters
| Type | Name | Description |
|---|---|---|
| CaretPosition | enumValue |
Returns
| Type | Description |
|---|---|
| string |
GetDropPositionUssClassName(DropPosition)
Declaration
public static string GetDropPositionUssClassName(DropPosition enumValue)
Parameters
| Type | Name | Description |
|---|---|---|
| DropPosition | enumValue |
Returns
| Type | Description |
|---|---|
| string |
RefreshTrailing()
Re-evaluates whether the trailing strip is shown, whether it has to collapse into the overflow button, and how much room the label reserves for it.
Declaration
public void RefreshTrailing()
Remarks
Call this after adding to or removing from trailingContainer from code; the row cannot observe child additions on its own.
ToggleExpand()
Toggles the expanded state of the TreeViewItem.
Declaration
public void ToggleExpand()