Skip to main content

Tree<T> class

Namespace: Arlecchino.Widgets.Lists · Assembly: Arlecchino

A hierarchy drawn as indented rows. Only the expanded parts are laid out, and that layout is recomputed on demand rather than cached, so nodes may be added or expanded between frames.

public sealed class Tree<T> : IArlecchinoInteractiveWidget, IArlecchinoWidget, IArlecchinoFocusable

Implements IArlecchinoInteractiveWidget, IArlecchinoWidget, IArlecchinoFocusable

Constructors

MemberSummary
Tree(ArlecchinoKeymap)Creates the tree.

Properties

MemberSummary
IsFocusedWhether the tree has focus, which decides how strongly the selection is drawn.
ItemStyleColors a node. Ignored for the selected one.
OnActivateWhat confirming a leaf does. Branches toggle instead, so this is never called for a node that has children.
OnExpandingCalled just before a branch opens, which is where its children can be filled in. It runs on the UI thread, so anything slow belongs in an AsyncAtom instead.
RenderTurns a value into its label. The marker and the indent are added around it.
RootsThe top-level nodes.
SelectedIndexIndex of the selected row, counted over the rows that are showing rather than over all nodes.
SelectedNodeThe selected node, or null when the tree is empty.

Methods

MemberSummary
CollapseAll()Closes every branch, leaving only the roots showing.
Draw(SurfaceRegion)Draws the rows that are showing around the selection and remembers where they landed, which is what lets a click tell a marker from a label. The tree fills whatever it is given, so nothing is left underneath it.
ExpandAll()Opens every branch. Branches are opened directly, so anything relying on the expand callback to fill in its children will still look empty.
Handle(KeyPress)Moves through the rows and opens or closes branches. The horizontal arrows behave the way they do in a file manager: right opens a closed branch or steps into it, left closes an open one or jumps to the parent.
HandleMouse(MouseEvent)Scrolls with the wheel and selects with a click. Clicking the marker toggles the branch, while clicking the label of the already selected row activates it.

Constructors in detail

Tree(ArlecchinoKeymap)

Obsolete

Constructors of types with required members are not supported in this version of your compiler.

public Tree(ArlecchinoKeymap keymap);

Creates the tree.

Parameters

NameTypeDescription
keymapArlecchinoKeymapKeys to obey, so the tree follows the application's bindings.

Properties in detail

IsFocused

public bool IsFocused { get; set; }

Whether the tree has focus, which decides how strongly the selection is drawn.

Type bool

ItemStyle

public Func<T, IArlecchinoColor> ItemStyle { get; set; }

Colors a node. Ignored for the selected one.

Type Func<T, TResult><T, IArlecchinoColor>

OnActivate

public Func<TreeNode<T>, ViewRoute> OnActivate { get; init; }

What confirming a leaf does. Branches toggle instead, so this is never called for a node that has children.

Type Func<T, TResult><TreeNode<T>, ViewRoute>

OnExpanding

public Action<TreeNode<T>> OnExpanding { get; init; }

Called just before a branch opens, which is where its children can be filled in. It runs on the UI thread, so anything slow belongs in an AsyncAtom instead.

Type Action<T><TreeNode<T>>

Render

public Func<T, string> Render { get; init; }

Turns a value into its label. The marker and the indent are added around it.

Type Func<T, TResult><T, string>

Roots

public IReadOnlyList<TreeNode<T>> Roots { get; set; }

The top-level nodes.

Type IReadOnlyList<T><TreeNode<T>>

SelectedIndex

public int SelectedIndex { get; set; }

Index of the selected row, counted over the rows that are showing rather than over all nodes.

Type int

SelectedNode

public TreeNode<T> SelectedNode { get; }

The selected node, or null when the tree is empty.

Type TreeNode<T>

Methods in detail

CollapseAll()

public void CollapseAll();

Closes every branch, leaving only the roots showing.

Draw(SurfaceRegion)

public SurfaceRegion Draw(SurfaceRegion region);

Draws the rows that are showing around the selection and remembers where they landed, which is what lets a click tell a marker from a label. The tree fills whatever it is given, so nothing is left underneath it.

Parameters

NameTypeDescription
regionSurfaceRegionWhere to draw.

Returns SurfaceRegion — An empty region: the tree uses every row it is handed.

ExpandAll()

public void ExpandAll();

Opens every branch. Branches are opened directly, so anything relying on the expand callback to fill in its children will still look empty.

Handle(KeyPress)

public FocusResult Handle(KeyPress key);

Moves through the rows and opens or closes branches. The horizontal arrows behave the way they do in a file manager: right opens a closed branch or steps into it, left closes an open one or jumps to the parent.

Parameters

NameTypeDescription
keyKeyPressThe key that was pressed.

Returns FocusResult — What became of the key, including a route when a leaf was activated.

HandleMouse(MouseEvent)

public FocusResult HandleMouse(MouseEvent mouse);

Scrolls with the wheel and selects with a click. Clicking the marker toggles the branch, while clicking the label of the already selected row activates it.

Parameters

NameTypeDescription
mouseMouseEventThe event that arrived.

Returns FocusResult — What became of the event, including a route when a leaf was activated.