diff options
author | Benjamin Otte <otte@redhat.com> | 2018-09-24 04:42:15 +0200 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2020-05-30 19:26:45 -0400 |
commit | e5add36a17cb64e6b300830f037d373bb8c0e031 (patch) | |
tree | 2d532fa8735be05eee642eb86cae29fe6641c817 /tests | |
parent | fe14181d4e69ac261dd7878ac3d952609866d4b7 (diff) | |
download | gtk+-e5add36a17cb64e6b300830f037d373bb8c0e031.tar.gz |
listview: Change how binding is done
We now don't let the functions create widgets for the item from the
listmodel, instead we hand out a GtkListItem for them to add a widget
to.
GtkListItems are created in advance and can only be filled in by the
binding code by gtk_container_add()ing a widget.
However, they are GObjects, so they can provide properties that the
binding code can make use of - either via notify signals or GBinding.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/testlistview-animating.c | 40 | ||||
-rw-r--r-- | tests/testlistview.c | 22 |
2 files changed, 37 insertions, 25 deletions
diff --git a/tests/testlistview-animating.c b/tests/testlistview-animating.c index a750945d44..3a0b08dfab 100644 --- a/tests/testlistview-animating.c +++ b/tests/testlistview-animating.c @@ -8,30 +8,46 @@ #define VARIANCE 200 #endif -static GtkWidget * -create_widget (gpointer unused) +static void +setup_list_item (GtkListItem *list_item, + gpointer unused) { - return gtk_label_new (""); + GtkWidget *label = gtk_label_new (""); + + gtk_list_item_set_child (list_item, label); } static void -bind_widget (GtkWidget *widget, - gpointer item, - gpointer unused) +bind_list_item (GtkListItem *list_item, + gpointer unused) { - const char *message = g_object_get_data (item, "message"); + GtkWidget *label; + gpointer item; + char *s; + + item = gtk_list_item_get_item (list_item); - gtk_label_set_text (GTK_LABEL (widget), message); + if (item) + s = g_strdup_printf ("%u: %s", + gtk_list_item_get_position (list_item), + (const char *) g_object_get_data (item, "message")); + else + s = NULL; + + label = gtk_list_item_get_child (list_item); + gtk_label_set_text (GTK_LABEL (label), s); + + g_free (s); } static GtkWidget * create_widget_for_listbox (gpointer item, gpointer unused) { + const char *message = g_object_get_data (item, "message"); GtkWidget *widget; - widget = create_widget (unused); - bind_widget (widget, item, unused); + widget = gtk_label_new (message); return widget; } @@ -131,8 +147,8 @@ main (int argc, listview = gtk_list_view_new (); gtk_list_view_set_functions (GTK_LIST_VIEW (listview), - create_widget, - bind_widget, + setup_list_item, + bind_list_item, NULL, NULL); gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), listview); diff --git a/tests/testlistview.c b/tests/testlistview.c index 1668fe2a18..6ccea18728 100644 --- a/tests/testlistview.c +++ b/tests/testlistview.c @@ -138,25 +138,21 @@ create_list_model_for_directory (gpointer file) return G_LIST_MODEL (sort); } -static GtkWidget * -create_widget (gpointer unused) -{ - return gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); -} - static void -bind_widget (GtkWidget *box, - gpointer item, - gpointer unused) +bind_widget (GtkListItem *list_item, + gpointer unused) { - GtkWidget *child; + GtkWidget *box, *child; GFileInfo *info; GFile *file; guint depth; GIcon *icon; + gpointer item; + + item = gtk_list_item_get_item (list_item); - while (gtk_widget_get_first_child (box)) - gtk_box_remove (GTK_BOX (box), gtk_widget_get_first_child (box)); + box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); + gtk_list_item_set_child (list_item, box); depth = gtk_tree_list_row_get_depth (item); if (depth > 0) @@ -300,7 +296,7 @@ main (int argc, char *argv[]) listview = gtk_list_view_new (); gtk_list_view_set_functions (GTK_LIST_VIEW (listview), - create_widget, + NULL, bind_widget, NULL, NULL); gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), listview); |