[gnome-maps] transitItineraryRow: Refine rendering route labels



commit b2c890c5e45299025fc16387dd1f6e5c043c36f8
Author: Marcus Lundblad <ml update uu se>
Date:   Tue Jun 27 22:17:56 2017 +0200

    transitItineraryRow: Refine rendering route labels
    
    Take into account the space of route labels when deciding
    when to render in contracted mode (with use mode icons).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=784231

 src/transitItineraryRow.js |   28 +++++++++++++++++++++++++---
 1 files changed, 25 insertions(+), 3 deletions(-)
---
diff --git a/src/transitItineraryRow.js b/src/transitItineraryRow.js
index e9ba11c..3b6bc99 100644
--- a/src/transitItineraryRow.js
+++ b/src/transitItineraryRow.js
@@ -55,10 +55,11 @@ const TransitItineraryRow = new Lang.Class({
          * overflowing the sidebar width
          */
         let useCompact = length > 2;
-        /* don't show the route labels when there are more than 5 legs in an
-         * itinerary
+        /* don't show the route labels if too much space is consumed,
+         * the constant 28 here was empiracally tested out...
          */
-        let useContractedLabels = length > 5;
+        let estimatedSpace = this._calculateEstimatedSpace();
+        let useContractedLabels = estimatedSpace > 28;
 
         this._itinerary.legs.forEach((function(leg, i) {
             this._summaryGrid.add(this._createLeg(leg, useCompact,
@@ -69,6 +70,27 @@ const TransitItineraryRow = new Lang.Class({
         }).bind(this));
     },
 
+    /* calculate an estimated relative space-consuption for rendering,
+     * this is done based on route label character lengths and a fixed
+     * "placeholder" amount for mode icons and separators, since doing an
+     * exact pixel-correct calculation would be hard depeding on fonts and
+     * themes
+     */
+    _calculateEstimatedSpace: function() {
+        let length = this._itinerary.legs.length;
+        /* assume mode icons and the separators consume about twice the space of
+         * characters
+         */
+        let space = 4 * length - 2;
+
+        this._itinerary.legs.forEach(function(leg) {
+            if (leg.transit)
+                space += leg.compactRoute.length;
+        });
+
+        return space;
+    },
+
     _createLeg: function(leg, useCompact, useContractedLabels) {
         if (!leg.transit || useContractedLabels) {
             /* if this is a non-transit leg (walking), or in case we should


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