ListBox
private readonly ListBox<string> _authors;
private readonly string _mine = "fEst";
_authors = new ListBox<string>(options.Keymap)
{
Render = author => $" {author}",
ItemStyle = author => author == _mine ? Theme.Active : Theme.Default,
OnActivate = author => ViewKind.Author,
Items = authors,
};
_authors.Draw(region);
Widgets are built in the view's constructor, so options is the ArlecchinoOptions the container
hands it, and region is the region the view draws the widget into.
| Member | Meaning |
|---|---|
Items | The rows, read fresh every frame |
Render | Turns an item into the line that is drawn |
ItemStyle | Optional per-row style |
PaintRow | Optional: draws the row itself, for rows that are not one color |
OnActivate | Runs on Confirm or a second click; returns a route |
SelectedIndex | Where the cursor is |
IsFocused | Set by the focus ring |
Keys and clicks
| Input | Does |
|---|---|
↑ / ↓ | Move one row |
PgUp / PgDn | Jump ten rows |
Home / End | Go to the ends |
Confirm | Activates the selected row |
| Wheel | Scrolls |
| Click | Selects the row |
| Second click on the selected row | Activates it |
All of them come from the keymap.
Focused and unfocused
The selected row is drawn ActiveSelection while the list has the focus and Selection while it does
not, so a list beside another pane still shows where its cursor is. Those two
roles are chosen so that neither reads as an error.
Scrolling
Only the visible slice is rendered — ScrollWindow.Around is the same
helper the widget uses, available for lists you draw yourself.
A list with more items than rows grows a scroll bar down its last column, and the rows are truncated one cell earlier to make room rather than being covered by it. A list that fits keeps its full width and shows nothing.
Choice and multi-choice modals get the same treatment: a bar beside the options and
a 3/40 readout on the filter line, worded by Strings.ListPosition.
Where the rows come from
Items is read while the frame is drawn, so the collection behind it belongs to the drawing thread.
Change it from a view, a command or a callback, and hand changes that arrive from anywhere else to
FrameThread.Post.
What is built on it
Table<T> and Tree<T> both hold a ListBox and hand it the rows they
computed, so movement, clicks, activation and the scroll bar are the same in all three.