[gtk/matthiasc/for-master: 16/16] gtk-demo: Improve the scrolling demo
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/for-master: 16/16] gtk-demo: Improve the scrolling demo
- Date: Mon, 14 Sep 2020 03:45:02 +0000 (UTC)
commit 9f03462ffb8718d550e057d0654fac5f99a8c995
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Sep 13 23:25:05 2020 -0400
gtk-demo: Improve the scrolling demo
Add an fps label to the scrolling demo.
demos/gtk-demo/iconscroll.c | 31 +++++++++++++++++++++++++++++++
demos/gtk-demo/iconscroll.ui | 7 +++++++
2 files changed, 38 insertions(+)
---
diff --git a/demos/gtk-demo/iconscroll.c b/demos/gtk-demo/iconscroll.c
index 3c05e2755d..d7a6c1b5e3 100644
--- a/demos/gtk-demo/iconscroll.c
+++ b/demos/gtk-demo/iconscroll.c
@@ -256,12 +256,38 @@ iconscroll_prev_clicked_cb (GtkButton *source,
set_widget_type (new_index);
}
+static gboolean
+update_fps (gpointer data)
+{
+ GtkWidget *label = data;
+ GdkFrameClock *frame_clock;
+ double fps;
+ char *str;
+
+ frame_clock = gtk_widget_get_frame_clock (label);
+
+ fps = gdk_frame_clock_get_fps (frame_clock);
+ str = g_strdup_printf ("%.2f fps", fps);
+ gtk_label_set_label (GTK_LABEL (label), str);
+ g_free (str);
+
+ return G_SOURCE_CONTINUE;
+}
+
+static void
+remove_timeout (gpointer data)
+{
+ g_source_remove (GPOINTER_TO_UINT (data));
+}
+
G_MODULE_EXPORT GtkWidget *
do_iconscroll (GtkWidget *do_widget)
{
if (!window)
{
GtkBuilder *builder;
+ GtkWidget *label;
+ guint id;
builder = gtk_builder_new_from_resource ("/iconscroll/iconscroll.ui");
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
@@ -275,6 +301,11 @@ do_iconscroll (GtkWidget *do_widget)
vadjustment = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "vadjustment"));
set_widget_type (0);
+ label = GTK_WIDGET (gtk_builder_get_object (builder, "fps_label"));
+ id = g_timeout_add (500, update_fps, label);
+ g_object_set_data_full (G_OBJECT (label), "timeout",
+ GUINT_TO_POINTER (id), remove_timeout);
+
g_object_unref (builder);
}
diff --git a/demos/gtk-demo/iconscroll.ui b/demos/gtk-demo/iconscroll.ui
index 18e7317dff..95d2452747 100644
--- a/demos/gtk-demo/iconscroll.ui
+++ b/demos/gtk-demo/iconscroll.ui
@@ -25,6 +25,13 @@
</child>
</object>
</child>
+ <child type="end">
+ <object class="GtkLabel" id="fps_label">
+ <attributes>
+ <attribute name="font-features" value="tnum=1"/>
+ </attributes>
+ </object>
+ </child>
</object>
</child>
<child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]