[gtk] Add an icon scrolling demo



commit 60e2242256f7fe2df36b2bfb8b0090af3fa45a56
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Oct 11 17:35:58 2019 -0400

    Add an icon scrolling demo
    
    This is good to exercise the GL renderer icon cache.

 demos/gtk-demo/demo.gresource.xml |  4 +++
 demos/gtk-demo/iconscroll.c       | 72 +++++++++++++++++++++++++++++++++++++++
 demos/gtk-demo/iconscroll.ui      | 24 +++++++++++++
 demos/gtk-demo/meson.build        |  1 +
 4 files changed, 101 insertions(+)
---
diff --git a/demos/gtk-demo/demo.gresource.xml b/demos/gtk-demo/demo.gresource.xml
index 11ed21f593..625ecac18a 100644
--- a/demos/gtk-demo/demo.gresource.xml
+++ b/demos/gtk-demo/demo.gresource.xml
@@ -104,6 +104,9 @@
     <file>gtkfishbowl.c</file>
     <file>gtkfishbowl.h</file>
   </gresource>
+  <gresource prefix="/iconscroll">
+    <file>iconscroll.ui</file>
+  </gresource>
   <gresource prefix="/iconview">
     <file>gnome-fs-directory.png</file>
     <file>gnome-fs-regular.png</file>
@@ -179,6 +182,7 @@
     <file>glarea.c</file>
     <file>headerbar.c</file>
     <file>hypertext.c</file>
+    <file>iconscroll.c</file>
     <file>iconview.c</file>
     <file>iconview_edit.c</file>
     <file>images.c</file>
diff --git a/demos/gtk-demo/iconscroll.c b/demos/gtk-demo/iconscroll.c
new file mode 100644
index 0000000000..5c17d0b6af
--- /dev/null
+++ b/demos/gtk-demo/iconscroll.c
@@ -0,0 +1,72 @@
+/* Benchmark/Icons
+ *
+ * This demo scrolls a view with many icons.
+ */
+
+#include <gtk/gtk.h>
+
+static guint tick_cb;
+static GtkAdjustment *adjustment;
+int increment = 5;
+
+static gboolean
+scroll_cb (GtkWidget *widget,
+           GdkFrameClock *frame_clock,
+           gpointer data)
+{
+  double value;
+
+  value = gtk_adjustment_get_value (adjustment);
+  if (value + increment <= gtk_adjustment_get_lower (adjustment) ||
+     (value + increment >= gtk_adjustment_get_upper (adjustment) - gtk_adjustment_get_page_size 
(adjustment)))
+    increment = - increment;
+
+  gtk_adjustment_set_value (adjustment, value + increment);
+
+  return G_SOURCE_CONTINUE;
+}
+
+extern GtkWidget *create_icon (void);
+
+static void
+populate (GtkWidget *grid)
+{
+  int top, left;
+
+  for (top = 0; top < 100; top++)
+    for (left = 0; left < 15; left++)
+      gtk_grid_attach (GTK_GRID (grid), create_icon (), left, top, 1, 1);
+}
+
+GtkWidget *
+do_iconscroll (GtkWidget *do_widget)
+{
+  static GtkWidget *window = NULL;
+
+  if (!window)
+    {
+      GtkBuilder *builder;
+      GtkWidget *grid;
+
+      builder = gtk_builder_new_from_resource ("/iconscroll/iconscroll.ui");
+      window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
+      g_signal_connect (window, "destroy",
+                        G_CALLBACK (gtk_widget_destroyed), &window);
+      gtk_window_set_display (GTK_WINDOW (window),
+                              gtk_widget_get_display (do_widget));
+      g_signal_connect (window, "destroy",
+                        G_CALLBACK (gtk_widget_destroyed), &window);
+      grid = GTK_WIDGET (gtk_builder_get_object (builder, "grid"));
+      populate (grid);
+      gtk_widget_realize (window);
+      adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "adjustment"));
+      tick_cb = gtk_widget_add_tick_callback (window, scroll_cb, NULL, NULL);
+    }
+
+  if (!gtk_widget_get_visible (window))
+    gtk_widget_show (window);
+  else
+    gtk_widget_destroy (window);
+
+  return window;
+}
diff --git a/demos/gtk-demo/iconscroll.ui b/demos/gtk-demo/iconscroll.ui
new file mode 100644
index 0000000000..d7c68e5f6a
--- /dev/null
+++ b/demos/gtk-demo/iconscroll.ui
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <object class="GtkWindow" id="window">
+    <property name="resizable">0</property>
+    <property name="default-width">500</property>
+    <property name="default-height">500</property>
+    <property name="title">Scrolling icons</property>
+    <child>
+      <object class="GtkScrolledWindow">
+        <property name="hscrollbar-policy">never</property>
+        <property name="vscrollbar-policy">automatic</property>
+        <property name="vadjustment"><object class="GtkAdjustment" id="adjustment"/></property> 
+        <child>
+          <object class="GtkGrid" id="grid">
+            <property name="halign">center</property>
+            <property name="margin">10</property>
+            <property name="row-spacing">10</property>
+            <property name="orientation">vertical</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/demos/gtk-demo/meson.build b/demos/gtk-demo/meson.build
index 711e466b43..c021f9f60a 100644
--- a/demos/gtk-demo/meson.build
+++ b/demos/gtk-demo/meson.build
@@ -34,6 +34,7 @@ demos = files([
   'glarea.c',
   'headerbar.c',
   'hypertext.c',
+  'iconscroll.c',
   'iconview.c',
   'iconview_edit.c',
   'images.c',


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