Class TreeListVirtual
A tree whose rows are windowed: only the rows near the scrolled view exist as
TreeViewItem elements, so a tree of any size costs a constant number of
elements. A port of the web registry's TreeListVirtual.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class TreeListVirtual : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, ISizeableElement
Remarks
TreeList stays a composition container: its consumer builds every TreeViewItem, and its public surface (items, selectedItems, onReparent) hands out those element references, so it cannot recycle rows without breaking that contract. This sibling takes the rows as data instead, flat and in display order (see Flatten<T>(TreeListFlattenOptions<T>)), and recycles a small pool of items over them. Selection is therefore by row id rather than by element.
Selection (with the same press-then-release rule as TreeList in Multiple mode) and keyboard navigation (arrows, Home / End, Shift-range, action+A, Escape, Delete) read the row list rather than the realised elements, so they reach rows that are not realised. Expansion is the caller's: a caret click or an arrow key reports it through onExpandedChange and the caller rebuilds rows. Rows are a uniform height, the height of the first realised row. Drag to reorder is not supported yet.
Constructors
TreeListVirtual()
Initializes a new instance of the TreeListVirtual class.
Declaration
public TreeListVirtual()
Fields
indentProbeUssClassName
The USS class name of the hidden element whose width is the per-level indent.
Declaration
public const string indentProbeUssClassName = "appui-tree-list-virtual__indent-probe"
Field Value
| Type | Description |
|---|---|
| string |
placeholderUssClassName
The USS class name of a realised placeholder row.
Declaration
public const string placeholderUssClassName = "appui-tree-list-virtual__row--placeholder"
Field Value
| Type | Description |
|---|---|
| string |
rowUssClassName
The USS class name of a realised row.
Declaration
public const string rowUssClassName = "appui-tree-list-virtual__row"
Field Value
| Type | Description |
|---|---|
| string |
rowsContainerUssClassName
The USS class name of the element sized to the whole row list.
Declaration
public const string rowsContainerUssClassName = "appui-tree-list-virtual__rows"
Field Value
| Type | Description |
|---|---|
| string |
scrollViewUssClassName
The USS class name of the scroll view.
Declaration
public const string scrollViewUssClassName = "appui-tree-list-virtual__scroll-view"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The TreeListVirtual's main USS class name. The element also carries ussClassName, so the rows pick up the tree's row styling.
Declaration
public const string ussClassName = "appui-tree-list-virtual"
Field Value
| Type | Description |
|---|---|
| string |
Properties
bindRow
Draws one row onto a recycled TreeViewItem: its label, icon and anything else that comes from the caller's item. The tree has already set the row's indentation, caret, expansion and selection. Called for placeholders too; check placeholder. With no handler, the row shows its id.
Declaration
public Action<TreeViewItem, TreeListRow, int> bindRow { get; set; }
Property Value
| Type | Description |
|---|---|
| Action<TreeViewItem, TreeListRow, int> |
onDeleteSelection
Called when Delete or Backspace is pressed with a non-empty selection, receiving the selected ids in priority order. There is no default behaviour.
Declaration
public Action<IReadOnlyList<string>> onDeleteSelection { get; set; }
Property Value
| Type | Description |
|---|---|
| Action<IReadOnlyList<string>> |
onExpandedChange
Called with a row's id and its requested state when a caret click or an arrow key expands or collapses it. The caller updates its expansion state and assigns new rows.
Declaration
public Action<string, bool> onExpandedChange { get; set; }
Property Value
| Type | Description |
|---|---|
| Action<string, bool> |
overscan
Rows realised beyond each edge of the view. -1, the default, realises one view's worth, and never fewer than 10, so a scroll of up to a full view in one frame still lands on realised rows.
Declaration
[CreateProperty]
[UxmlAttribute]
public int overscan { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
pinnedIds
Row ids kept realised even when scrolled out of view, a row being renamed for instance. The lead selected row and a row being pressed are always kept.
Declaration
public IReadOnlyList<string> pinnedIds { get; set; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyList<string> |
realisedRowCount
How many rows currently exist as elements.
Declaration
public int realisedRowCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
rowSize
The height every row is laid out at, measured from the first realised row.
Declaration
public float rowSize { get; }
Property Value
| Type | Description |
|---|---|
| float |
rows
Every visible row in display order, placeholders included. Assigning it rebinds the realised rows. The selection is kept by id.
Declaration
public IReadOnlyList<TreeListRow> rows { get; set; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyList<TreeListRow> |
scrollView
The scroll view the rows are windowed against.
Declaration
public ScrollView scrollView { get; }
Property Value
| Type | Description |
|---|---|
| ScrollView |
selectedId
The lead selected row id, or null.
Declaration
public string selectedId { get; }
Property Value
| Type | Description |
|---|---|
| string |
selectedIds
The selected row ids in priority order. Index 0 is the lead, the row the user acted on last, which keyboard navigation moves from.
Declaration
public IReadOnlyList<string> selectedIds { get; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyList<string> |
selectionType
How many rows the user can select at once. Defaults to Single. Narrowing it trims the current selection.
Declaration
[CreateProperty]
[UxmlAttribute]
public SelectionType selectionType { get; set; }
Property Value
| Type | Description |
|---|---|
| SelectionType |
size
The size of the rows. Cascades onto the rows the same way size does.
Declaration
[CreateProperty]
[UxmlAttribute]
public Size size { get; set; }
Property Value
| Type | Description |
|---|---|
| Size |
Methods
ClearSelection()
Clears the selection.
Declaration
public void ClearSelection()
GetRealisedItem(int)
The realised item drawing the row at index, or null when that row is
not realised.
Declaration
public TreeViewItem GetRealisedItem(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | The row index. |
Returns
| Type | Description |
|---|---|
| TreeViewItem | The item, or null. |
IndexOf(string)
The index of the item row with this id, or -1. Placeholders are not indexed.
Declaration
public int IndexOf(string id)
Parameters
| Type | Name | Description |
|---|---|---|
| string | id | The row id. |
Returns
| Type | Description |
|---|---|
| int | The index, or -1. |
IsIndexVisible(int)
Whether the row at index lies entirely inside the scrolled view.
Declaration
public bool IsIndexVisible(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | The row index. |
Returns
| Type | Description |
|---|---|
| bool | True when the whole row is visible. |
ScrollToIndex(int)
Scrolls the least distance that brings the row at index fully into view.
Declaration
public void ScrollToIndex(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | The row index. |
Select(string, bool, bool)
Applies a user selection gesture to the row with this id, the same way a click does.
Declaration
public void Select(string id, bool shift = false, bool toggle = false)
Parameters
| Type | Name | Description |
|---|---|---|
| string | id | The row id. |
| bool | shift | True when the range modifier is held (Multiple mode only). |
| bool | toggle | True when the action key is held (Multiple mode only). |
SelectAll()
Selects every item row. Only valid in Multiple mode.
Declaration
public void SelectAll()
SetSelection(IEnumerable<string>)
Replaces the selection with these ids, the first being the lead, and raises selectionChanged when it changes.
Declaration
public void SetSelection(IEnumerable<string> ids)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<string> | ids | The ids to select. |
Events
selectionChanged
Raised when the selection changes, with the selected ids in priority order.
Declaration
public event Action<IReadOnlyList<string>> selectionChanged
Event Type
| Type | Description |
|---|---|
| Action<IReadOnlyList<string>> |