diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-06-08 14:54:26 +0000 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-06-08 14:54:26 +0000 |
commit | 2e415e266fc410b00801071c01c215dc791283df (patch) | |
tree | d691f015543db4fd8a6199f2f43c8ee02c21bfb4 | |
parent | 37acfcfcd51ff42c9132db19d4878cec0625ad37 (diff) | |
parent | 915388cfdb23610e8128214cbb9a7e7248f72049 (diff) | |
download | gtk+-2e415e266fc410b00801071c01c215dc791283df.tar.gz |
Merge branch 'wip/carlosg/spin-button-swipe-gesture' into 'master'3828-fix-gtk-treeview-row_activated-signature
spinbutton: Connect swipe gesture to the text entry
Closes #4008
See merge request GNOME/gtk!3649
-rw-r--r-- | gtk/gtkspinbutton.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c index f54b8a7eb6..4e70bc56d7 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 @@ -1075,7 +1079,8 @@ gtk_spin_button_init (GtkSpinButton *spin_button) G_CALLBACK (swipe_gesture_begin), spin_button); g_signal_connect (gesture, "update", G_CALLBACK (swipe_gesture_update), spin_button); - gtk_widget_add_controller (GTK_WIDGET (spin_button), GTK_EVENT_CONTROLLER (gesture)); + gtk_widget_add_controller (GTK_WIDGET (spin_button->entry), + GTK_EVENT_CONTROLLER (gesture)); controller = gtk_event_controller_scroll_new (GTK_EVENT_CONTROLLER_SCROLL_VERTICAL | GTK_EVENT_CONTROLLER_SCROLL_DISCRETE); |