testdatatable: Add a --pages option
authorBenjamin Otte <otte@redhat.com>
Thu, 30 Mar 2023 05:43:12 +0000 (07:43 +0200)
committerBenjamin Otte <otte@redhat.com>
Sat, 1 Apr 2023 18:49:40 +0000 (20:49 +0200)
That way, local scrolling is available and the scrolling isn't random.

Recycling should now involve reordering the recycled widgets instead of
just keeping their order because all of them got recycled.

tests/testdatatable.c

index 72de5829e48343fee37cf4a89fa1db5b002a4205..6e3ca992d2696b272921c1003515cc65e9cedf7c 100644 (file)
@@ -5,6 +5,11 @@
 #include "frame-stats.h"
 
 
+static gboolean no_auto_scroll = FALSE;
+static gint n_columns = 20;
+static double scroll_pages = 0;
+
+
 /* This is our dummy item for the model. */
 #define DATA_TABLE_TYPE_ITEM (data_table_item_get_type ())
 G_DECLARE_FINAL_TYPE (DataTableItem, data_table_item, DATA_TABLE, ITEM, GObject)
@@ -48,6 +53,18 @@ set_adjustment_to_fraction (GtkAdjustment *adjustment,
                             fraction * (upper - page_size));
 }
 
+static void
+move_adjustment_by_pages (GtkAdjustment *adjustment,
+                          double         n_pages)
+{
+  double page_size = gtk_adjustment_get_page_size (adjustment);
+  double value = gtk_adjustment_get_value (adjustment);
+
+  value += page_size * n_pages;
+  /* the adjustment will clamp properly */
+  gtk_adjustment_set_value (adjustment, value);
+}
+
 static gboolean
 scroll_column_view (GtkWidget     *column_view,
                     GdkFrameClock *frame_clock,
@@ -57,7 +74,10 @@ scroll_column_view (GtkWidget     *column_view,
 
   vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (column_view));
 
-  set_adjustment_to_fraction (vadjustment, g_random_double ());
+  if (scroll_pages == 0.0)
+    set_adjustment_to_fraction (vadjustment, g_random_double ());
+  else
+    move_adjustment_by_pages (vadjustment, (g_random_double () * 2 - 1) * scroll_pages);
 
   return TRUE;
 }
@@ -172,9 +192,6 @@ parse_widget_arg (const gchar* option_name,
     }
 }
 
-static gboolean no_auto_scroll = FALSE;
-static gint n_columns = 20;
-
 static GOptionEntry options[] = {
   {
     "widget",
@@ -203,6 +220,15 @@ static GOptionEntry options[] = {
     "Column count",
     "COUNT"
   },
+  {
+    "pages",
+    'p',
+    G_OPTION_FLAG_NONE,
+    G_OPTION_ARG_DOUBLE,
+    &scroll_pages,
+    "Maximum number of pages to scroll (or 0 for random)",
+    "COUNT"
+  },
   { NULL }
 };