From 6640881711f7eb138acf4c1b2e7fde7a2ef40abf Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 18 Dec 2019 21:56:57 -0500 Subject: maplistmodel: Add an example to the docs --- gtk/gtkmaplistmodel.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'gtk/gtkmaplistmodel.c') diff --git a/gtk/gtkmaplistmodel.c b/gtk/gtkmaplistmodel.c index d30c3eb7a0..e7e37c8ac0 100644 --- a/gtk/gtkmaplistmodel.c +++ b/gtk/gtkmaplistmodel.c @@ -34,10 +34,30 @@ * #GtkMapListModel is a list model that takes a list model and maps the items * in that model to different items according to a #GtkMapListModelMapFunc. * - * FIXME: Add useful examples here, like turning #GFile into #GFileInfo or #GdkPixmap. + * Example: Create a list of #GtkEventControllers + * |[ + * static gpointer + * map_to_controllers (gpointer widget, + * gpointer data) + * { + * gpointer result = gtk_widget_observe_controllers (widget); + * g_object_unref (widget); + * return result; + * } * - * #GtkMapListModel will attempt to discard the mapped objects as soon as they are no - * longer needed and recreate them if necessary. + * widgets = gtk_widget_observe_children (widget); + * + * controllers = gtk_map_list_model_new (G_TYPE_LIST_MODEL, + * widgets, + * map_to_controllers, + * NULL, NULL); + * + * model = gtk_flatten_list_model_new (GTK_TYPE_EVENT_CONTROLLER, + * controllers); + * ]| + * + * #GtkMapListModel will attempt to discard the mapped objects as soon as + * they are no longer needed and recreate them if necessary. */ enum { -- cgit v1.2.1