Skip to content

SurfaceLayerContext

Namespace: Hex1b.Widgets

Assembly: Hex1b.dll

Context provided to layer builders.

csharp
public class SurfaceLayerContext

Inheritance

ObjectSurfaceLayerContext

Properties

Capabilities

Gets the terminal capabilities available for rendering.

Returns: TerminalCapabilities

csharp
public TerminalCapabilities Capabilities { get; }

CellMetrics

Gets the cell metrics (pixel dimensions per cell).

Returns: CellMetrics

csharp
public CellMetrics CellMetrics { get; }

Height

Gets the height of the surface in rows.

Returns: Int32

csharp
public int Height { get; }

MouseX

Gets the current mouse X position (column) relative to the widget.

Returns: Int32

csharp
public int MouseX { get; }

MouseY

Gets the current mouse Y position (row) relative to the widget.

Returns: Int32

csharp
public int MouseY { get; }

Theme

Gets the current theme.

Returns: Hex1bTheme

csharp
public Hex1bTheme Theme { get; }

Width

Gets the width of the surface in columns.

Returns: Int32

csharp
public int Width { get; }

Methods

CreateKgp(byte[], int, int, KgpZOrder)

Creates a tracked KGP image from raw pixel data.

Parameters:

  • imageData (Byte[]): Raw RGBA32 pixel data.
  • pixelWidth (Int32): Width in pixels.
  • pixelHeight (Int32): Height in pixels.
  • zOrder (KgpZOrder): Z-ordering relative to text (below or above).

Returns: TrackedObject<KgpCellData>

A tracked KGP object, or null if KGP creation is not available.

csharp
public TrackedObject<KgpCellData>? CreateKgp(byte[] imageData, int pixelWidth, int pixelHeight, KgpZOrder zOrder = KgpZOrder.BelowText)

CreateKgp(KgpCellData)

Creates a tracked KGP image from structured cell data.

Parameters:

Returns: TrackedObject<KgpCellData>

A tracked KGP object, or null if KGP creation is not available.

csharp
public TrackedObject<KgpCellData>? CreateKgp(KgpCellData kgpData)

CreateSixel(SixelPixelBuffer)

Creates a tracked sixel from a pixel buffer.

Parameters:

Returns: TrackedObject<SixelData>

A tracked sixel object, or null if sixel creation is not available.

csharp
public TrackedObject<SixelData>? CreateSixel(SixelPixelBuffer buffer)

CreateSixel(string, int, int)

Creates a tracked sixel from a pre-encoded sixel payload.

Parameters:

  • payload (String): The sixel-encoded string.
  • widthInCells (Int32): Width in terminal cells.
  • heightInCells (Int32): Height in terminal cells.

Returns: TrackedObject<SixelData>

A tracked sixel object, or null if sixel creation is not available.

csharp
public TrackedObject<SixelData>? CreateSixel(string payload, int widthInCells, int heightInCells)

Layer(Action<Surface>, int, int)

Creates a layer whose content is drawn via a callback.

Parameters:

  • draw (Action<Surface>): The callback that draws content to a fresh surface.
  • offsetX (Int32): X offset where the drawn surface's (0,0) will be placed.
  • offsetY (Int32): Y offset where the drawn surface's (0,0) will be placed.

Returns: SurfaceLayer

A layer that renders the drawn content at the specified offset.

csharp
public SurfaceLayer Layer(Action<Surface> draw, int offsetX = 0, int offsetY = 0)

Layer(CellCompute)

Creates a computed layer whose cells are calculated dynamically.

Parameters:

  • compute (CellCompute): The delegate that computes each cell's value.

Returns: SurfaceLayer

A computed layer covering the entire surface.

csharp
public SurfaceLayer Layer(CellCompute compute)

Layer(ISurfaceSource, int, int)

Creates a layer from an existing surface source.

Parameters:

  • source (ISurfaceSource): The surface source providing cell data.
  • offsetX (Int32): X offset where the source's (0,0) will be placed.
  • offsetY (Int32): Y offset where the source's (0,0) will be placed.

Returns: SurfaceLayer

A layer that renders the source at the specified offset.

csharp
public SurfaceLayer Layer(ISurfaceSource source, int offsetX = 0, int offsetY = 0)

WidgetLayer(Hex1bWidget)

Creates a layer whose content is rendered from a widget tree.

Parameters:

  • widget (Hex1bWidget): The widget tree to render as a layer.

Returns: SurfaceLayer

A layer that renders the widget tree.

csharp
public SurfaceLayer WidgetLayer(Hex1bWidget widget)

Remarks

This context is passed to the layer builder callback and provides: Factory methods for creating layersMouse position for interactive effectsTheme access for styled effectsSixel creation for graphics

The context is created fresh for each render, with current mouse position and theme state.

Released under the MIT License.