Skip to content
Dustin Horne edited this page Mar 5, 2026 · 1 revision

Tables

Namespace: ParentElement.RichText.Core.Tables

The tables subsystem provides inline tables that flow with document text. Tables are created through IDocumentController.InsertTable, managed via InlineTable, and their cells' content is written via ICellWriter.


TableOptions

Configuration passed to IDocumentController.InsertTable to define a new table's initial structure and appearance.

public class TableOptions

Properties

Property Type Default Description
Rows int 0 Number of rows
Columns int 0 Number of columns
BorderStyle TableBorderStyle Solid Style applied to all borders
BorderWidth float 1 Border thickness in pixels
BorderColor SKColor #C0C0C0 Border color
HeaderBackgroundColor SKColor White Background color of header row cells
IncludeHeader bool false Whether row 0 should be treated as a header row

Example

var table = editor.InsertTable(new TableOptions
{
    Rows               = 4,
    Columns            = 3,
    BorderStyle        = TableBorderStyle.Solid,
    BorderWidth        = 1f,
    BorderColor        = SKColors.Gray,
    IncludeHeader      = true,
    HeaderBackgroundColor = new SKColor(0xE0, 0xE0, 0xFF),
});

TableBorderStyle

Controls how table borders are rendered.

public enum TableBorderStyle { None, Solid, Dashed, Dotted }
Value Description
None No borders drawn
Solid Solid lines
Dashed Dashed lines
Dotted Dotted lines

InlineTable

Represents a live inline table that flows with the document text. Returned by IDocumentController.InsertTable and accessible through the document's internal structure.

public class InlineTable : IInlineObject

Properties

Property Type Description
Width float Total rendered width in pixels (read-only)
Height float Total rendered height in pixels (computed from row heights)
Rows int Number of rows
Cols int Number of columns
ColWidths IReadOnlyList<float> Per-column content widths in pixels
RowHeights IReadOnlyList<float> Per-row heights in pixels (recomputed on demand)
BorderWidth float Effective border width
BorderStyle TableBorderStyle Border render style
BorderColor SKColor Border color
IsEmpty bool true when no primary cells remain (e.g. after all rows are deleted)
HasMultiSelection bool true when a multi-cell selection is active
NeedsGhostBorders bool true when the border width is less than 1px and ghost borders should be painted
OnHeightChanged Action? Callback invoked when the table height changes

Cell Access

Method Returns Description
GetCell(int row, int col) TableCell? Get the cell at the given position, or null for spanned slots

Content

Method Returns Description
WriteToCell(int row, int col, Action<ICellWriter>) void Populate a cell's content via an ICellWriter callback

Layout

Method Returns Description
RecalcRowHeights() void Recompute all row heights from cell content
GetRowTop(int row) float Y offset of a row's top edge relative to the table origin
GetColumnMinWidth(int col) float Minimum content width for a column
GetCellBounds(int row, int col) SKRect Bounding rectangle of a cell in table-local coordinates
GetRowSplitIndex(float availableHeight) int Row index where the table would split given a page height limit

Hit Testing

Method Returns Description
HitTestCell(SKPoint) (int row, int col)? Row/col of the cell at a table-local point, or null
HitTestColumnDivider(SKPoint, float tolerance) int Index of the column divider nearest the point, or -1
IsPointInSelection(SKPoint) bool Whether the table-local point is within the multi-cell selection

Column Resizing

Method Returns Description
ResizeDivider(int dividerIdx, float newLeftWidth, float newRightWidth) void Resize adjacent columns by setting their new widths

Row and Column Editing

Method Returns Description
AddRow() void Append a new row at the bottom
InsertRow(int insertAt) void Insert a row before the given index
InsertColumn(int insertAt) void Insert a column before the given index
DeleteRow(int row) void Remove a row by index
DeleteColumn(int col) void Remove a column by index

Cell Merging

Method Returns Description
SetMultiSelection(int r1, int c1, int r2, int c2) void Define a multi-cell selection rectangle
ClearMultiSelection() void Clear the multi-cell selection
CanMergeSelection() bool true if the current selection can be merged
MergeSelection() (int row, int col) Merge the current selection; returns the primary cell position
MergeRange(int minRow, int minCol, int maxRow, int maxCol) void Merge a specific rectangular range

Rendering

Method Returns Description
Paint(SKCanvas, SKPoint origin) void Render the table at the given origin
PaintGhostBorders(SKCanvas, SKPoint origin) void Paint low-opacity guide lines when border width is below 1px
PaintSplitBorders(SKCanvas, SKPoint origin, float splitLocalY) void Paint borders up to a page-split Y position

TableCell

A single cell in a live InlineTable, exposing its spanning and header state.

public class TableCell

Constructor

public TableCell(float cellContentWidth, IStyle defaultStyle, bool isHeader,
                 Action invalidate, Action contentChanged,
                 SKColor? backgroundOverride = null)
Parameter Type Description
cellContentWidth float Available content width for this cell
defaultStyle IStyle Default character style
isHeader bool Whether this cell is a header cell
invalidate Action Callback to request a redraw
contentChanged Action Callback invoked when content is modified
backgroundOverride SKColor? Optional explicit background color

Properties

Property Type Description
IsHeader bool Whether this is a header cell
RowSpan int Number of rows spanned (set internally by the table)
ColSpan int Number of columns spanned (set internally by the table)
BackgroundColor SKColor? Background color override, or null for default

CellController

The internal document controller scoped to a single table cell. Provides editing operations equivalent to DocumentController but applied to the cell's TextDocument.

public class CellController

Key Properties

Property Type Description
Selection TextRange Current text selection within the cell
MeasuredHeight float Measured content height in pixels
Invalidate Action? Callback to request a redraw
ContentChanged Action? Callback invoked when content changes

Key Methods

Method Description
Insert(string) Insert text at the caret
Backspace() Delete the character before the caret
Delete() Delete the character after the caret
Navigate(NavigationKind, bool extend) Move the caret or extend the selection
ApplyStyle(IStyle) Apply a style to the selection
ApplyBold(), ApplyItalic(), ApplyUnderline(), etc. Toggle character formatting
ApplyAlignment(TextAlignment) Set paragraph alignment
SetWidth(float) Update the cell content width and re-layout
GetContentReader() Return a DocumentReader for this cell's content
Paint(SKCanvas, float availableHeight, TextPaintOptions?) Render cell content
PaintCaret(SKCanvas) Render the caret if this cell has focus
Click(SKPoint) Handle a pointer click in cell-local coordinates
DragTo(SKPoint) Extend the selection to a cell-local point

See also: ICellWriter · IDocumentController · Content-Model

Clone this wiki locally