Skip to content

Hex1bWidget

Namespace: Hex1b.Widgets

Assembly: Hex1b.dll

Base class for every Hex1b widget.

csharp
public abstract record Hex1bWidget : IEquatable<Hex1bWidget>

Inheritance

ObjectHex1bWidget

Implements

Properties

DefaultHeightHint

Per-widget default for . See for the rationale.

Returns: Nullable<SizeHint>

csharp
protected virtual SizeHint? DefaultHeightHint { get; }

DefaultWidthHint

Per-widget default for when the user hasn't explicitly set one. Returning a non-null value lets a widget opt into "expand to fill" or any other sizing behavior without forcing every caller to chain .FillWidth(). The user-supplied always wins over this default.

Returns: Nullable<SizeHint>

csharp
protected virtual SizeHint? DefaultWidthHint { get; }

HeightHint

Hint for how this widget should be sized vertically within its parent. Used by VStack to distribute height among children.

Returns: Nullable<SizeHint>

csharp
public SizeHint? HeightHint { get; init; }

MetricName

A user-assigned name for this widget used as a tag value in per-node metrics. When per-node metrics are enabled, this name becomes a segment in the hierarchical metric path (e.g., root.sidebar.orders). If null, an auto-generated name based on the node type and child index is used (e.g., VStack[0]).

Returns: String

csharp
public string? MetricName { get; init; }

RedrawDelay

Delay after which this widget requests a redraw.

Returns: Nullable<TimeSpan>

csharp
public TimeSpan? RedrawDelay { get; init; }

WidthHint

Hint for how this widget should be sized horizontally within its parent. Used by HStack to distribute width among children.

Returns: Nullable<SizeHint>

csharp
public SizeHint? WidthHint { get; init; }

Methods

Build(CompositionContext)

Builds the widget tree for this widget. Override this method to author a widget compositionally — by returning a tree of other widgets — without writing a custom .

Parameters:

  • ctx (CompositionContext): The composition context. Exposes per-instance state via , ambient values via and , and the full fluent widget-building API (ctx.Text(...), ctx.VStack(...), ctx.Button(...), etc.).

Returns: Hex1bWidget

The widget tree to render. Returns null by default, which signals to the framework that this widget does not use the compositional path. Widgets that override this method must return a non-null tree.

csharp
protected virtual Hex1bWidget? Build(CompositionContext ctx)

Remarks

There are two ways to author a widget:

Compositional (the recommended path for most widgets): override and return a tree of other widgets. The framework handles reconciliation, layout, focus preservation, and ambient state for you. Authors never need to write a custom .

Primitive (used by the built-in widgets that touch the terminal directly): pair the widget with a custom that implements Render/Measure/Arrange, and override ReconcileAsync/GetExpectedNodeType to wire them together. Note that these overrides are internal, so the primitive path is only available inside the Hex1b assembly.

A widget should pick exactly one path. Overriding both and ReconcileAsync is a programming error and is flagged by analyzer HEX1B0010. At runtime, an explicit ReconcileAsync override always wins and any implementation is ignored.

Released under the MIT License.