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.
This commit is contained in:
Jehan 2020-12-16 14:56:29 +01:00
parent a30cbb22d9
commit 976b518999
1 changed files with 38 additions and 28 deletions

View File

@ -554,7 +554,7 @@ static SpinScaleTarget
gimp_spin_scale_get_target (GtkWidget *widget, gimp_spin_scale_get_target (GtkWidget *widget,
gdouble x, gdouble x,
gdouble y, gdouble y,
GdkEventButton *event) GdkEvent *event)
{ {
GdkRectangle text_area; GdkRectangle text_area;
@ -577,21 +577,17 @@ gimp_spin_scale_get_target (GtkWidget *widget,
layout_x -= text_area.x; layout_x -= text_area.x;
layout_y -= text_area.y; layout_y -= text_area.y;
if (x >= layout_x && x < layout_x + logical.width && if (event->type != GDK_MOTION_NOTIFY)
y >= layout_y && y < layout_y + logical.height &&
gtk_widget_has_focus (widget) &&
gdk_event_triggers_context_menu ((GdkEvent *) event))
{ {
return TARGET_NUMBER; GdkEventButton *event_button = (GdkEventButton *) event;
}
switch (event->button) switch (event_button->button)
{ {
case 1: case 1:
if (event->state & GDK_SHIFT_MASK) if (event_button->state & GDK_SHIFT_MASK)
return TARGET_LOWER; return TARGET_LOWER;
else else
return TARGET_UPPER; break;
case 3: case 3:
return TARGET_LOWER; return TARGET_LOWER;
@ -601,6 +597,20 @@ gimp_spin_scale_get_target (GtkWidget *widget,
} }
} }
/* 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; return TARGET_NONE;
} }
@ -640,12 +650,12 @@ gimp_spin_scale_update_target (GtkWidget *widget,
GdkWindow *window, GdkWindow *window,
gdouble x, gdouble x,
gdouble y, gdouble y,
GdkEventButton *event) GdkEvent *event)
{ {
GimpSpinScalePrivate *private = GET_PRIVATE (widget); GimpSpinScalePrivate *private = GET_PRIVATE (widget);
SpinScaleTarget target; 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) if (target != private->target)
{ {
@ -787,7 +797,7 @@ gimp_spin_scale_button_press (GtkWidget *widget,
event->x, event->y, event->x, event->y,
&x, &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) switch (private->target)
{ {
@ -1008,7 +1018,7 @@ gimp_spin_scale_motion_notify (GtkWidget *widget,
private->hover) private->hover)
{ {
gimp_spin_scale_update_target (widget, event->window, gimp_spin_scale_update_target (widget, event->window,
x, y, NULL); x, y, (GdkEvent *) event);
} }
return FALSE; return FALSE;