[gtk+] GtkSwitch: Don't store dest_offset
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] GtkSwitch: Don't store dest_offset
- Date: Mon, 4 Aug 2014 12:37:14 +0000 (UTC)
commit 2e85046b8f96f4f751d6afa13ab220b4dab5c7f6
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Aug 4 14:30:23 2014 +0200
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.
gtk/gtkswitch.c | 23 ++++++++++++-----------
1 files changed, 12 insertions(+), 11 deletions(-)
---
diff --git a/gtk/gtkswitch.c b/gtk/gtkswitch.c
index e983737..b175806 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]