[gnome-shell/wip/paging-release: 11/90] PaginationScrollView: take into account velocity on paning



commit 882924ea9ce4a090d938b7942563cb34a0fba878
Author: Carlos Soriano <carlos soriano89 gmail com>
Date:   Mon Aug 12 16:37:50 2013 +0200

    PaginationScrollView: take into account velocity on paning

 js/ui/appDisplay.js |   25 ++++++++++++++++++++++---
 1 files changed, 22 insertions(+), 3 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index d69d010..830e463 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -39,7 +39,7 @@ const MAX_APPS_PAGES = 20;
 //fraction of page height the finger or mouse must reach before
 //change page
 const PAGE_SWITCH_TRESHOLD = 0.2;
-const PAGE_SWITCH_TIME = 0.25;
+const PAGE_SWITCH_TIME = 0.3;
 
 // Recursively load a GMenuTreeDirectory; we could put this in ShellAppSystem too
 function _loadCategory(dir, list) {
@@ -316,12 +316,31 @@ const PaginationScrollView = new Lang.Class({
         child.allocate(childBox, flags);
     },
     
-    goToPage: function(pageNumber) {
+    goToPage: function(pageNumber, velocity) {
+        if(!velocity)
+            velocity = 0;
+        // Tween the change between pages.
+        // If velocity is not specified (i.e. scrolling with mouse wheel),
+        // use the same speed regardless of original position
+        // if velocity is specified, it's in pixels per milliseconds
+        let computedSwitchTime;
+        let childBox = this.get_allocation_box();
+        let availHeight = childBox.y2 - childBox.y1;
+        let min_velocity = availHeight / (PAGE_SWITCH_TIME * 1000);
+        let velocity = Math.max(min_velocity, velocity);
+        let diffFromPage =  this._diffToPage(pageNumber);
+        let time = (diffFromPage / velocity) / 1000;
+        //Let a maximum time of swtich
+        time = Math.min(PAGE_SWITCH_TIME, time);
+        //Only take into account the velocity if we change of page, if not,
+        //we returns smoothly to the current page (not with a lot of velocity)
+        if(this._currentPage == pageNumber)
+            time = PAGE_SWITCH_TIME;       
         
         if(pageNumber < this._pages.nPages() && pageNumber >= 0) {
             this._currentPage = pageNumber;
             let params = { value: this._pages.getPagePosition(this._currentPage)[1],
-                           time: PAGE_SWITCH_TIME,
+                           time: time,
                            transition: 'easeOutQuad'
                           };
             Tweener.addTween(this.vscroll.adjustment, params);


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