[gimp] app: improve GimpSpinScale usability for keyboard editing of value.



commit 976b5189991ce4b9f661a7903bbde602ebef85c1
Author: Jehan <jehan girinstud io>
Date:   Wed Dec 16 14:56:29 2020 +0100

    app: improve GimpSpinScale usability for keyboard editing of value.
    
    Currently to edit the value with the keyboard (i.e. get a focus on the
    text entry part of the widget), we can click on the scale which gives us
    edit focus, but it implies to change the value (which may not be
    wanted).
    
    An interaction method exists to do just this, which is the secondary
    button (middle click). Unfortunately, though powerful, it is totally
    "hidden feature". People expects to be able to click on the numbers they
    see and start typing.
    This change allows just this. Now when clicking on the number part, it
    selects the whole text input contents (same as with middle-click ever
    since commit 3449652fe8), without changing the value. You just enter in
    text input mode.
    To properly advertize the behavior change, the cursor will also change
    when hovering, showing a text cursor over the existing number text.
    
    As many of my changes, this change was designed together with Aryeom and
    triggered originally by her usability feedbacks and inputs.

 app/widgets/gimpspinscale.c | 66 ++++++++++++++++++++++++++-------------------
 1 file changed, 38 insertions(+), 28 deletions(-)
---
diff --git a/app/widgets/gimpspinscale.c b/app/widgets/gimpspinscale.c
index 94a32c6fab..8ab166121f 100644
--- a/app/widgets/gimpspinscale.c
+++ b/app/widgets/gimpspinscale.c
@@ -551,10 +551,10 @@ gimp_spin_scale_event_to_widget_coords (GtkWidget *widget,
 }
 
 static SpinScaleTarget
-gimp_spin_scale_get_target (GtkWidget      *widget,
-                            gdouble         x,
-                            gdouble         y,
-                            GdkEventButton *event)
+gimp_spin_scale_get_target (GtkWidget *widget,
+                            gdouble    x,
+                            gdouble    y,
+                            GdkEvent  *event)
 {
   GdkRectangle text_area;
 
@@ -577,28 +577,38 @@ gimp_spin_scale_get_target (GtkWidget      *widget,
       layout_x -= text_area.x;
       layout_y -= text_area.y;
 
-      if (x >= layout_x && x < layout_x + logical.width  &&
-          y >= layout_y && y < layout_y + logical.height &&
-          gtk_widget_has_focus (widget)                  &&
-          gdk_event_triggers_context_menu ((GdkEvent *) event))
+      if (event->type != GDK_MOTION_NOTIFY)
         {
-          return TARGET_NUMBER;
-        }
+          GdkEventButton *event_button = (GdkEventButton *) event;
 
-      switch (event->button)
-        {
-        case 1:
-          if (event->state & GDK_SHIFT_MASK)
-            return TARGET_LOWER;
-          else
-            return TARGET_UPPER;
+          switch (event_button->button)
+            {
+            case 1:
+              if (event_button->state & GDK_SHIFT_MASK)
+                return TARGET_LOWER;
+              else
+                break;
 
-        case 3:
-          return TARGET_LOWER;
+            case 3:
+              return TARGET_LOWER;
 
-        default:
+            default:
+              return TARGET_NUMBER;
+            }
+        }
+
+      /* For motion events or main button clicks, the target depends on
+       * the position.
+       */
+      if (x >= layout_x && x < layout_x + logical.width  &&
+          y >= layout_y && y < layout_y + logical.height)
+        {
           return TARGET_NUMBER;
         }
+      else
+        {
+          return TARGET_UPPER;
+        }
     }
 
   return TARGET_NONE;
@@ -636,16 +646,16 @@ gimp_spin_scale_update_cursor (GtkWidget *widget,
 }
 
 static void
-gimp_spin_scale_update_target (GtkWidget      *widget,
-                               GdkWindow      *window,
-                               gdouble         x,
-                               gdouble         y,
-                               GdkEventButton *event)
+gimp_spin_scale_update_target (GtkWidget *widget,
+                               GdkWindow *window,
+                               gdouble    x,
+                               gdouble    y,
+                               GdkEvent  *event)
 {
   GimpSpinScalePrivate *private = GET_PRIVATE (widget);
   SpinScaleTarget       target;
 
-  target = gimp_spin_scale_get_target (widget, x, y, event);
+  target = gimp_spin_scale_get_target (widget, x, y, (GdkEvent *) event);
 
   if (target != private->target)
     {
@@ -787,7 +797,7 @@ gimp_spin_scale_button_press (GtkWidget      *widget,
                                           event->x, event->y,
                                           &x, &y);
 
-  gimp_spin_scale_update_target (widget, event->window, x, y, event);
+  gimp_spin_scale_update_target (widget, event->window, x, y, (GdkEvent *) event);
 
   switch (private->target)
     {
@@ -1008,7 +1018,7 @@ gimp_spin_scale_motion_notify (GtkWidget      *widget,
       private->hover)
     {
       gimp_spin_scale_update_target (widget, event->window,
-                                     x, y, NULL);
+                                     x, y, (GdkEvent *) event);
     }
 
   return FALSE;


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