celina/widgets/table

Search:
Group by:

Table widget

This module provides table widgets for displaying structured data in rows and columns, with support for headers, selection, scrolling, and styling.

Types

BorderStyle = enum
  NoBorder, SimpleBorder, RoundedBorder, DoubleBorder
Table border drawing style
Column = object
  title*: string
  width*: Option[int]
  alignment*: ColumnAlignment
  style*: Option[Style]
Table column definition
ColumnAlignment = enum
  AlignLeft, AlignCenter, AlignRight
Column text alignment options
SelectionMode = enum
  None, Single, Multiple
Table selection behavior
Table = ref object of Widget
  columns*: seq[Column]
  rows*: seq[TableRow]
  selectionMode*: SelectionMode
  selectedIndices*: seq[int]
  highlightedIndex*: int
  scrollOffset*: int
  visibleRowCount*: int
  showHeader*: bool
  borderStyle*: BorderStyle
  columnSpacing*: int
  showScrollbar*: bool
  headerStyle*: Style
  normalRowStyle*: Style
  selectedRowStyle*: Style
  highlightedRowStyle*: Style
  borderStyleOptions*: Style
  onSelect*: proc (index: int)
  onMultiSelect*: proc (indices: seq[int])
  onHighlight*: proc (index: int)
Table widget for structured data
TableRow = object
  cells*: seq[string]
  style*: Option[Style]
  selectable*: bool
Table row data

Procs

proc addColumn(widget: Table; col: Column) {....raises: [], tags: [], forbids: [].}
Add a column to the table
proc addColumn(widget: Table; title: string; width: Option[int] = none(int)) {.
    ...raises: [], tags: [], forbids: [].}
Add a simple column to the table
proc addRow(widget: Table; cells: seq[string]) {....raises: [], tags: [],
    forbids: [].}
Add a simple row to the table
proc addRow(widget: Table; row: TableRow) {....raises: [], tags: [], forbids: [].}
Add a row to the table
proc calculateColumnWidths(widget: Table; availableWidth: int): seq[int] {.
    ...raises: [], tags: [], forbids: [].}
Calculate actual column widths based on content and constraints
proc calculateTotalLineWidth(columnWidths: seq[int]; columnSpacing: int;
                             hasBorders: bool): int {....raises: [], tags: [],
    forbids: [].}
Calculate the total width needed for a table line including borders and spacing
proc clearRows(widget: Table) {....raises: [], tags: [], forbids: [].}
Clear all rows from the table
proc clearSelection(widget: Table) {....raises: [Exception], tags: [RootEffect],
                                     forbids: [].}
Clear all selections
proc column(title: string): Column {....raises: [], tags: [], forbids: [].}
Convenience constructor for simple column
proc column(title: string; alignment: ColumnAlignment): Column {....raises: [],
    tags: [], forbids: [].}
Create column with specific alignment
proc column(title: string; width: int): Column {....raises: [], tags: [],
    forbids: [].}
Create column with fixed width
proc deselectRow(widget: Table; index: int) {....raises: [Exception],
    tags: [RootEffect], forbids: [].}
Deselect a row (for multiple selection mode)
proc formatCell(content: string; width: int; alignment: ColumnAlignment): string {.
    ...raises: [], tags: [], forbids: [].}
Format a cell's content within the given width
proc fullPageDown(widget: Table) {....raises: [Exception], tags: [RootEffect],
                                   forbids: [].}
Scroll down by full page (vim: Ctrl-F)
proc fullPageUp(widget: Table) {....raises: [Exception], tags: [RootEffect],
                                 forbids: [].}
Scroll up by full page (vim: Ctrl-B)
proc getBorderChars(style: BorderStyle): tuple[horizontal: string,
    vertical: string, topLeft: string, topRight: string, bottomLeft: string,
    bottomRight: string, cross: string, topT: string, bottomT: string,
    leftT: string, rightT: string] {....raises: [], tags: [], forbids: [].}
Get border characters for the specified border style
proc handleKeyEvent(widget: Table; event: KeyEvent): bool {....raises: [Exception],
    tags: [RootEffect], forbids: [].}
Handle keyboard input for the table with vim-like navigation Returns true if the event was handled
proc highlightFirst(widget: Table) {....raises: [Exception], tags: [RootEffect],
                                     forbids: [].}
Move highlight to first selectable row (vim: gg)
proc highlightLast(widget: Table) {....raises: [Exception], tags: [RootEffect],
                                    forbids: [].}
Move highlight to last selectable row (vim: G)
proc highlightNext(widget: Table) {....raises: [Exception], tags: [RootEffect],
                                    forbids: [].}
Move highlight to next selectable row
proc highlightPrevious(widget: Table) {....raises: [Exception], tags: [RootEffect],
                                        forbids: [].}
Move highlight to previous selectable row
proc isSelected(widget: Table; index: int): bool {....raises: [], tags: [],
    forbids: [].}
Check if a row is selected
proc newColumn(title: string; width: Option[int] = none(int);
               alignment: ColumnAlignment = AlignLeft;
               style: Option[Style] = none(Style)): Column {....raises: [],
    tags: [], forbids: [].}
Create a new table column
proc newTable(columns: seq[Column] = @[]; rows: seq[TableRow] = @[];
              selectionMode: SelectionMode = Single; showHeader: bool = true;
              borderStyle: BorderStyle = SimpleBorder; columnSpacing: int = 1;
              showScrollbar: bool = true;
              headerStyle: Style = style(White, BrightBlack);
              normalRowStyle: Style = defaultStyle();
              selectedRowStyle: Style = style(Black, White);
              highlightedRowStyle: Style = style(White, BrightBlack);
              borderStyleOptions: Style = style(BrightBlack);
              onSelect: proc (index: int) = nil;
              onMultiSelect: proc (indices: seq[int]) = nil;
              onHighlight: proc (index: int) = nil): Table {....raises: [],
    tags: [], forbids: [].}
Create a new Table widget
proc newTableRow(cells: seq[string]; style: Option[Style] = none(Style);
                 selectable: bool = true): TableRow {....raises: [], tags: [],
    forbids: [].}
Create a new table row
proc pageDown(widget: Table) {....raises: [Exception], tags: [RootEffect],
                               forbids: [].}
Scroll down by one page (vim: Ctrl-D)
proc pageUp(widget: Table) {....raises: [Exception], tags: [RootEffect],
                             forbids: [].}
Scroll up by one page (vim: Ctrl-U)
proc removeColumn(widget: Table; index: int) {....raises: [], tags: [], forbids: [].}
Remove a column from the table
proc removeRow(widget: Table; index: int) {....raises: [], tags: [], forbids: [].}
Remove a row from the table
proc scrollDown(widget: Table; lines: int = 1) {....raises: [], tags: [],
    forbids: [].}
Scroll the table down
proc scrollUp(widget: Table; lines: int = 1) {....raises: [], tags: [], forbids: [].}
Scroll the table up
proc selectRow(widget: Table; index: int) {....raises: [Exception],
    tags: [RootEffect], forbids: [].}
Select a row (respecting selection mode)
proc setData(widget: Table; rows: seq[seq[string]]) {....raises: [], tags: [],
    forbids: [].}
Replace all row data
proc table(columns: seq[string]): Table {....raises: [], tags: [], forbids: [].}
Convenience constructor from column titles
proc table(columns: seq[string]; rows: seq[seq[string]]): Table {....raises: [],
    tags: [], forbids: [].}
Convenience constructor from column titles and row data
proc tableRow(cells: seq[string]): TableRow {....raises: [], tags: [], forbids: [].}
Convenience constructor for simple row
proc tableRow(cells: seq[string]; style: Style): TableRow {....raises: [],
    tags: [], forbids: [].}
Create styled row
proc toggleSelection(widget: Table; index: int) {....raises: [Exception],
    tags: [RootEffect], forbids: [].}
Toggle selection of a row

Methods

method canFocus(widget: Table): bool {....raises: [], tags: [], forbids: [].}
Tables can receive focus when they have selectable rows
method getMinSize(widget: Table): Size {....raises: [], tags: [], forbids: [].}
Get minimum size for table widget
method getPreferredSize(widget: Table; available: Size): Size {....raises: [],
    tags: [], forbids: [].}
Get preferred size for table widget
method render(widget: Table; area: Rect; buf: var Buffer) {....raises: [],
    tags: [], forbids: [].}
Render the table widget