[gtk+/wip/baedert/drawing: 274/396] switch: Fix handle dragging with padding applied



commit a7b712ce7bf05b01703e4dc8b8412f96922b5652
Author: Timm Bäder <mail baedert org>
Date:   Sat Jun 17 13:16:50 2017 +0200

    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.

 gtk/gtkswitch.c |   17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)
---
diff --git a/gtk/gtkswitch.c b/gtk/gtkswitch.c
index 900b40e..de8b4c6 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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]