[gtk/usable-scales: 2/3] range: Allow clicking on the margin of the trough



commit 35cedea2970f753e84c31a095207bca0354a0604
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed May 13 13:00:36 2020 -0400

    range: Allow clicking on the margin of the trough
    
    The narrow troughs we have now are very hard to hit.

 gtk/gtkrange.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c
index 95c728a4fe..9f879316bd 100644
--- a/gtk/gtkrange.c
+++ b/gtk/gtkrange.c
@@ -41,6 +41,7 @@
 #include "gtkscale.h"
 #include "gtktypebuiltins.h"
 #include "gtkeventcontrollerkey.h"
+#include "gtkcssboxesprivate.h"
 
 #include "a11y/gtkrangeaccessible.h"
 
@@ -235,6 +236,9 @@ static void          gtk_range_allocate_trough          (GtkGizmo            *gi
                                                          int                  baseline);
 static void          gtk_range_render_trough            (GtkGizmo     *gizmo,
                                                          GtkSnapshot  *snapshot);
+static gboolean      gtk_range_trough_contains          (GtkGizmo     *gizmo,
+                                                         double        x,
+                                                         double        y);
 
 static gboolean      gtk_range_scroll_controller_scroll (GtkEventControllerScroll *scroll,
                                                          gdouble                   dx,
@@ -548,7 +552,7 @@ gtk_range_init (GtkRange *range)
                                        gtk_range_measure_trough,
                                        gtk_range_allocate_trough,
                                        gtk_range_render_trough,
-                                       NULL,
+                                       gtk_range_trough_contains,
                                        NULL, NULL);
 
   gtk_widget_set_parent (priv->trough_widget, GTK_WIDGET (range));
@@ -1649,6 +1653,21 @@ gtk_range_render_trough (GtkGizmo    *gizmo,
   gtk_widget_snapshot_child (GTK_WIDGET (gizmo), priv->slider_widget, snapshot);
 }
 
+static gboolean
+gtk_range_trough_contains (GtkGizmo *trough,
+                           double    x,
+                           double    y)
+{
+  GtkCssBoxes boxes;
+  graphene_rect_t area;
+
+  gtk_css_boxes_init (&boxes, GTK_WIDGET (trough));
+
+  graphene_rect_init_from_rect (&area, gtk_css_boxes_get_margin_rect (&boxes));
+
+  return graphene_rect_contains_point (&area, &GRAPHENE_POINT_INIT (x, y));
+}
+
 static void
 range_grab_add (GtkRange  *range,
                 GtkWidget *location)


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