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 @@ gtkfishbowl.c gtkfishbowl.h + + iconscroll.ui + gnome-fs-directory.png gnome-fs-regular.png @@ -179,6 +182,7 @@ glarea.c headerbar.c hypertext.c + iconscroll.c iconview.c iconview_edit.c images.c 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 + +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 @@ + + + + 0 + 500 + 500 + Scrolling icons + + + never + automatic + + + + center + 10 + 10 + vertical + + + + + + 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',