[gnome-shell/wip/paging-release: 13/93] PaginationScrollView: Added pan action
- From: Carlos Soriano <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/paging-release: 13/93] PaginationScrollView: Added pan action
- Date: Mon, 12 Aug 2013 17:12:52 +0000 (UTC)
commit cf78debb0f92cd95789eea531fb72bc13e57c88d
Author: Carlos Soriano <carlos soriano89 gmail com>
Date: Mon Aug 12 16:36:45 2013 +0200
PaginationScrollView: Added pan action
js/ui/appDisplay.js | 68 ++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 54 insertions(+), 14 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index e70646e..d69d010 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -276,6 +276,17 @@ const PaginationScrollView = new Lang.Class({
this._parent = parent;
this.connect('scroll-event', Lang.bind(this, this._onScroll));
+
+ 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]));
+ }));
+ panAction.connect('gesture-end', Lang.bind(this, function() {
+ this._goToNearestPage(Math.abs(this._panAction.get_velocity(0)[2]));
+ }));
+ this._panAction = panAction;
+ this.add_action(panAction);
},
vfunc_get_preferred_height: function (container, forWidht) {
@@ -325,12 +336,44 @@ const PaginationScrollView = new Lang.Class({
return this._currentPage;
},
+ _diffToPage: function (pageNumber) {
+ let currentScrollPosition = this.vscroll.adjustment.value;
+ return Math.abs(currentScrollPosition - this._pages._grid.getPagePosition(pageNumber)[1]);
+ },
+
+ _nearestPage: function() {
+ let currentNearestPage = 0;
+ let diff = this._diffToPage(currentNearestPage);
+ let oldDiff = diff;
+
+ while(diff <= oldDiff && currentNearestPage < (this._pages.nPages() - 1)) {
+ currentNearestPage++;
+ oldDiff = diff;
+ diff = this._diffToPage(currentNearestPage);
+ }
+ if(diff > oldDiff)
+ currentNearestPage--;
+
+ return currentNearestPage;
+ },
+
+ _goToNearestPage: function(velocity) {
+ this._parent.goToPage(this._nearestPage(), velocity);
+ },
+
_onScroll: function(actor, event) {
let direction = event.get_scroll_direction();
+ let nextPage;
if (direction == Clutter.ScrollDirection.UP)
- this._parent.goToPage(this._currentPage - 1);
+ if(this._currentPage > 0) {
+ nextPage = this._currentPage - 1;
+ this._parent.goToPage(nextPage);
+ }
if (direction == Clutter.ScrollDirection.DOWN)
- this._parent.goToPage(this._currentPage + 1);
+ if(this._currentPage < (this.nPages() - 1)) {
+ nextPage = this._currentPage + 1;
+ this._parent.goToPage(nextPage);
+ }
},
addFolderPopup: function(popup) {
@@ -350,6 +393,13 @@ const PaginationScrollView = new Lang.Class({
else
this._items[id].actor.opacity = 255;
}
+ },
+
+ _onPan: function(action) {
+ let [dist, dx, dy] = action.get_motion_delta(0);
+ let adjustment = this.vscroll.adjustment;
+ adjustment.value -= (dy / this.height) * adjustment.page_size;
+ return false;
}
});
@@ -492,16 +542,6 @@ const AllView = new Lang.Class({
return false;
},
-
- _onPan: function(action) {
- /*
- this._clickAction.release();
-
- let [dist, dx, dy] = action.get_motion_delta(0);
- let adjustment = this.actor.vscroll.adjustment;
- adjustment.value -= (dy / this.actor.height) * adjustment.page_size;*/
- return false;
- },
addApp: function(app) {
let appIcon = this._paginationView._pages.addItem(app);
@@ -529,9 +569,9 @@ const AllView = new Lang.Class({
this._paginationView._pages.loadGrid();
},
- goToPage: function(index) {
+ goToPage: function(index, velocity) {
this._paginationIndicator.get_child_at_index(this._paginationView.currentPage()).set_checked(false);
- this._paginationView.goToPage(index);
+ this._paginationView.goToPage(index, velocity);
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]