CompositeWidget<TNode>
Namespace: Hex1b.Widgets
Assembly: Hex1b.dll
Base class for composite widgets that build their UI from other widgets. Composite widgets describe reusable UI patterns like Picker, DatePicker, ColorPicker, etc.
public abstract record CompositeWidget<TNode> : Hex1bWidget, IEquatable<Hex1bWidget>, IEquatable<CompositeWidget<TNode>> where TNode : CompositeNode, new()Inheritance
Object → Hex1bWidget → CompositeWidget<TNode>
Implements
Methods
BuildContentAsync(TNode, ReconcileContext)
Builds the content widget tree for this composite widget. Called during reconciliation to determine what widgets to render.
Parameters:
node(<TNode>): The composite node managing this widget's state.context(ReconcileContext): The reconciliation context.
Returns: Task<Hex1bWidget>
A task that resolves to the widget representing this composite's content.
protected abstract Task<Hex1bWidget> BuildContentAsync(TNode node, ReconcileContext context)UpdateNode(TNode)
Called during reconciliation to update the node's properties from the widget. Override this to copy widget properties to the node before building content.
Parameters:
node(<TNode>): The node to update.
protected virtual void UpdateNode(TNode node)Remarks
CompositeWidget enables building complex widgets from simpler ones while maintaining proper reconciliation semantics. The method returns the widget tree that represents this composite's visual content.
The composite node holds state that survives reconciliation (e.g., popup open state, selected value). During reconciliation, the composite widget builds its content and the framework reconciles that content as a child of the composite node.
Examples
public sealed record PickerWidget(IReadOnlyList Items) : CompositeWidget
{
public int SelectedIndex { get; init; }
protected override Task BuildContentAsync(PickerNode node, ReconcileContext context)
{
// Build button that shows current selection
// When clicked, show popup list
return Task.FromResult(
new ButtonWidget(Items[node.SelectedIndex])
.OnClick(e => e.PushAnchored(AnchorPosition.Below, () => BuildPickerList()))
);
}
}