summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Boles <dboles.src@gmail.com>2018-07-04 20:18:04 +0100
committerDaniel Boles <dboles.src@gmail.com>2018-07-04 20:20:30 +0100
commit65ab1bad5d076fafc4e0a17e266f281cd420b405 (patch)
treea8ed7563923ccc2665ac874c6bc9caf774dce779
parent927004178f17ffabac42c75009c5ea0d8c601527 (diff)
downloadgtk+-dboles/switch-slider-active-state-gtk3.tar.gz
Switch: Implement :active state on slider subnodedboles/switch-slider-active-state-gtk3
https://gitlab.gnome.org/GNOME/gtk/issues/1201
-rw-r--r--gtk/gtkswitch.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/gtk/gtkswitch.c b/gtk/gtkswitch.c
index 15f11a4649..83c5b45c68 100644
--- a/gtk/gtkswitch.c
+++ b/gtk/gtkswitch.c
@@ -196,6 +196,21 @@ gtk_switch_begin_toggle_animation (GtkSwitch *sw)
}
static void
+gtk_switch_set_slider_state_active (GtkSwitch *sw,
+ gboolean active)
+{
+ GtkSwitchPrivate *priv = sw->priv;
+ GtkStateFlags state = gtk_widget_get_state_flags (GTK_WIDGET (sw));
+
+ if (active)
+ state |= GTK_STATE_FLAG_ACTIVE;
+ else
+ state &= ~GTK_STATE_FLAG_ACTIVE;
+
+ gtk_css_gadget_set_state (priv->slider_gadget, state);
+}
+
+static void
gtk_switch_multipress_gesture_pressed (GtkGestureMultiPress *gesture,
gint n_press,
gdouble x,
@@ -214,6 +229,8 @@ gtk_switch_multipress_gesture_pressed (GtkGestureMultiPress *gesture,
if ((priv->is_active && x <= allocation.width / 2.0) ||
(!priv->is_active && x > allocation.width / 2.0))
gtk_gesture_set_state (priv->pan_gesture, GTK_EVENT_SEQUENCE_DENIED);
+ else
+ gtk_switch_set_slider_state_active (sw, TRUE);
}
static void
@@ -226,6 +243,7 @@ gtk_switch_multipress_gesture_released (GtkGestureMultiPress *gesture,
GtkSwitchPrivate *priv = sw->priv;
GdkEventSequence *sequence;
+ gtk_switch_set_slider_state_active (sw, FALSE);
sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
if (priv->in_switch &&
@@ -258,6 +276,7 @@ gtk_switch_pan_gesture_pan (GtkGesturePan *gesture,
priv->handle_pos = CLAMP (offset, 0, 1.0);
/* we need to redraw the handle */
+ gtk_switch_set_slider_state_active (sw, TRUE);
gtk_widget_queue_allocate (widget);
}
@@ -289,6 +308,7 @@ gtk_switch_pan_gesture_drag_end (GtkGestureDrag *gesture,
return;
priv->handle_pos = active ? 1.0 : 0.0;
+ gtk_switch_set_slider_state_active (sw, FALSE);
gtk_switch_set_active (sw, active);
gtk_widget_queue_allocate (GTK_WIDGET (sw));
}