diff options
author | Timm Bäder <mail@baedert.org> | 2017-06-17 13:16:50 +0200 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2017-07-19 21:27:14 -0400 |
commit | 63158fd3ff8b512c82e29eb55feea8a16c2e8f3a (patch) | |
tree | 1c09de44c1249f72b6f8c68a69b8f8a8f7494e0b /gtk/gtkswitch.c | |
parent | a73d3418bc4253725e0889705c4a60e9051b0bc5 (diff) | |
download | gtk+-63158fd3ff8b512c82e29eb55feea8a16c2e8f3a.tar.gz |
switch: Fix handle dragging with padding applied
We only move the handle inside the content allocation, so we need to use
the content width when calculating the new handle_pos.
Diffstat (limited to 'gtk/gtkswitch.c')
-rw-r--r-- | gtk/gtkswitch.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/gtk/gtkswitch.c b/gtk/gtkswitch.c index 900b40e009..de8b4c6be6 100644 --- a/gtk/gtkswitch.c +++ b/gtk/gtkswitch.c @@ -191,7 +191,7 @@ gtk_switch_multipress_gesture_pressed (GtkGestureMultiPress *gesture, GtkSwitchPrivate *priv = sw->priv; GtkAllocation allocation; - gtk_widget_get_allocation (GTK_WIDGET (sw), &allocation); + gtk_widget_get_outer_allocation (GTK_WIDGET (sw), &allocation); gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED); /* If the press didn't happen in the draggable handle, @@ -228,13 +228,14 @@ gtk_switch_pan_gesture_pan (GtkGesturePan *gesture, GtkWidget *widget = GTK_WIDGET (sw); GtkSwitchPrivate *priv = sw->priv; gint width; + int height; if (direction == GTK_PAN_DIRECTION_LEFT) offset = -offset; gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED); - width = gtk_widget_get_allocated_width (widget); + gtk_widget_get_content_size (widget, &width, &height); if (priv->is_active) offset += width / 2; @@ -354,8 +355,8 @@ gtk_switch_size_allocate (GtkWidget *widget, GtkAllocation slider_alloc; int min; - slider_alloc.x = allocation->x + round (priv->handle_pos * (allocation->width - allocation->width / 2)); - slider_alloc.y = allocation->y; + slider_alloc.x = round (priv->handle_pos * (allocation->width / 2)); + slider_alloc.y = 0; slider_alloc.width = allocation->width / 2; slider_alloc.height = allocation->height; @@ -366,10 +367,10 @@ gtk_switch_size_allocate (GtkWidget *widget, /* Center ON label in left half */ gtk_widget_measure (priv->on_label, GTK_ORIENTATION_HORIZONTAL, -1, &min, NULL, NULL, NULL); - child_alloc.x = allocation->x + ((allocation->width / 2) - min) / 2; + child_alloc.x = ((allocation->width / 2) - min) / 2; child_alloc.width = min; gtk_widget_measure (priv->on_label, GTK_ORIENTATION_VERTICAL, min, &min, NULL, NULL, NULL); - child_alloc.y = allocation->y + (allocation->height - min) / 2; + child_alloc.y = (allocation->height - min) / 2; child_alloc.height = min; gtk_widget_size_allocate (priv->on_label, &child_alloc); gtk_widget_get_clip (priv->on_label, &child_clip); @@ -377,10 +378,10 @@ gtk_switch_size_allocate (GtkWidget *widget, /* Center OFF label in right half */ gtk_widget_measure (priv->off_label, GTK_ORIENTATION_HORIZONTAL, -1, &min, NULL, NULL, NULL); - child_alloc.x = allocation->x + (allocation->width / 2) + ((allocation->width / 2) - min) / 2; + child_alloc.x = (allocation->width / 2) + ((allocation->width / 2) - min) / 2; child_alloc.width = min; gtk_widget_measure (priv->off_label, GTK_ORIENTATION_VERTICAL, min, &min, NULL, NULL, NULL); - child_alloc.y = allocation->y + (allocation->height - min) / 2; + child_alloc.y = (allocation->height - min) / 2; child_alloc.height = min; gtk_widget_size_allocate (priv->off_label, &child_alloc); gtk_widget_get_clip (priv->off_label, &child_clip); |