summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Boles <dboles@src.gnome.org>2018-04-17 21:44:16 +0100
committerDaniel Boles <dboles.src@gmail.com>2018-04-17 21:44:16 +0100
commit9b011081c53b59241a6aa6bf95c3ac50ae4286f0 (patch)
tree5bade3e2e65a10bc194c5064ba4fc0207b72c10b
parent0c46d94ec3f93c2b43bc8629d7c064d6c9732ac7 (diff)
downloadgtk+-9b011081c53b59241a6aa6bf95c3ac50ae4286f0.tar.gz
Range: Add should_invert_move() for scrolls & keys
This will be used in subsequent commits to fix the sign by which the value is changed in response to directional scroll or keypress events. The idea is: you have a movement to make – in the form of a delta that follows widget directions, i.e. −1 means left or up, +1 means right or down – and you want to know whether that delta needs to be inverted in order to produce the intuitively expected directional change of :value. The existing should_invert() is not sufficient: it just determines whether to invert visually, but we need more nuance than that for input. To answer that – while not doubling up the work for scrolls and keys – I add a helper should_invert_move(), which considers other relevant state: • A parallel movement on priv->orientation should just use the existing should_invert(), which already worked OK for this case (not others). • Movements on the other orientation now depend on priv->orientation: ◦ For a horizontal Range, always invert, so up (i.e. −ve in terms of widget coords) always means increase value & vice-versa. This was done in get_wheel_delta(), but move it here for use with keys too. ◦ For a vertical Range, ignore :invert as it’s only relevant to the parallel orientation. Do not care about text direction here either as RTL locales do not invert number lines, Cartesian plots, etc. This returns TRUE if the delta should be inverted before applying to the value, and we can now use this function in both scroll and key handlers. https://bugzilla.gnome.org/show_bug.cgi?id=407242 https://bugzilla.gnome.org/show_bug.cgi?id=791802
-rw-r--r--gtk/gtkrange.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c
index cadece27ed..bca07b19b2 100644
--- a/gtk/gtkrange.c
+++ b/gtk/gtkrange.c
@@ -949,6 +949,24 @@ should_invert (GtkRange *range)
return priv->inverted;
}
+static gboolean
+should_invert_move (GtkRange *range,
+ GtkOrientation move_orientation)
+{
+ GtkRangePrivate *priv = range->priv;
+
+ /* If the move is parallel to the range, use general check for inversion */
+ if (move_orientation == priv->orientation)
+ return should_invert (range);
+
+ /* H range/V move: Always invert, so down/up always dec/increase the value */
+ if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+ return TRUE;
+
+ /* V range/H move: Left/right always dec/increase the value */
+ return FALSE;
+}
+
static void
update_highlight_position (GtkRange *range)
{