Models
Four widgets draw a list model rather than children you append: the list view, the grid view and the column view, each pairing a model with a factory that builds one widget per item, plus the tree expander a tree row wears in front of its contents.
On GTK the model is a Gio.ListModel wrapped in a Gtk.SelectionModel, and the
factory is a pair of callbacks. The browser port takes the portable list —
the same model value <gtk-drop-down> takes — and a factory that is one
function, and keeps the selection on the widget as selection-mode.
List View
Section titled “List View”One row per item, each built by the factory. model is a JSON array of
strings (or of { "value", "label" } objects); selection-mode says which
Gtk.SelectionModel the view behaves as — single, multiple or none — and
show-separators draws the hairline between rows. A click selects,
Ctrl toggles and Shift extends, exactly as
gtk_list_base_select_item does; a double click emits activate.
Grid View
Section titled “Grid View”The same model and the same factory, reflowed into as many equal columns as the
width fits. min-columns and max-columns bound the count — GTK’s
own default maximum is seven — and the arithmetic between them is
gtk_grid_view_compute_n_columns: the available width divided by one item’s,
rounding down, with the gap counted between items only.
Column View
Section titled “Column View”A list view with a header and one cell per column. On GTK each column is a
Gtk.ColumnViewColumn carrying a factory of its own; in the browser port
columns is a JSON array, and a column’s key picks which half of the
portable item it draws — label or value — unless a per-column factory is
set from JavaScript.
Clicking a sortable header sets the sort and inverts it on the next click,
which is gtk_column_view_sorter_add_column’s whole rule. The view reorders
nothing by itself: it publishes the sort, and the application re-assigns the
model — on GTK through a Gtk.SortListModel, here by assigning a sorted array.
Tree Expander
Section titled “Tree Expander”The indent and the disclosure arrow in front of a tree row’s contents. On GTK it
watches a Gtk.TreeListRow, which only a Gtk.TreeListModel produces; in the
browser port the three things it reads off that row — depth,
expandable and expanded — are the attributes.
A leaf takes one more indent in place of the arrow, so its text lines up
with its expandable siblings’; setting indent-for-icon to false turns that allowance
off, and hide-expander makes an expandable row take the leaf’s shape.
+ and * expand, - and / collapse,
Ctrl+Space toggles, and Shift with the arrow
keys does the same in whichever direction the locale reads.
Related
Section titled “Related”- Controls: the drop-down, which takes the same portable list model and shows one item at a time.
- Layout: the separator these views draw between their rows.
- Adwaita Boxed Lists:
Adw.ComboRowand the row widgets a list of records is usually built from instead. - Adwaita Storybook: the same four widgets in a live component browser you can poke at.