[gnome-shell/wip/paging-release: 15/93] PagionationScrollView, allview: take into account velocity when panning
- From: Carlos Soriano <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/paging-release: 15/93] PagionationScrollView, allview: take into account velocity when panning
- Date: Mon, 12 Aug 2013 17:13:02 +0000 (UTC)
commit 60a061d2e0c7c228cb5c346c9fb4bf7f456981a1
Author: Carlos Soriano <carlos soriano89 gmail com>
Date: Mon Aug 12 17:02:28 2013 +0200
PagionationScrollView, allview: take into account velocity when panning
js/ui/appDisplay.js | 59 ++++++++++++++++++++++++++++++++-------------------
1 files changed, 37 insertions(+), 22 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 830e463..6c90d01 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -280,10 +280,10 @@ const PaginationScrollView = new Lang.Class({
let panAction = new Clutter.PanAction({ interpolate: false });
panAction.connect('pan', Lang.bind(this, this._onPan));
panAction.connect('gesture-cancel', Lang.bind(this, function() {
- this._goToNearestPage(Math.abs(this._panAction.get_velocity(0)[2]));
+ this._onPanEnd(this._panAction);
}));
panAction.connect('gesture-end', Lang.bind(this, function() {
- this._goToNearestPage(Math.abs(this._panAction.get_velocity(0)[2]));
+ this._onPanEnd(this._panAction);
}));
this._panAction = panAction;
this.add_action(panAction);
@@ -315,28 +315,30 @@ const PaginationScrollView = new Lang.Class({
this._pages.setGridParentSize([availWidth, availHeight]);
child.allocate(childBox, flags);
},
-
- goToPage: function(pageNumber, velocity) {
- if(!velocity)
+
+ goToPage: function(pageNumber, action) {
+ let velocity;
+ if(!action)
velocity = 0;
+ else
+ velocity = Math.abs(action.get_velocity(0)[2]);
// 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;
-
+ let childBox = this.get_allocation_box();
+ let totalHeight = childBox.y2 - childBox.y1;
+ let time;
+ // Only take into account the velocity if we change of page, if not,
+ // we returns smoothly with default velocity to the current page
+ if(this._currentPage != pageNumber) {
+ let min_velocity = totalHeight / (PAGE_SWITCH_TIME * 1000);
+ velocity = Math.max(min_velocity, velocity);
+ time = (diffFromPage / velocity) / 1000;
+
+ } else
+ time = PAGE_SWITCH_TIME * diffFromPage / totalHeight;
if(pageNumber < this._pages.nPages() && pageNumber >= 0) {
this._currentPage = pageNumber;
let params = { value: this._pages.getPagePosition(this._currentPage)[1],
@@ -376,8 +378,8 @@ const PaginationScrollView = new Lang.Class({
return currentNearestPage;
},
- _goToNearestPage: function(velocity) {
- this._parent.goToPage(this._nearestPage(), velocity);
+ _goToNearestPage: function(action) {
+ this._parent.goToPage(this._nearestPage(), action);
},
_onScroll: function(actor, event) {
@@ -419,7 +421,20 @@ const PaginationScrollView = new Lang.Class({
let adjustment = this.vscroll.adjustment;
adjustment.value -= (dy / this.height) * adjustment.page_size;
return false;
+ },
+
+ _onPanEnd: function(action) {
+ let diffCurrentPage = this._diffToPage(this._currentPage);
+ if(diffCurrentPage > this.height * PAGE_SWITCH_TRESHOLD) {
+ if(action.get_velocity(0)[2] > 0 && this._currentPage > 0) {
+ this._parent.goToPage(this._currentPage - 1, action);
+ } else if(this._currentPage < this.nPages() - 1) {
+ this._parent.goToPage(this._currentPage + 1, action);
+ }
+ } else
+ this._parent.goToPage(this._currentPage, action);
}
+
});
const PaginationIconIndicator = new Lang.Class({
@@ -588,9 +603,9 @@ const AllView = new Lang.Class({
this._paginationView._pages.loadGrid();
},
- goToPage: function(index, velocity) {
+ goToPage: function(index, action) {
this._paginationIndicator.get_child_at_index(this._paginationView.currentPage()).set_checked(false);
- this._paginationView.goToPage(index, velocity);
+ this._paginationView.goToPage(index, action);
this._paginationIndicator.get_child_at_index(this._paginationView.currentPage()).set_checked(true);
}
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]