ConsoleForge 0.3.0
Elm-architecture TUI framework for .NET 8
Loading...
Searching...
No Matches
ConsoleForge.Layout.RenderContext Class Referencesealed

Concrete implementation of IRenderContext backed by a cell buffer where each cell stores a pre-rendered ANSI string for one character. More...

Inheritance diagram for ConsoleForge.Layout.RenderContext:

Public Member Functions

SubRenderContext CreateSub (Region subRegion)
 Create a sub-context restricted to a sub-region of this context.
void RegisterWidget (IWidget widget, Region region)
 Record that widget was rendered at region this frame.
 RenderContext (Region region, Theme theme, ColorProfile colorProfile, ResolvedLayout layout)
 Initialises a fresh render context for a single full-redraw frame.
void Reset (Region region, Theme theme, ColorProfile colorProfile, ResolvedLayout layout)
 Prepare this context for a new frame.
void SetCursorDescriptor (CursorDescriptor cursor)
 Set cursor on the Rendering Context.
string ToAnsiFrame ()
 Produce a minimal ANSI frame string by diffing current cell buffer against the previous frame.
bool TryReuseWidget (IWidget widget, Region region)
 If widget (same object reference) was rendered at exactly region last frame AND the previous cell buffer exists, copy those cells into the current buffer and return true (caller should skip rendering).
void Write (int col, int row, string text, Style style)
 Write a styled string at absolute terminal position (col, row).

Properties

ColorProfile ColorProfile [get]
 Detected terminal color capability.
CursorDescriptorCursor [get]
 Cursor information for TextArea and TextInput widgets.
ResolvedLayout Layout [get]
 Resolved layout for the current frame.
Region Region [get]
 The allocated region for this widget (absolute terminal coordinates).
Theme Theme [get]
 Active theme for style inheritance. Updated by Reset.

Detailed Description

Concrete implementation of IRenderContext backed by a cell buffer where each cell stores a pre-rendered ANSI string for one character.

Supports double-buffering: ToAnsiFrame diffs the current cell buffer against the previous frame and emits only changed cells, then swaps the buffers. On the first frame (no previous buffer) all cells are emitted.

Call Reset before each frame to clear the current buffer and update the region. The previous buffer is untouched until ToAnsiFrame swaps.

Constructor & Destructor Documentation

◆ RenderContext()

ConsoleForge.Layout.RenderContext.RenderContext ( Region region,
Theme theme,
ColorProfile colorProfile,
ResolvedLayout layout )

Initialises a fresh render context for a single full-redraw frame.

Parameters
regionThe terminal region this context covers.
themeActive visual theme.
colorProfileANSI color output profile.
layoutPre-resolved widget-to-region layout map.

Member Function Documentation

◆ CreateSub()

SubRenderContext ConsoleForge.Layout.RenderContext.CreateSub ( Region subRegion)

Create a sub-context restricted to a sub-region of this context.

Writes to the sub-context are forwarded to this context with adjusted coordinates.

◆ RegisterWidget()

void ConsoleForge.Layout.RenderContext.RegisterWidget ( IWidget widget,
Region region )

Record that widget was rendered at region this frame.

Called by Widgets.Container after rendering each child.

Implements ConsoleForge.Layout.IRenderContext.

◆ Reset()

void ConsoleForge.Layout.RenderContext.Reset ( Region region,
Theme theme,
ColorProfile colorProfile,
ResolvedLayout layout )

Prepare this context for a new frame.

Clears the current cell buffer (so stale content from last frame is not present) and updates Region/Layout/Theme. The previous frame buffer is preserved for diffing in ToAnsiFrame. If terminal dimensions changed, the previous buffer is discarded (forces full redraw).

◆ ToAnsiFrame()

string ConsoleForge.Layout.RenderContext.ToAnsiFrame ( )

Produce a minimal ANSI frame string by diffing current cell buffer against the previous frame.

Only emits cells that changed. On first frame (no previous buffer) emits all cells. Pre-sizes StringBuilder to avoid repeated reallocations. After emitting, swaps current ↔ previous buffers.

◆ TryReuseWidget()

bool ConsoleForge.Layout.RenderContext.TryReuseWidget ( IWidget widget,
Region region )

If widget (same object reference) was rendered at exactly region last frame AND the previous cell buffer exists, copy those cells into the current buffer and return true (caller should skip rendering).

Otherwise return false.

Implements ConsoleForge.Layout.IRenderContext.

◆ Write()

void ConsoleForge.Layout.RenderContext.Write ( int col,
int row,
string text,
Style style )

Write a styled string at absolute terminal position (col, row).

Clips text that extends beyond or starts before the Region bounds. Each visible character is stored as a pre-rendered styled cell. Uses Rune-based enumeration to avoid StringInfo allocations per character. ASCII fast path skips grapheme cluster logic entirely.

Implements ConsoleForge.Layout.IRenderContext.

Property Documentation

◆ Layout

ResolvedLayout ConsoleForge.Layout.RenderContext.Layout
get

Resolved layout for the current frame.

Container widgets use this to retrieve child regions without re-running layout.

Implements ConsoleForge.Layout.IRenderContext.


The documentation for this class was generated from the following file:
  • src/ConsoleForge/Layout/RenderContext.cs