GtkRevealer: Add a fading animation

Using a container for this is not necessarily the most
elegant solution, but it lets us reuse the animation
machinery in GtkRevealer.
This commit is contained in:
Matthias Clasen 2013-04-22 09:42:48 -04:00
parent 0bd173e3d8
commit d7f43c30a3
3 changed files with 12 additions and 6 deletions

View File

@ -439,7 +439,15 @@ gtk_revealer_set_position (GtkRevealer *revealer,
new_visible != gtk_widget_get_child_visible (child))
gtk_widget_set_child_visible (child, new_visible);
gtk_widget_queue_resize (GTK_WIDGET (revealer));
if (priv->transition_type == GTK_REVEALER_TRANSITION_TYPE_CROSSFADE)
{
gtk_widget_set_opacity (GTK_WIDGET (revealer), priv->current_pos);
gtk_widget_queue_draw (GTK_WIDGET (revealer));
}
else
{
gtk_widget_queue_resize (GTK_WIDGET (revealer));
}
if (priv->current_pos == priv->target_pos)
g_object_notify (G_OBJECT (revealer), "child-revealed");
@ -480,7 +488,6 @@ gtk_revealer_animate_cb (GtkRevealer *revealer,
gtk_revealer_animate_step (revealer, now);
if (priv->current_pos == priv->target_pos)
{
gtk_widget_set_opacity (GTK_WIDGET (revealer), 1.0);
priv->tick_id = 0;
return FALSE;
}
@ -505,8 +512,6 @@ gtk_revealer_start_animation (GtkRevealer *revealer,
priv->transition_duration != 0 &&
priv->transition_type != GTK_REVEALER_TRANSITION_TYPE_NONE)
{
gtk_widget_set_opacity (widget, 0.999);
priv->source_pos = priv->current_pos;
priv->start_time = gdk_frame_clock_get_frame_time (gtk_widget_get_frame_clock (widget));
priv->end_time = priv->start_time + (priv->transition_duration * 1000);

View File

@ -40,6 +40,7 @@ typedef struct _GtkRevealerPrivate GtkRevealerPrivate;
typedef enum {
GTK_REVEALER_TRANSITION_TYPE_NONE,
GTK_REVEALER_TRANSITION_TYPE_CROSSFADE,
GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT,
GTK_REVEALER_TRANSITION_TYPE_SLIDE_LEFT,
GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP,

View File

@ -41,7 +41,7 @@ main (gint argc,
gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), 2000);
gtk_grid_attach (GTK_GRID (box), revealer, 1, 0, 1, 1);
widget = gtk_toggle_button_new_with_label ("None");
widget = gtk_toggle_button_new_with_label ("Fade");
gtk_grid_attach (GTK_GRID (box), widget, 4, 4, 1, 1);
revealer = gtk_revealer_new ();
gtk_widget_set_halign (revealer, GTK_ALIGN_END);
@ -50,7 +50,7 @@ main (gint argc,
gtk_entry_set_text (GTK_ENTRY (entry), "00000");
gtk_container_add (GTK_CONTAINER (revealer), entry);
g_object_bind_property (widget, "active", revealer, "reveal-child", 0);
gtk_revealer_set_transition_type (GTK_REVEALER (revealer), GTK_REVEALER_TRANSITION_TYPE_NONE);
gtk_revealer_set_transition_type (GTK_REVEALER (revealer), GTK_REVEALER_TRANSITION_TYPE_CROSSFADE);
gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), 2000);
gtk_grid_attach (GTK_GRID (box), revealer, 3, 4, 1, 1);