[gnome-maps/wip/mlundblad/transit-routing: 5/8] WIP: Add label widget for route labels



commit be9f21ec3468a1ffff1cc5d1a0ddf8f772b0fa3f
Author: Marcus Lundblad <ml update uu se>
Date:   Tue May 31 23:26:26 2016 +0200

    WIP: Add label widget for route labels

 src/org.gnome.Maps.src.gresource.xml |    1 +
 src/transitRouteLabel.js             |   69 ++++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+), 0 deletions(-)
---
diff --git a/src/org.gnome.Maps.src.gresource.xml b/src/org.gnome.Maps.src.gresource.xml
index 8a9a218..7fc9174 100644
--- a/src/org.gnome.Maps.src.gresource.xml
+++ b/src/org.gnome.Maps.src.gresource.xml
@@ -74,6 +74,7 @@
     <file>togeojson/togeojson.js</file>
     <file>transitOptions.js</file>
     <file>transitPlan.js</file>
+    <file>transitRouteLabel.js</file>
     <file>translations.js</file>
     <file>turnPointMarker.js</file>
     <file>userLocationBubble.js</file>
diff --git a/src/transitRouteLabel.js b/src/transitRouteLabel.js
new file mode 100644
index 0000000..830df3b
--- /dev/null
+++ b/src/transitRouteLabel.js
@@ -0,0 +1,69 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2016 Marcus Lundblad.
+ *
+ * GNOME Maps is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * GNOME Maps is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with GNOME Maps; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Marcus Lundblad <ml update uu se>
+ */
+
+const Lang = imports.lang;
+
+const Gtk = imports.gi.Gtk;
+
+/* default route label colors */
+const DEFAULT_COLOR = "3465a4";
+const DEFAULT_TEXT_COLOR = "ffffff";
+
+const TransitRouteLabel = new Lang.Class({
+    Name: 'TransitRouteLabel',
+    Extends: Gtk.Label,
+
+    _init: function(params) {
+        this._leg = params.leg;
+        delete params.leg;
+
+        this._compact = params.compact;
+        delete params.compact;
+
+        this.parent(params);
+
+        this._setLabel();
+    },
+
+    _setLabel: function() {
+        let color = this._leg.color;
+        let textColor = this._leg.textColor;
+        let route = this._leg.route;
+
+        /* TODO: we should check saneness of supplied route color/text color
+         * (sufficent contrast) and also in case only color was supplied,
+         * deduce a good contrasting text color (black or white)
+         */
+        if (!color || !textColor) {
+            color = DEFAULT_COLOR;
+            textColor = DEFAULT_TEXT_COLOR;
+        }
+
+        /* TODO: take the "compact" parameter in consideration and produce a
+         * shortend variant in case the route is too long for overview use
+         * (can be the case for i.e. train lines)
+         */
+        this.label =
+            '<span background="#%s" foreground="#%s">%s</span>'.format(color,
+                                                                       textColor,
+                                                                       route);
+    }
+});


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