gtk-demo: Improve the scrolling demo

Add an fps label to the scrolling demo.
This commit is contained in:
Matthias Clasen 2020-09-13 23:25:05 -04:00
parent 3b11896581
commit 9f03462ffb
2 changed files with 38 additions and 0 deletions

View File

@ -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);
}

View File

@ -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>