Class TableControl
- Namespace
- SharpConsoleUI.Controls
- Assembly
- SharpConsoleUI.dll
A table control that wraps Spectre.Console's Table widget. Provides read-only display of tabular data with theming support.
public class TableControl : IDOMPaintable, IMouseAwareControl, IWindowControl, IDisposable
- Inheritance
-
TableControl
- Implements
- Inherited Members
- Extension Methods
Constructors
TableControl()
Initializes a new instance of the TableControl class.
public TableControl()
Properties
ActualHeight
public int? ActualHeight { get; }
Property Value
- int?
ActualWidth
Gets the actual rendered width of the control, or null if not yet rendered.
public int? ActualWidth { get; }
Property Value
- int?
BackgroundColor
public Color? BackgroundColor { get; set; }
Property Value
- Color?
BorderColor
Gets or sets the border color. Null falls back to theme.
public Color? BorderColor { get; set; }
Property Value
- Color?
BorderStyle
Gets or sets the border style.
public BorderStyle BorderStyle { get; set; }
Property Value
CanFocusWithMouse
Whether this control can receive focus via mouse clicks
public bool CanFocusWithMouse { get; set; }
Property Value
ColumnCount
Gets the number of columns in the table.
public int ColumnCount { get; }
Property Value
Columns
Gets the read-only list of columns.
public IReadOnlyList<TableColumn> Columns { get; }
Property Value
Container
Gets or sets the parent container that hosts this control.
public IContainer? Container { get; set; }
Property Value
ForegroundColor
public Color? ForegroundColor { get; set; }
Property Value
- Color?
HeaderBackgroundColor
Gets or sets the header background color. Null falls back to theme.
public Color? HeaderBackgroundColor { get; set; }
Property Value
- Color?
HeaderForegroundColor
Gets or sets the header foreground color. Null falls back to theme.
public Color? HeaderForegroundColor { get; set; }
Property Value
- Color?
Height
public int? Height { get; set; }
Property Value
- int?
HorizontalAlignment
Gets or sets the horizontal alignment of the control within its container.
public HorizontalAlignment HorizontalAlignment { get; set; }
Property Value
Margin
Gets or sets the margin (spacing) around the control.
public Margin Margin { get; set; }
Property Value
Name
Gets or sets the unique name identifier for this control, used for lookup.
public string? Name { get; set; }
Property Value
RowCount
Gets the number of rows in the table.
public int RowCount { get; }
Property Value
Rows
Gets the read-only list of rows.
public IReadOnlyList<TableRow> Rows { get; }
Property Value
ShowHeader
Gets or sets whether to show the header row.
public bool ShowHeader { get; set; }
Property Value
ShowRowSeparators
Gets or sets whether to show row separators.
public bool ShowRowSeparators { get; set; }
Property Value
StickyPosition
Gets or sets whether this control should stick to the top or bottom during scrolling.
public StickyPosition StickyPosition { get; set; }
Property Value
Tag
Gets or sets an arbitrary object value that can be used to store custom data.
public object? Tag { get; set; }
Property Value
Title
Gets or sets the table title.
public string? Title { get; set; }
Property Value
TitleAlignment
Gets or sets the title alignment.
public Justify TitleAlignment { get; set; }
Property Value
- Justify
UseSafeBorder
Gets or sets whether to use safe border characters.
public bool UseSafeBorder { get; set; }
Property Value
VerticalAlignment
Gets or sets the vertical alignment of the control within its container.
public VerticalAlignment VerticalAlignment { get; set; }
Property Value
Visible
Gets or sets whether this control is visible.
public bool Visible { get; set; }
Property Value
WantsMouseEvents
Whether this control wants to receive mouse events
public bool WantsMouseEvents { get; set; }
Property Value
Width
Gets or sets the explicit width of the control, or null for automatic sizing.
public int? Width { get; set; }
Property Value
- int?
Methods
AddColumn(TableColumn)
Adds a column to the table.
public void AddColumn(TableColumn column)
Parameters
columnTableColumn
AddColumn(string, Justify, int?)
Adds a column with the specified header.
public void AddColumn(string header, Justify alignment = Justify.Left, int? width = null)
Parameters
AddRow(TableRow)
Adds a row to the table.
public void AddRow(TableRow row)
Parameters
rowTableRow
AddRow(params string[])
Adds a row with the specified cells.
public void AddRow(params string[] cells)
Parameters
cellsstring[]
AddRows(IEnumerable<TableRow>)
Adds multiple rows to the table.
public void AddRows(IEnumerable<TableRow> rows)
Parameters
rowsIEnumerable<TableRow>
ClearColumns()
Clears all columns.
public void ClearColumns()
ClearRows()
Clears all rows.
public void ClearRows()
Create()
Creates a new TableControlBuilder for fluent configuration.
public static TableControlBuilder Create()
Returns
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
GetCell(int, int)
Gets a cell value.
public string GetCell(int row, int column)
Parameters
Returns
GetLogicalContentSize()
Gets the logical size of the control's content without rendering.
public Size GetLogicalContentSize()
Returns
- Size
The size representing the content's natural dimensions.
GetRow(int)
Gets a row.
public TableRow GetRow(int index)
Parameters
indexint
Returns
Invalidate()
Marks this control as needing to be re-rendered.
public void Invalidate()
MeasureDOM(LayoutConstraints)
Measures the control's desired size given the available constraints.
public LayoutSize MeasureDOM(LayoutConstraints constraints)
Parameters
constraintsLayoutConstraintsThe layout constraints (min/max width/height).
Returns
- LayoutSize
The desired size of the control.
PaintDOM(CharacterBuffer, LayoutRect, LayoutRect, Color, Color)
Paints the control's content directly to a CharacterBuffer.
public void PaintDOM(CharacterBuffer buffer, LayoutRect bounds, LayoutRect clipRect, Color defaultFg, Color defaultBg)
Parameters
bufferCharacterBufferThe buffer to paint to.
boundsLayoutRectThe absolute bounds where the control should paint.
clipRectLayoutRectThe clipping rectangle (visible area).
defaultFgColordefaultBgColor
ProcessMouseEvent(MouseEventArgs)
Processes a mouse event for this control
public bool ProcessMouseEvent(MouseEventArgs args)
Parameters
argsMouseEventArgsMouse event arguments with control-relative coordinates
Returns
- bool
True if the event was handled and should not propagate further
RemoveColumn(int)
Removes the column at the specified index.
public void RemoveColumn(int index)
Parameters
indexint
RemoveRow(int)
Removes the row at the specified index.
public void RemoveRow(int index)
Parameters
indexint
SetColumnAlignment(int, Justify)
Sets the alignment of a column.
public void SetColumnAlignment(int index, Justify alignment)
Parameters
indexintalignmentJustify
SetColumnWidth(int, int?)
Sets the width of a column.
public void SetColumnWidth(int index, int? width)
Parameters
SetData(IEnumerable<TableRow>)
Sets all rows at once.
public void SetData(IEnumerable<TableRow> rows)
Parameters
rowsIEnumerable<TableRow>
UpdateCell(int, int, string)
Updates a cell value.
public void UpdateCell(int row, int column, string value)
Parameters
Events
MouseClick
Event fired when the control is clicked
public event EventHandler<MouseEventArgs>? MouseClick
Event Type
MouseDoubleClick
Event fired when the control is double-clicked
public event EventHandler<MouseEventArgs>? MouseDoubleClick
Event Type
MouseEnter
Event fired when the mouse enters the control area
public event EventHandler<MouseEventArgs>? MouseEnter
Event Type
MouseLeave
Event fired when the mouse leaves the control area
public event EventHandler<MouseEventArgs>? MouseLeave
Event Type
MouseMove
Event fired when the mouse moves over the control
public event EventHandler<MouseEventArgs>? MouseMove