[gnome-usage/pstetka/gnome-usage-disk-io: 7/7] graph-stack-switcher: Better change active button on scrolling



commit 46307f1b2998aefa705c4494e96296e7a498cb04
Author: Petr Štětka <stetka peta gmail com>
Date:   Tue Apr 9 14:24:40 2019 +0200

    graph-stack-switcher: Better change active button on scrolling
    
    With this commit GraphStackSwitcher will switch active button
    when subview will occupy more than half of displayed window.
    
    This too solve problem when is last subview smaller then half of
    window but window is scrolled to the end using bottom tolerance.
    
    This is much more intuitive for users and gives it a sense of user
    experience.

 src/graph-stack-switcher.vala | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)
---
diff --git a/src/graph-stack-switcher.vala b/src/graph-stack-switcher.vala
index a1fba7b..9a1e33b 100644
--- a/src/graph-stack-switcher.vala
+++ b/src/graph-stack-switcher.vala
@@ -26,6 +26,7 @@ namespace Usage
         AnimatedScrolledWindow scrolled_window;
 
         GraphSwitcherButton[] buttons;
+        private const int BOTTOM_TOLERANCE = 150;
 
         class construct
         {
@@ -83,17 +84,29 @@ namespace Usage
 
         private void on_scroll_changed(double y)
         {
-            Gtk.Allocation alloc;
-
             var button_number = 0;
-            for(int i = 1; i < buttons.length; i++)
-            {
-                this.sub_views[i].get_allocation(out alloc);
-                if(y < alloc.y)
+            Gtk.Allocation container_alloc;
+            sub_views[0].parent.parent.get_allocation(out container_alloc);
+
+            for(int i = 0; i < sub_views.length; i++) {
+                Gtk.Allocation sub_view_alloc;
+                sub_views[i].get_allocation(out sub_view_alloc);
+
+                if(y + container_alloc.height / 2 < sub_view_alloc.y + sub_view_alloc.height) {
+                    button_number = i;
                     break;
-                button_number = i;
+                }
             }
 
+            var last_subview_number = sub_views.length - 1;
+            Gtk.Allocation last_subview_alloc;
+            sub_views[last_subview_number].get_allocation(out last_subview_alloc);
+
+            if(y < BOTTOM_TOLERANCE)
+                button_number = 0;
+            else if(y + container_alloc.height > last_subview_alloc.y + last_subview_alloc.height - 
BOTTOM_TOLERANCE)
+                button_number = last_subview_number;
+
             buttons[button_number].set_active(true);
         }
     }


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