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

A tabular data widget. More...

Inheritance diagram for ConsoleForge.Widgets.Table:

Public Member Functions

void Render (IRenderContext ctx)
 Renders the header row, separator line, and data rows into ctx 's allocated region.
 Table ()
 Object-initializer constructor.
 Table (IReadOnlyList< TableColumn > columns, IReadOnlyList< IReadOnlyList< string > > rows, int selectedIndex=-1, Style? headerStyle=null, Style? rowStyle=null, int paddingLeft=1, int paddingRight=1, int scrollOffset=0)
 Positional constructor for inline usage.

Static Public Member Functions

static int ComputeScrollOffset (int selectedIndex, int viewportHeight, int currentScrollOffset)
 Computes a new ScrollOffset that keeps selectedIndex within the visible data-row viewport.

Properties

IReadOnlyList< TableColumnColumns = [] [get]
 Column definitions. Must not be empty.
Style HeaderStyle = Style.Default.Bold(true) [get]
 Style applied to the header row. Inherits theme base style when unset.
SizeConstraint Height = SizeConstraint.Flex(1) [get]
 Vertical size constraint. Defaults to SizeConstraint.Flex(int) weight 1 (fill available height).
int PaddingLeft = 1 [get]
 Blank columns inserted to the left of each cell's text.
int PaddingRight = 1 [get]
 Blank columns reserved to the right of each cell's text.
IReadOnlyList< IReadOnlyList< string > > Rows = [] [get]
 Data rows.
Style RowStyle = Style.Default [get]
 Style applied to data rows. Inherits theme base style when unset.
int ScrollOffset [get]
 Zero-based index of the first data row rendered in the viewport.
int SelectedIndex = -1 [get]
 Zero-based index of the selected row. -1 means no selection.
Style SelectedRowStyle = Style.Default.Reverse(true) [get]
 Style applied to the currently selected row (when SelectedIndex ≥ 0).
char Separator = '\0' [get]
 Character used to separate columns.
Style Style = Style.Default [get]
 Base style applied to the widget. Individual row and header styles override this per-section.
SizeConstraint Width = SizeConstraint.Flex(1) [get]
 Horizontal size constraint. Defaults to SizeConstraint.Flex(int) weight 1 (fill available width).

Detailed Description

A tabular data widget.

Renders a header row followed by data rows. Columns are defined by Columns; each row is a string array whose elements correspond to each column in order.

Columns with Width == 0 share the remaining horizontal space equally. Content that exceeds a column's width is truncated. No scrolling — clip to the available height. For scrolling, wrap in a scrollable Container.

Member Function Documentation

◆ ComputeScrollOffset()

int ConsoleForge.Widgets.Table.ComputeScrollOffset ( int selectedIndex,
int viewportHeight,
int currentScrollOffset )
static

Computes a new ScrollOffset that keeps selectedIndex within the visible data-row viewport.

Call this from your model's Update handler when processing TableSelectionChangedMsg.

Parameters
selectedIndexThe newly selected row index.
viewportHeightNumber of rows in the Table's region minus 1 for the header row.
currentScrollOffsetCurrent ScrollOffset.

◆ Render()

void ConsoleForge.Widgets.Table.Render ( IRenderContext ctx)

Renders the header row, separator line, and data rows into ctx 's allocated region.

Rows that exceed the available height are clipped. Column widths are resolved on each render; flex columns share remaining space equally.

Parameters
ctxThe render context providing the target region, theme, and write methods.

Implements ConsoleForge.Layout.IWidget.

Property Documentation

◆ PaddingLeft

int ConsoleForge.Widgets.Table.PaddingLeft = 1
get

Blank columns inserted to the left of each cell's text.

Provides breathing room between the column edge and the content. Defaults to 1, matching the Bubbles table convention.

◆ PaddingRight

int ConsoleForge.Widgets.Table.PaddingRight = 1
get

Blank columns reserved to the right of each cell's text.

Defaults to 1, matching the Bubbles table convention.

◆ Rows

IReadOnlyList<IReadOnlyList<string> > ConsoleForge.Widgets.Table.Rows = []
get

Data rows.

Each row must have the same number of elements as Columns; extra elements are ignored, missing elements are treated as empty strings.

◆ ScrollOffset

int ConsoleForge.Widgets.Table.ScrollOffset
get

Zero-based index of the first data row rendered in the viewport.

The header row is not affected by this offset. Update via ComputeScrollOffset when handling TableSelectionChangedMsg to keep the selected row visible.

◆ Separator

char ConsoleForge.Widgets.Table.Separator = '\0'
get

Character used to separate columns.

Defaults to '\0' (no separator). When non-zero the separator is always rendered with the base row style so it never inherits the selection highlight.


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