gtk/demos/gtk-demo/revealer.c
Benjamin Otte 27d05102ab builder: Remove user_data argument from gtk_builder_connect_signals()
This is pretty unused and gets in the way of the next steps.

A potential side effect is that for templates the widget was passed as
the user data argument. If that turns out to be important, we have to
special case that situation.
2019-11-22 07:46:18 +01:00

95 lines
2.0 KiB
C

/* Revealer
*
* GtkRevealer is a container that animates showing and hiding
* of its sole child with nice transitions.
*/
#include <gtk/gtk.h>
static gint count = 0;
static guint timeout = 0;
static void
change_direction (GtkRevealer *revealer)
{
if (gtk_widget_get_mapped (GTK_WIDGET (revealer)))
{
gboolean revealed;
revealed = gtk_revealer_get_child_revealed (revealer);
gtk_revealer_set_reveal_child (revealer, !revealed);
}
}
static gboolean
reveal_one (gpointer data)
{
GtkWidget *window = data;
GtkBuilder *builder;
gchar *name;
GtkRevealer *revealer;
builder = GTK_BUILDER (g_object_get_data (G_OBJECT (window), "builder"));
name = g_strdup_printf ("revealer%d", count);
revealer = (GtkRevealer *)gtk_builder_get_object (builder, name);
gtk_revealer_set_reveal_child (revealer, TRUE);
g_signal_connect (revealer, "notify::child-revealed",
G_CALLBACK (change_direction), NULL);
count++;
if (count >= 9)
{
timeout = 0;
return FALSE;
}
else
return TRUE;
}
static GtkWidget *window = NULL;
static void
on_destroy (gpointer data)
{
window = NULL;
if (timeout != 0)
{
g_source_remove (timeout);
timeout = 0;
}
}
GtkWidget *
do_revealer (GtkWidget *do_widget)
{
if (!window)
{
GtkBuilder *builder;
builder = gtk_builder_new_from_resource ("/revealer/revealer.ui");
gtk_builder_connect_signals (builder);
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
g_signal_connect (window, "destroy",
G_CALLBACK (on_destroy), NULL);
g_object_set_data_full (G_OBJECT (window), "builder", builder, g_object_unref);
}
if (!gtk_widget_get_visible (window))
{
count = 0;
timeout = g_timeout_add (690, reveal_one, window);
gtk_widget_show (window);
}
else
{
gtk_widget_destroy (window);
}
return window;
}