Table<T> class
Namespace: Arlecchino.Widgets.Lists · Assembly: Arlecchino
Rows in aligned columns, with a heading and optional sorting, over a list box that does the selecting and the scrolling. Sorting reorders a copy, leaving Table.Rows untouched.
public sealed class Table<T> : IArlecchinoInteractiveWidget, IArlecchinoWidget, IArlecchinoFocusable
Implements IArlecchinoInteractiveWidget, IArlecchinoWidget, IArlecchinoFocusable
Constructors
| Member | Summary |
|---|---|
Table(ArlecchinoKeymap) | Creates the table. |
Properties
| Member | Summary |
|---|---|
Columns | The columns, left to right. |
IsFocused | Whether the table has focus, which decides how strongly the selection is drawn. |
ItemStyle | Colors a whole row. Ignored for the selected one. |
OnActivate | What confirming a row does. Returning a route navigates. |
Rows | What to show. Assigning re-applies the current sort. |
SelectedIndex | Index of the selected row within the sorted order, not within what was assigned. |
SelectedRow | The selected row, or the type's default when the table is empty. |
SortedColumn | Index of the column being sorted by, or -1 when the rows are in their original order. |
SortsDescending | Which way the sort runs. |
Methods
| Member | Summary |
|---|---|
Draw(SurfaceRegion) | Works out the column widths for the space available, then draws the heading on the first row and the rows below it. The table fills whatever it is given, so nothing is left underneath it. |
Handle(KeyPress) | Moves the selection or confirms it. Sorting is not bound to a key; call Table.SortBy. |
HandleMouse(MouseEvent) | Scrolls and selects. Clicks on the heading are not routed here. |
SortBy(int) | Sorts by a column, or flips the direction when it is already the one being sorted by. Columns without a comparison, and indexes outside the table, are ignored. |
Constructors in detail
Table(ArlecchinoKeymap)
Constructors of types with required members are not supported in this version of your compiler.
public Table(ArlecchinoKeymap keymap);
Creates the table.
Parameters
| Name | Type | Description |
|---|---|---|
keymap | ArlecchinoKeymap | Keys to obey, so the table follows the application's bindings. |
Properties in detail
Columns
public IReadOnlyList<TableColumn<T>> Columns { get; init; }
The columns, left to right.
Type IReadOnlyList<T><TableColumn<T>>
IsFocused
public bool IsFocused { get; set; }
Whether the table has focus, which decides how strongly the selection is drawn.
Type bool
ItemStyle
public Func<T, IArlecchinoColor> ItemStyle { get; init; }
Colors a whole row. Ignored for the selected one.
Type Func<T, TResult><T, IArlecchinoColor>
OnActivate
public Func<T, ViewRoute> OnActivate { get; init; }
What confirming a row does. Returning a route navigates.
Type Func<T, TResult><T, ViewRoute>
Rows
public IReadOnlyList<T> Rows { get; set; }
What to show. Assigning re-applies the current sort.
Type IReadOnlyList<T><T>
SelectedIndex
public int SelectedIndex { get; set; }
Index of the selected row within the sorted order, not within what was assigned.
Type int
SelectedRow
public T SelectedRow { get; }
The selected row, or the type's default when the table is empty.
Type T
SortedColumn
public int SortedColumn { get; }
Index of the column being sorted by, or -1 when the rows are in their original order.
Type int
SortsDescending
public bool SortsDescending { get; }
Which way the sort runs.
Type bool
Methods in detail
Draw(SurfaceRegion)
public SurfaceRegion Draw(SurfaceRegion region);
Works out the column widths for the space available, then draws the heading on the first row and the rows below it. The table fills whatever it is given, so nothing is left underneath it.
Parameters
| Name | Type | Description |
|---|---|---|
region | SurfaceRegion | Where to draw, heading included. |
Returns SurfaceRegion — An empty region: the table uses every row it is handed.
Handle(KeyPress)
public FocusResult Handle(KeyPress key);
Moves the selection or confirms it. Sorting is not bound to a key; call Table.SortBy.
Parameters
| Name | Type | Description |
|---|---|---|
key | KeyPress | The key that was pressed. |
Returns FocusResult — What became of the key.
HandleMouse(MouseEvent)
public FocusResult HandleMouse(MouseEvent mouse);
Scrolls and selects. Clicks on the heading are not routed here.
Parameters
| Name | Type | Description |
|---|---|---|
mouse | MouseEvent | The event that arrived. |
Returns FocusResult — What became of the event.
SortBy(int)
public void SortBy(int column);
Sorts by a column, or flips the direction when it is already the one being sorted by. Columns without a comparison, and indexes outside the table, are ignored.
Parameters
| Name | Type | Description |
|---|---|---|
column | int | Index of the column to sort by. |