Vixen
02b45cc4
csharp
public sealed class TreeView

A tree, of which only what is on screen exists as elements.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

Virtualised, and the virtualising is VirtualizingPanel's. The nodes are model objects; the rows are a pool of elements the size of the viewport, rebound as the view scrolls. A million-node tree is a million TreeNodes and about thirty TreeRows.

⚠ The pooling used to be written here. It was the same code as the panel's — a capacity from the viewport, a first index from the scroll offset, a pool that only grows and parks its surplus — and two copies of an arithmetic that has to agree is one copy too many. What is left of it here is what is actually about a tree: flattening the expanded nodes into a list, and binding a row to one.

⚠ Rows are positioned absolutely, at a fixed height. Virtualisation needs to know where row 40 000 is without having measured the 39 999 above it, and a fixed height is what makes that arithmetic instead of a walk. Variable-height rows need a running-sum index that is maintained as things expand; that is a different control and is owed.

A resize no longer needs telling, and this control no longer watches for one. The panel subscribes to LayoutFinished directly rather than through Control.WhenResized, because it has to realise when the view is scrolled as well as when it is resized — which is the case that helper's own remarks send to the event itself. What is left for a tree to notice is a change to its nodes, and that arrives through Refresh, which stays public.

Fields and properties (21)

  • public const int Overscan

    How many rows are realised above and below the viewport.

  • protected override string TagName

    The element name this type answers to when a caller does not choose one.

  • protected override bool AcceptsFocus

    Whether the focus can rest on this kind of control at all.

  • public TreeNode Root

    The invisible node everything hangs off.

  • public VirtualizingPanel Panel

    The virtualiser the rows live in.

  • public ScrollView Scroller

    The scroller inside it.

  • public UiElement DropIndicator

    The line shown while a drag is over a row.

  • public float RowHeight

    How tall a row is, from --row-height.

  • public float Indent

    How far each level is indented, from --indent.

  • public Color4 GuideColour

    What the indent guides are drawn in, from --tree-guide-color.

  • public IReadOnlyList<TreeNode> Visible

    The nodes currently showing, in order, including the ones scrolled past.

  • public IReadOnlyList<TreeRow> Rows

    The rows that exist as elements, in pool order rather than in node order.

  • public IReadOnlyCollection<TreeNode> Selection

    What is selected.

  • public bool MultiSelect
  • public bool AllowDrag
  • public bool RenameOnActivate
  • public bool RenameOnSecondClick
  • public static readonly UiPropertyKey MultiSelectProperty

    Identity for MultiSelect.

  • public static readonly UiPropertyKey AllowDragProperty

    Identity for AllowDrag.

  • public static readonly UiPropertyKey RenameOnActivateProperty

    Identity for RenameOnActivate.

  • public static readonly UiPropertyKey RenameOnSecondClickProperty

    Identity for RenameOnSecondClick.

Events (5)

  • public Action<TreeView>? SelectionChanged

    Raised when the selection changes.

  • public Action<TreeView, TreeNode>? Activated

    Raised when a node is activated — double-clicked, or Enter pressed on it.

  • public Action<TreeView, TreeNode, string>? Renamed

    Raised after a rename is committed. Returning without setting the text refuses it.

  • public Action<TreeRow, TreeNode>? RowBound

    Raised whenever a row is bound to a node, so a consumer can decorate it.

  • public Action<TreeView, TreeNode>? Moved

    Raised after a drag has moved a node.

Methods (14)

  • protected override void OnCreated()

    Builds whatever this element is made of, once, as it joins a document.

  • public void Refresh()

    Rebuilds the list of visible nodes and realises the rows for it.

  • public void Expand(TreeNode node, bool expanded = true)

    Opens or closes a node.

  • public void Expand(IEnumerable<TreeNode> nodes, bool expanded = true)

    Opens or closes several nodes, refreshing once at the end.

  • public void Reveal(TreeNode node)

    Opens every node between a node and the root, so that it is visible.

  • public void Select(TreeNode? node, ModifierKeys modifiers = None)

    Selects a node, or adds it to or removes it from the selection.

  • public void BeginRename(TreeNode node)

    Puts a text box in a row so its node can be renamed.

  • public bool MoveNode(TreeNode node, TreeNode target, DropPosition position)

    Moves a node next to or into another one.

  • public TreeNode? NodeAt(float x, float y)

    The node showing at a point.

  • public TreeRow? RowOf(TreeNode node)

    The realised row showing a node, if it has one.

  • public void ClearMultiSelect()

    Unsets MultiSelect, so it takes its default or its ancestor's value again.

  • public void ClearAllowDrag()

    Unsets AllowDrag, so it takes its default or its ancestor's value again.

  • public void ClearRenameOnActivate()

    Unsets RenameOnActivate, so it takes its default or its ancestor's value again.

  • public void ClearRenameOnSecondClick()

    Unsets RenameOnSecondClick, so it takes its default or its ancestor's value again.

Used by (22)

  • ShellHelloUi
  • ResizeTestsVixen.Ui.Controls.Advanced.Tests
  • TreeRowVixen.Ui.Controls.Advanced
  • TreeViewTestsVixen.Ui.Controls.Advanced.Tests
  • AddressableGroupsViewVixen.Editor.AssetEditors
  • ChromeFixtureVixen.Editor.Ui.Tests
  • EditorAffordanceTestsVixen.Editor.App.Tests
  • EditorApplicationVixen.Editor.App
  • EditorSessionVixen.Editor.Testing
  • FrameDebuggerViewVixen.Editor.Debugger
  • GridViewTestsVixen.Editor.App.Tests
  • IconContributionTestsVixen.Editor.App.Tests
  • ImportViewTestsVixen.Editor.AssetEditors.Tests
  • InputActionsViewVixen.Editor.AssetEditors
  • InspectorPanelTestsVixen.Editor.App.Tests
  • ModelImportViewVixen.Editor.AssetEditors
  • OutlinerTestsVixen.Editor.App.Tests
  • PanelBehaviourTestsVixen.Editor.App.Tests
  • ProjectBrowserVixen.Editor.App
  • RemoteInspectorViewVixen.Editor.Debugger
  • SceneHierarchyViewVixen.Editor.AssetEditors
  • SelectionTestsVixen.Editor.App.Tests