[gnome-maps/wip/mlundblad/touch-gestures] mapView: WIP: implement swipe gesture to bring up the sidebar
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/touch-gestures] mapView: WIP: implement swipe gesture to bring up the sidebar
- Date: Fri, 20 Oct 2017 21:12:18 +0000 (UTC)
commit c80eb10f71f032431119555018e54d888fcc8246
Author: Marcus Lundblad <ml update uu se>
Date: Thu Oct 19 23:54:16 2017 +0200
mapView: WIP: implement swipe gesture to bring up the sidebar
src/mapView.js | 34 ++++++++++++++++++++++++++++++++++
1 files changed, 34 insertions(+), 0 deletions(-)
---
diff --git a/src/mapView.js b/src/mapView.js
index 363ae90..2dca680 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -24,6 +24,7 @@ const Clutter = imports.gi.Clutter;
const GObject = imports.gi.GObject;
const Geocode = imports.gi.GeocodeGlib;
const Gio = imports.gi.Gio;
+const Gtk = imports.gi.Gtk;
const GtkChamplain = imports.gi.GtkChamplain;
const Lang = imports.lang;
const Mainloop = imports.mainloop;
@@ -86,6 +87,9 @@ const DASHED_ROUTE_LINE_FILLED_LENGTH = 5;
// length of gaps of dashed lines used for walking legs of transit itineraries
const DASHED_ROUTE_LINE_GAP_LENGTH = 5;
+// threashhold to detect as a swipe-from-the edge gesture
+const SWIPE_EDGE_THREASHHOLD = 10;
+
var MapView = new Lang.Class({
Name: 'MapView',
Extends: GtkChamplain.Embed,
@@ -160,6 +164,7 @@ var MapView = new Lang.Class({
this._updateUserLocation.bind(this));
this._storeId = 0;
this._connectRouteSignals();
+ this._initGestures();
},
_initScale: function(view) {
@@ -201,6 +206,35 @@ var MapView = new Lang.Class({
return view;
},
+ _initGestures: function() {
+ this._swipeGesture =
+ new Gtk.GestureSwipe({ widget: this, 'touch-only': true });
+ this._panGesture = new Gtk.GesturePan({ widget: this,
+ 'touch-only': true,
+ orientation: Gtk.Orientation.HORIZONTAL });
+ // restrict to horizontal swiping by grouping with a horizontal pan
+ this._swipeGesture.group(this._panGesture);
+ this._swipeGesture.connect('swipe', this._onSwipe.bind(this));
+ this._swipeGesture.connect('begin', this._onSwipeBegin.bind(this));
+ },
+
+ _onSwipeBegin: function(gesture, sequence) {
+ let rtl = Gtk.get_locale_direction() === Gtk.TextDirection.RTL;
+ Utils.debug('swipe begin');
+ let [_, x, y] = gesture.get_point(sequence);
+ Utils.debug('point: ' + x + ',' + y);
+ this._recognizeEdgeSwipe = rtl ?
+ x < SWIPE_EDGE_THREASHHOLD :
+ x > this.get_allocated_width() - SWIPE_EDGE_THREASHHOLD;
+ Utils.debug('recognized: ' + this._recognizeEdgeSwipe);
+ },
+
+ _onSwipe: function(gesture, velocityX, velocityY) {
+ Utils.debug('swipe: ' + velocityX + ', ' + velocityY);
+ if (this._recognizeEdgeSwipe)
+ Application.routeQuery.notify('points');
+ },
+
/* create and store a route layer, pass true to get a dashed line */
_createRouteLayer: function(dashed, lineColor, width) {
let red = Color.parseColor(lineColor, 0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]