Gtk4 introduced a new GtkListView
and a new model that diverge with
what GtkTreeView
used to offer, that is now deprecated in
Gtk4. While you can still use the old API, it’s probably better to not
write new code with it.
One of the goal of the new API it to focus on models and let the widget itself worry about the rest.
This primer will try to make sense of it and provide answers on how to do things with the new API. And it will be in Rust.
Views or list widgets are the widgets responsible for presenting the
data to the user and interacting. There are two main ones:
Gtk.ListView
and Gtk.GridView
.
Gtk.ListView
will display lists of items. It can also display
hierachical list where rows have children, etc. It’s the replacement
for the old Gtk.TreeView
.
Gtk.GridView
will display items in a grid format.
Factories are responsible for for populating these list by ad-hoc creation of widgets, and recycling them through the life time. Each visual item in the list is a widget. One performance goal is to limit the amount of widget to just what is necessary. Think about just having enough to show what is visible ; even though what is actually created doesn’t to matter to the programmer,
The factories work from models. The model will be the structure that
contains the data to be displayed in the view, with factories
connecting the dots. A model is a collection of Glib.Object
and it
implements the basic interface of Gio.ListModel
. There are a few
implementations for general use models, like Gio.ListStore
that
store generic Glib.Object
and Gtk.StringList
that contain just
strings. There are also wrapping models, that providing sorting and
filtering capabilities by wrapping an existing model.