[gtk/wip/carlosg/spin-button-swipe-gesture-4-2: 2/2] spinbutton: Mind the step in the swipe gesture
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/carlosg/spin-button-swipe-gesture-4-2: 2/2] spinbutton: Mind the step in the swipe gesture
- Date: Tue, 8 Jun 2021 16:41:50 +0000 (UTC)
commit 6df3296211586c179a8f85f89dcee314d6ab3b9a
Author: Carlos Garnacho <carlosg gnome org>
Date: Tue Jun 8 15:09:37 2021 +0200
spinbutton: Mind the step in the swipe gesture
The swipe gesture forces values in the spin button that are
"impossible" according to the adjustment. This can break things
in creative ways.
Ensure the steps provided are always multiples of the adjustment
step value, and keep the remainder for further interaction.
gtk/gtkspinbutton.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c
index ba7a3d5fa9..7f59b741b0 100644
--- a/gtk/gtkspinbutton.c
+++ b/gtk/gtkspinbutton.c
@@ -208,6 +208,7 @@ struct _GtkSpinButton
double climb_rate;
double timer_step;
+ double swipe_remainder;
int width_chars;
@@ -838,6 +839,7 @@ swipe_gesture_begin (GtkGesture *gesture,
{
gtk_gesture_set_state (gesture, GTK_EVENT_SEQUENCE_CLAIMED);
gtk_widget_grab_focus (GTK_WIDGET (spin_button));
+ spin_button->swipe_remainder = 0;
}
static void
@@ -845,10 +847,12 @@ swipe_gesture_update (GtkGesture *gesture,
GdkEventSequence *sequence,
GtkSpinButton *spin_button)
{
- double vel_y;
+ double vel_y, step;
gtk_gesture_swipe_get_velocity (GTK_GESTURE_SWIPE (gesture), NULL, &vel_y);
- gtk_spin_button_real_spin (spin_button, -vel_y / 20);
+ step = (-vel_y / 20) + spin_button->swipe_remainder;
+ spin_button->swipe_remainder = fmod (step, gtk_adjustment_get_step_increment (spin_button->adjustment));
+ gtk_spin_button_real_spin (spin_button, step - spin_button->swipe_remainder);
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]