[gtk/wip/exalm/overshoot-changes: 83/83] scrolledwindow: Cancel overshoot on dimension changes




commit 1f580e4a74d9d198b65384230ee57c234e429b4e
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Mon Mar 15 17:17:01 2021 +0500

    scrolledwindow: Cancel overshoot on dimension changes
    
    If we scroll down in a list that's still being filled, we hit the edge and
    initiate overshoot, and then the adjustment's upper value increases. This
    leads to an unwanted bounce back.
    
    Additionally, if in a similar situation the upper value decreases, the
    overscroll glow gets stuck.
    
    Update kinetic scrolling upper and lower value on changes, and immediately
    cancel it if dimensions on that side change.
    
    Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/3752

 gtk/gtkkineticscrolling.c        | 26 ++++++++++++++++++++++++++
 gtk/gtkkineticscrollingprivate.h |  4 ++++
 gtk/gtkscrolledwindow.c          | 31 +++++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+)
---
diff --git a/gtk/gtkkineticscrolling.c b/gtk/gtkkineticscrolling.c
index eb9c13bdfd..0358c8f8ac 100644
--- a/gtk/gtkkineticscrolling.c
+++ b/gtk/gtkkineticscrolling.c
@@ -123,6 +123,32 @@ gtk_kinetic_scrolling_new (double lower,
   return data;
 }
 
+gboolean
+gtk_kinetic_scrolling_update_size (GtkKineticScrolling *data,
+                                   double               lower,
+                                   double               upper)
+{
+  if (lower != data->lower)
+    {
+      if (data->phase == GTK_KINETIC_SCROLLING_PHASE_OVERSHOOTING &&
+          data->position <= lower)
+        return FALSE;
+
+      data->lower = lower;
+    }
+
+  if (upper != data->upper)
+    {
+      if (data->phase == GTK_KINETIC_SCROLLING_PHASE_OVERSHOOTING &&
+          data->position >= data->upper)
+        return FALSE;
+
+      data->upper = upper;
+    }
+
+  return TRUE;
+}
+
 void
 gtk_kinetic_scrolling_free (GtkKineticScrolling *kinetic)
 {
diff --git a/gtk/gtkkineticscrollingprivate.h b/gtk/gtkkineticscrollingprivate.h
index b97fac360f..3a3b9a775c 100644
--- a/gtk/gtkkineticscrollingprivate.h
+++ b/gtk/gtkkineticscrollingprivate.h
@@ -34,6 +34,10 @@ GtkKineticScrolling *    gtk_kinetic_scrolling_new  (double                lower
                                                      double                initial_velocity);
 void                     gtk_kinetic_scrolling_free (GtkKineticScrolling  *kinetic);
 
+gboolean                 gtk_kinetic_scrolling_update_size (GtkKineticScrolling *data,
+                                                            double               lower,
+                                                            double               upper);
+
 gboolean                 gtk_kinetic_scrolling_tick (GtkKineticScrolling  *data,
                                                      double                time_delta,
                                                      double               *position,
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index a56891b5e2..2c6ffe9633 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -3455,6 +3455,20 @@ gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
 
           if (priv->hscrollbar_visible != visible)
             gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
+
+          if (priv->hscrolling)
+            {
+              double lower = gtk_adjustment_get_lower (adjustment);
+              double upper = gtk_adjustment_get_upper (adjustment);
+              upper -= gtk_adjustment_get_page_size (adjustment);
+
+              if (!gtk_kinetic_scrolling_update_size (priv->hscrolling, lower, upper))
+                {
+                  g_clear_pointer (&priv->hscrolling, gtk_kinetic_scrolling_free);
+                  priv->unclamped_hadj_value = gtk_adjustment_get_value (adjustment);
+                  gtk_scrolled_window_invalidate_overshoot (scrolled_window);
+                }
+            }
         }
     }
   else if (adjustment == gtk_scrollbar_get_adjustment (GTK_SCROLLBAR (priv->vscrollbar)))
@@ -3468,8 +3482,25 @@ gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
 
           if (priv->vscrollbar_visible != visible)
             gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
+
+          if (priv->vscrolling)
+            {
+              double lower = gtk_adjustment_get_lower (adjustment);
+              double upper = gtk_adjustment_get_upper (adjustment);
+              upper -= gtk_adjustment_get_page_size (adjustment);
+
+              if (!gtk_kinetic_scrolling_update_size (priv->vscrolling, lower, upper))
+                {
+                  g_clear_pointer (&priv->vscrolling, gtk_kinetic_scrolling_free);
+                  priv->unclamped_vadj_value = gtk_adjustment_get_value (adjustment);
+                  gtk_scrolled_window_invalidate_overshoot (scrolled_window);
+                }
+            }
         }
     }
+
+  if (!priv->hscrolling && !priv->vscrolling)
+    gtk_scrolled_window_cancel_deceleration (scrolled_window);
 }
 
 static void


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