mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-13 22:10:08 +00:00
gtk-demo: Improve the scrolling demo
Add an fps label to the scrolling demo.
This commit is contained in:
parent
3b11896581
commit
9f03462ffb
@ -256,12 +256,38 @@ iconscroll_prev_clicked_cb (GtkButton *source,
|
|||||||
set_widget_type (new_index);
|
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 *
|
G_MODULE_EXPORT GtkWidget *
|
||||||
do_iconscroll (GtkWidget *do_widget)
|
do_iconscroll (GtkWidget *do_widget)
|
||||||
{
|
{
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
GtkBuilder *builder;
|
GtkBuilder *builder;
|
||||||
|
GtkWidget *label;
|
||||||
|
guint id;
|
||||||
|
|
||||||
builder = gtk_builder_new_from_resource ("/iconscroll/iconscroll.ui");
|
builder = gtk_builder_new_from_resource ("/iconscroll/iconscroll.ui");
|
||||||
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
|
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"));
|
vadjustment = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "vadjustment"));
|
||||||
set_widget_type (0);
|
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);
|
g_object_unref (builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,13 @@
|
|||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
<child type="end">
|
||||||
|
<object class="GtkLabel" id="fps_label">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="font-features" value="tnum=1"/>
|
||||||
|
</attributes>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
|
Loading…
Reference in New Issue
Block a user