gtk.list_view
Module for [ListView] class
Types 3
gtk.list_view.ListView presents a large dynamic list of items.
gtk.list_view.ListView uses its factory to generate one row widget for each visible item and shows them in a linear display, either vertically or horizontally.
The gtk.list_view.ListView.showSeparators property offers a simple way to display separators between the rows.
gtk.list_view.ListView allows the user to select items according to the selection characteristics of the model. For models that allow multiple selected items, it is possible to turn on _rubberband selection_, using gtk.list_view.ListView.enableRubberband.
If you need multiple columns with headers, see gtk.column_view.ColumnView.
To learn more about the list widget framework, see the overview.
An example of using gtk.list_view.ListView:
static void
setup_listitem_cb (GtkListItemFactory *factory,
GtkListItem *list_item)
{
GtkWidget *image;
image = gtk_image_new ();
gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE);
gtk_list_item_set_child (list_item, image);
}
static void
bind_listitem_cb (GtkListItemFactory *factory,
GtkListItem *list_item)
{
GtkWidget *image;
GAppInfo *app_info;
image = gtk_list_item_get_child (list_item);
app_info = gtk_list_item_get_item (list_item);
gtk_image_set_from_gicon (GTK_IMAGE (image), g_app_info_get_icon (app_info));
}
static void
activate_cb (GtkListView *list,
guint position,
gpointer unused)
{
GAppInfo *app_info;
app_info = g_list_model_get_item (G_LIST_MODEL (gtk_list_view_get_model (list)), position);
g_app_info_launch (app_info, NULL, NULL, NULL);
g_object_unref (app_info);
}
...
model = create_application_list ();
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_listitem_cb), NULL);
g_signal_connect (factory, "bind", G_CALLBACK (bind_listitem_cb), NULL);
list = gtk_list_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (model)), factory);
g_signal_connect (list, "activate", G_CALLBACK (activate_cb), NULL);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), list);CSS nodes
listview[.separators][.rich-list][.navigation-sidebar][.data-table]
├── row[.activatable]
│
├── row[.activatable]
│
┊
╰── [rubberband]gtk.list_view.ListView uses a single CSS node named listview. It may carry the .separators style class, when gtk.list_view.ListView.showSeparators property is set. Each child widget uses a single CSS node named row. If the gtk.list_item.ListItem.activatable property is set, the corresponding row will have the .activatable style class. For rubberband selection, a node with name rubberband is used.
The main listview node may also carry style classes to select the style of list presentation: .rich-list, .navigation-sidebar or .data-table.
Accessibility
gtk.list_view.ListView uses the gtk.types.AccessibleRole.List role, and the list items use the gtk.types.AccessibleRole.ListItem role.
ListViewGidBuilder builder() static nothrowGet builder for [gtk.list_view.ListView] Returns: New builder objectbool enableRubberband() @property nothrowGet `enableRubberband` property. Returns: Allow rubberband selection.void enableRubberband(bool propval) @property nothrowSet `enableRubberband` property. Params: propval = Allow rubberband selection.gtk.list_item_factory.ListItemFactory factory() @property nothrowGet `factory` property. Returns: Factory for populating list items.void factory(gtk.list_item_factory.ListItemFactory propval) @property nothrowSet `factory` property. Params: propval = Factory for populating list items.gtk.list_item_factory.ListItemFactory headerFactory() @property nothrowGet `headerFactory` property. Returns: Factory for creating header widgets.void headerFactory(gtk.list_item_factory.ListItemFactory propval) @property nothrowSet `headerFactory` property. Params: propval = Factory for creating header widgets.gtk.selection_model.SelectionModel model() @property nothrowGet `model` property. Returns: Model for the items displayed.void model(gtk.selection_model.SelectionModel propval) @property nothrowSet `model` property. Params: propval = Model for the items displayed.bool showSeparators() @property nothrowGet `showSeparators` property. Returns: Show separators between rows.void showSeparators(bool propval) @property nothrowSet `showSeparators` property. Params: propval = Show separators between rows.bool singleClickActivate() @property nothrowGet `singleClickActivate` property. Returns: Activate rows on single click and select them on hover.void singleClickActivate(bool propval) @property nothrowSet `singleClickActivate` property. Params: propval = Activate rows on single click and select them on hover.gtk.types.ListTabBehavior tabBehavior() @property nothrowGet `tabBehavior` property. Returns: Behavior of the <kbd>Tab</kbd> keyvoid tabBehavior(gtk.types.ListTabBehavior propval) @property nothrowSet `tabBehavior` property. Params: propval = Behavior of the <kbd>Tab</kbd> keybool getEnableRubberband() nothrowReturns whether rows can be selected by dragging with the mouse. Returns: true if rubberband selection is enabledgtk.list_item_factory.ListItemFactory getFactory() nothrowGets the factory that's currently used to populate list items. Returns: The factory in usegtk.list_item_factory.ListItemFactory getHeaderFactory() nothrowGets the factory that's currently used to populate section headers. Returns: The factory in usegtk.selection_model.SelectionModel getModel() nothrowGets the model that's currently used to read the items displayed. Returns: The model in usebool getShowSeparators() nothrowReturns whether the list box should show separators between rows. Returns: true if the list box shows separatorsbool getSingleClickActivate() nothrowReturns whether rows will be activated on single click and selected on hover. Returns: true if rows are activated on single clickgtk.types.ListTabBehavior getTabBehavior() nothrowGets the behavior set for the <kbd>Tab</kbd> key. Returns: The behavior of the <kbd>Tab</kbd> keyvoid scrollTo(uint pos, gtk.types.ListScrollFlags flags, gtk.scroll_info.ScrollInfo scroll = null) nothrowScrolls to the item at the given position and performs the actions specified in flags.void setEnableRubberband(bool enableRubberband) nothrowSets whether selections can be changed by dragging with the mouse.void setFactory(gtk.list_item_factory.ListItemFactory factory = null) nothrowSets the [gtk.list_item_factory.ListItemFactory] to use for populating list items.void setHeaderFactory(gtk.list_item_factory.ListItemFactory factory = null) nothrowSets the [gtk.list_item_factory.ListItemFactory] to use for populating the [gtk.list_header.ListHeader] objects used in section headers.void setShowSeparators(bool showSeparators) nothrowSets whether the list box should show separators between rows.void setSingleClickActivate(bool singleClickActivate) nothrowSets whether rows should be activated on single click and selected on hover.void setTabBehavior(gtk.types.ListTabBehavior tabBehavior) nothrowSets the behavior of the <kbd>Tab</kbd> and <kbd>Shift</kbd>+<kbd>Tab</kbd> keys.gulong connectActivate(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == uint)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtk.list_view.ListView)))
&& Parameters!T.length < 3) nothrowConnect to `Activate` signal.this(gtk.selection_model.SelectionModel model = null, gtk.list_item_factory.ListItemFactory factory = null)Creates a new [gtk.list_view.ListView] that uses the given factory for mapping items to widgets.Fluent builder implementation template for gtk.list_view.ListView
T enableRubberband(bool propval) nothrowSet `enableRubberband` property. Params: propval = Allow rubberband selection. Returns: Builder instance for fluent chainingT factory(gtk.list_item_factory.ListItemFactory propval) nothrowSet `factory` property. Params: propval = Factory for populating list items. Returns: Builder instance for fluent chainingT headerFactory(gtk.list_item_factory.ListItemFactory propval) nothrowSet `headerFactory` property. Params: propval = Factory for creating header widgets. Returns: Builder instance for fluent chainingT model(gtk.selection_model.SelectionModel propval) nothrowSet `model` property. Params: propval = Model for the items displayed. Returns: Builder instance for fluent chainingT showSeparators(bool propval) nothrowSet `showSeparators` property. Params: propval = Show separators between rows. Returns: Builder instance for fluent chainingT singleClickActivate(bool propval) nothrowSet `singleClickActivate` property. Params: propval = Activate rows on single click and select them on hover. Returns: Builder instance for fluent chainingT tabBehavior(gtk.types.ListTabBehavior propval) nothrowSet `tabBehavior` property. Params: propval = Behavior of the <kbd>Tab</kbd> key Returns: Builder instance for fluent chainingFluent builder for gtk.list_view.ListView