[gtk/prop-list: 3/7] gtk-demo: Add more scrolling benchmarks



commit 08043148564014477c2d1a48bb4aae647bf906fd
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Dec 22 12:27:30 2019 -0500

    gtk-demo: Add more scrolling benchmarks
    
    Add a listview and gridview to the scrolling
    benchmarks.

 demos/gtk-demo/iconscroll.c       | 51 ++++++++++++++++++++++++++++++++++++++-
 demos/gtk-demo/listview_colors.c  | 45 +++++++++++++++++++++++-----------
 demos/gtk-demo/listview_weather.c | 34 +++++++++++++++++---------
 3 files changed, 103 insertions(+), 27 deletions(-)
---
diff --git a/demos/gtk-demo/iconscroll.c b/demos/gtk-demo/iconscroll.c
index fafd51930e..54bef3ac20 100644
--- a/demos/gtk-demo/iconscroll.c
+++ b/demos/gtk-demo/iconscroll.c
@@ -12,7 +12,7 @@ static GtkWidget *window = NULL;
 static GtkWidget *scrolledwindow;
 static int selected;
 
-#define N_WIDGET_TYPES 4
+#define N_WIDGET_TYPES 6
 
 
 static int hincrement = 5;
@@ -61,6 +61,7 @@ populate_icons (void)
       gtk_grid_attach (GTK_GRID (grid), create_icon (), left, top, 1, 1);
 
   hincrement = 0;
+  vincrement = 5;
 
   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow),
                                  GTK_POLICY_NEVER,
@@ -97,6 +98,7 @@ populate_text (gboolean hilight)
   gtk_text_view_set_buffer (GTK_TEXT_VIEW (textview), buffer);
 
   hincrement = 0;
+  vincrement = 5;
 
   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow),
                                  GTK_POLICY_NEVER,
@@ -121,6 +123,7 @@ populate_image (void)
   gtk_picture_set_can_shrink (GTK_PICTURE (image), FALSE);
 
   hincrement = 5;
+  vincrement = 5;
 
   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow),
                                  GTK_POLICY_AUTOMATIC,
@@ -128,6 +131,42 @@ populate_image (void)
   gtk_container_add (GTK_CONTAINER (scrolledwindow), image);
 }
 
+extern GtkWidget *create_weather_view (void);
+
+static void
+populate_list (void)
+{
+  GtkWidget *list;
+
+  list = create_weather_view ();
+
+  hincrement = 5;
+  vincrement = 0;
+
+  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow),
+                                 GTK_POLICY_AUTOMATIC,
+                                 GTK_POLICY_AUTOMATIC);
+  gtk_container_add (GTK_CONTAINER (scrolledwindow), list);
+}
+
+extern GtkWidget *create_color_grid (void);
+
+static void
+populate_grid (void)
+{
+  GtkWidget *list;
+
+  list = create_color_grid ();
+
+  hincrement = 0;
+  vincrement = 5;
+
+  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow),
+                                 GTK_POLICY_AUTOMATIC,
+                                 GTK_POLICY_AUTOMATIC);
+  gtk_container_add (GTK_CONTAINER (scrolledwindow), list);
+}
+
 static void
 set_widget_type (int type)
 {
@@ -162,6 +201,16 @@ set_widget_type (int type)
       populate_image ();
       break;
 
+    case 4:
+      gtk_window_set_title (GTK_WINDOW (window), "Scrolling a list");
+      populate_list ();
+      break;
+
+    case 5:
+      gtk_window_set_title (GTK_WINDOW (window), "Scrolling a grid");
+      populate_grid ();
+      break;
+
     default:
       g_assert_not_reached ();
     }
diff --git a/demos/gtk-demo/listview_colors.c b/demos/gtk-demo/listview_colors.c
index e6d87bc280..a6d5cdd2b1 100644
--- a/demos/gtk-demo/listview_colors.c
+++ b/demos/gtk-demo/listview_colors.c
@@ -309,6 +309,7 @@ setup_simple_listitem_cb (GtkListItemFactory *factory,
   color_expression = gtk_property_expression_new (GTK_TYPE_LIST_ITEM, expression, "item");
 
   picture = gtk_picture_new ();
+  gtk_widget_set_size_request (picture, 32, 32);
   gtk_expression_bind (color_expression, picture, "paintable", NULL);
 
   gtk_list_item_set_child (list_item, picture);
@@ -403,6 +404,34 @@ set_item (GBinding *binding,
   return TRUE;
 }
 
+GtkWidget *
+create_color_grid (void)
+{
+  GtkWidget *gridview;
+  GtkListItemFactory *factory;
+  GListModel *model, *selection;
+
+  gridview = gtk_grid_view_new ();
+  gtk_scrollable_set_hscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL);
+  gtk_scrollable_set_vscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL);
+
+  factory = gtk_signal_list_item_factory_new ();
+  g_signal_connect (factory, "setup", G_CALLBACK (setup_simple_listitem_cb), NULL);
+  gtk_grid_view_set_factory (GTK_GRID_VIEW (gridview), factory);
+  g_object_unref (factory);
+ 
+  gtk_grid_view_set_max_columns (GTK_GRID_VIEW (gridview), 24);
+  g_object_set (gridview, "enable-rubber-band", TRUE, NULL);
+
+  model = G_LIST_MODEL (gtk_sort_list_model_new (create_colors_model (), NULL));
+  selection = G_LIST_MODEL (gtk_multi_selection_new (model));
+  gtk_grid_view_set_model (GTK_GRID_VIEW (gridview), selection);
+  g_object_unref (selection);
+  g_object_unref (model);
+
+  return gridview;
+}
+
 static GtkWidget *window = NULL;
 
 GtkWidget *
@@ -414,7 +443,6 @@ do_listview_colors (GtkWidget *do_widget)
       GtkListItemFactory *factory;
       GListStore *factories;
       GListModel *model;
-      GListModel *selection;
       GtkSorter *sorter;
       GtkSorter *multi_sorter;
       GListStore *sorters;
@@ -435,18 +463,9 @@ do_listview_colors (GtkWidget *do_widget)
       sw = gtk_scrolled_window_new (NULL, NULL);
       gtk_container_add (GTK_CONTAINER (window), sw);
 
-      gridview = gtk_grid_view_new ();
-      gtk_scrollable_set_hscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL);
-      gtk_scrollable_set_vscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL);
-
-      gtk_grid_view_set_max_columns (GTK_GRID_VIEW (gridview), 24);
-      g_object_set (gridview, "enable-rubber-band", TRUE, NULL);
-
-      model = G_LIST_MODEL (gtk_sort_list_model_new (create_colors_model (), NULL));
-      selection = G_LIST_MODEL (gtk_multi_selection_new (model));
-      gtk_grid_view_set_model (GTK_GRID_VIEW (gridview), selection);
+      gridview = create_color_grid ();
       gtk_container_add (GTK_CONTAINER (sw), gridview);
-      g_object_unref (selection);
+      model = gtk_grid_view_get_model (GTK_GRID_VIEW (gridview));
 
       sorters = g_list_store_new (GTK_TYPE_SORTER);
 
@@ -560,8 +579,6 @@ do_listview_colors (GtkWidget *do_widget)
                                    G_BINDING_SYNC_CREATE,
                                    set_item, NULL,
                                    NULL, NULL);
-
-      g_object_unref (model);
     }
 
   if (!gtk_widget_get_visible (window))
diff --git a/demos/gtk-demo/listview_weather.c b/demos/gtk-demo/listview_weather.c
index 20f8f3ffea..f22d7b9daf 100644
--- a/demos/gtk-demo/listview_weather.c
+++ b/demos/gtk-demo/listview_weather.c
@@ -275,13 +275,33 @@ bind_widget (GtkListItem *list_item,
 
 static GtkWidget *window = NULL;
 
+GtkWidget *
+create_weather_view (void)
+{
+  GtkWidget *listview;
+  GListModel *model, *selection;
+
+  listview = gtk_list_view_new_with_factory (
+  gtk_functions_list_item_factory_new (setup_widget,
+                                       bind_widget,
+                                       NULL, NULL));
+  gtk_orientable_set_orientation (GTK_ORIENTABLE (listview), GTK_ORIENTATION_HORIZONTAL);
+  gtk_list_view_set_show_separators (GTK_LIST_VIEW (listview), TRUE);
+  model = create_weather_model ();
+  selection = G_LIST_MODEL (gtk_no_selection_new (model));
+  gtk_list_view_set_model (GTK_LIST_VIEW (listview), selection);
+  g_object_unref (selection);
+  g_object_unref (model);
+
+  return listview;
+}
+
 GtkWidget *
 do_listview_weather (GtkWidget *do_widget)
 {
   if (window == NULL)
     {
       GtkWidget *listview, *sw;;
-      GListModel *model, *selection;
 
       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
       gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);
@@ -295,17 +315,7 @@ do_listview_weather (GtkWidget *do_widget)
       sw = gtk_scrolled_window_new (NULL, NULL);
       gtk_container_add (GTK_CONTAINER (window), sw);
     
-      listview = gtk_list_view_new_with_factory (
-        gtk_functions_list_item_factory_new (setup_widget,
-                                             bind_widget,
-                                             NULL, NULL));
-      gtk_orientable_set_orientation (GTK_ORIENTABLE (listview), GTK_ORIENTATION_HORIZONTAL);
-      gtk_list_view_set_show_separators (GTK_LIST_VIEW (listview), TRUE);
-      model = create_weather_model ();
-      selection = G_LIST_MODEL (gtk_no_selection_new (model));
-      gtk_list_view_set_model (GTK_LIST_VIEW (listview), selection);
-      g_object_unref (selection);
-      g_object_unref (model);
+      listview = create_weather_view ();
 
       gtk_container_add (GTK_CONTAINER (sw), listview);
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]