Skip to content

TreeContext

Namespace: Hex1b.Widgets

Assembly: Hex1b.dll

Provides a fluent API context for building tree structures. This context exposes the Item method to create tree items with optional children.

csharp
public readonly struct TreeContext

Methods

Item(string, Func<TreeContext, IEnumerable<TreeItemWidget>>)

Creates a tree item with the specified label and static children.

Parameters:

Returns: TreeItemWidget

A TreeItemWidget configured with children.

csharp
public TreeItemWidget Item(string label, Func<TreeContext, IEnumerable<TreeItemWidget>> children)

Item(string, Func<TreeContext, Task<IEnumerable<TreeItemWidget>>>)

Creates a tree item with the specified label and async lazy-loaded children. When the item is expanded and the async callback is running, a spinner is shown.

Parameters:

Returns: TreeItemWidget

A TreeItemWidget configured for async lazy loading.

csharp
public TreeItemWidget Item(string label, Func<TreeContext, Task<IEnumerable<TreeItemWidget>>> asyncChildren)

Item(string)

Creates a tree item with the specified label and no children.

Parameters:

  • label (String): The display label for the tree item.

Returns: TreeItemWidget

A TreeItemWidget that can be further configured with fluent methods.

csharp
public TreeItemWidget Item(string label)

Remarks

TreeContext is passed to the tree builder callback and provides the method for creating tree items. Items can have children specified via a nested callback.

For async lazy loading, use the async children callback overload. When the async callback is pending, the tree automatically shows a spinner in place of the expand indicator.

Examples

Basic static tree:

csharp
ctx.Tree(t => [
    t.Item("Root", root => [
        root.Item("Child 1"),
        root.Item("Child 2")
    ]).Expanded().Icon("📁")
])

Async lazy loading:

csharp
ctx.Tree(t => [
    t.Item("Server", async children => {
        var data = await LoadAsync();
        return data.Select(d => children.Item(d.Name));
    })
])

Released under the MIT License.