diff options
author | Matthias Clasen <mclasen@redhat.com> | 2014-08-04 14:30:23 +0200 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2014-08-04 14:36:42 +0200 |
commit | 2e85046b8f96f4f751d6afa13ab220b4dab5c7f6 (patch) | |
tree | f02a0d5246dd52857917b69b30ff7ad6cc52e3a4 /gtk/gtkswitch.c | |
parent | d4bd9e9c46bc1230ea697efe887b1d77f66ba535 (diff) | |
download | gtk+-2e85046b8f96f4f751d6afa13ab220b4dab5c7f6.tar.gz |
GtkSwitch: Don't store dest_offset
Instead, calculate it on the spot in the tick callback, and
update handle_x in gtk_switch_set_active, based on the new
active property.
Diffstat (limited to 'gtk/gtkswitch.c')
-rw-r--r-- | gtk/gtkswitch.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/gtk/gtkswitch.c b/gtk/gtkswitch.c index e9837372b4..b1758061d0 100644 --- a/gtk/gtkswitch.c +++ b/gtk/gtkswitch.c @@ -68,7 +68,6 @@ struct _GtkSwitchPrivate gint handle_x; gint offset; - gint dest_offset; gint drag_start; gint drag_threshold; gint64 start_time; @@ -153,15 +152,20 @@ gtk_switch_on_frame_clock_update (GdkFrameClock *clock, if (now < priv->end_time) { gdouble t; + gint dest_offset; + + if (priv->is_active) + dest_offset = 0; + else + dest_offset = gtk_widget_get_allocated_width (GTK_WIDGET (sw)) / 2; t = (now - priv->start_time) / (gdouble) (priv->end_time - priv->start_time); t = ease_out_cubic (t); - priv->handle_x = priv->offset + t * (priv->dest_offset - priv->offset); + priv->handle_x = priv->offset + t * (dest_offset - priv->offset); } else { gtk_switch_set_active (sw, !priv->is_active); - priv->handle_x = priv->dest_offset; } gtk_widget_queue_draw (GTK_WIDGET (sw)); @@ -173,15 +177,8 @@ static void gtk_switch_begin_toggle_animation (GtkSwitch *sw) { GtkSwitchPrivate *priv = sw->priv; - GtkAllocation allocation; gboolean animate; - gtk_widget_get_allocation (GTK_WIDGET (sw), &allocation); - if (priv->is_active) - priv->dest_offset = 0; - else - priv->dest_offset = allocation.width / 2; - g_object_get (gtk_widget_get_settings (GTK_WIDGET (sw)), "gtk-enable-animations", &animate, NULL); @@ -201,7 +198,6 @@ gtk_switch_begin_toggle_animation (GtkSwitch *sw) else { gtk_switch_set_active (sw, !priv->is_active); - priv->handle_x = priv->dest_offset; } } @@ -1096,6 +1092,11 @@ gtk_switch_set_active (GtkSwitch *sw, priv->is_active = is_active; + if (priv->is_active) + priv->handle_x = gtk_widget_get_allocated_width (GTK_WIDGET (sw)) / 2; + else + priv->handle_x = 0; + g_object_notify_by_pspec (G_OBJECT (sw), switch_props[PROP_ACTIVE]); g_signal_emit (sw, signals[STATE_SET], 0, is_active, &handled); |