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.
public readonly struct TreeContextMethods
Item(string, Func<TreeContext, IEnumerable<TreeItemWidget>>)
Creates a tree item with the specified label and static children.
Parameters:
label(String): The display label for the tree item.children(Func<TreeContext, TreeItemWidget>>): A function that returns child items.
Returns: TreeItemWidget
A TreeItemWidget configured with children.
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:
label(String): The display label for the tree item.asyncChildren(Func<TreeContext, TreeItemWidget>>>): An async function that returns child items when the item is expanded.
Returns: TreeItemWidget
A TreeItemWidget configured for async lazy loading.
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.
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:
ctx.Tree(t => [
t.Item("Root", root => [
root.Item("Child 1"),
root.Item("Child 2")
]).Expanded().Icon("📁")
])Async lazy loading:
ctx.Tree(t => [
t.Item("Server", async children => {
var data = await LoadAsync();
return data.Select(d => children.Item(d.Name));
})
])