[gnome-shell] iconGrid: Dynamically adjust spacing based on columnLimit



commit b922035d4fcee7c84892e800ae387f8ad7b2a5ed
Author: Adel Gadllah <adel gadllah gmail com>
Date:   Wed Feb 20 00:38:11 2013 +0100

    iconGrid: Dynamically adjust spacing based on columnLimit
    
    Adjust the spacing based on the available width when a columnLimit
    is set to evenly place the icons.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=694215

 js/ui/appDisplay.js |    3 +++
 js/ui/iconGrid.js   |   21 +++++++++++++++------
 2 files changed, 18 insertions(+), 6 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index ecc2cb1..c38e328 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -63,6 +63,9 @@ const AlphabeticalView = new Lang.Class({
         this._grid = new IconGrid.IconGrid({ xAlign: St.Align.MIDDLE,
                                              columnLimit: MAX_COLUMNS });
 
+        // Standard hack for ClutterBinLayout
+        this._grid.actor.x_expand = true;
+
         this._items = {};
         this._allItems = [];
     },
diff --git a/js/ui/iconGrid.js b/js/ui/iconGrid.js
index 2b63865..98e5761 100644
--- a/js/ui/iconGrid.js
+++ b/js/ui/iconGrid.js
@@ -241,7 +241,7 @@ const IconGrid = new Lang.Class({
         let availWidth = box.x2 - box.x1;
         let availHeight = box.y2 - box.y1;
 
-        let [nColumns, usedWidth] = this._computeLayout(availWidth);
+        let [nColumns, usedWidth, spacing] = this._computeLayout(availWidth);
 
         let leftPadding;
         switch(this._xAlign) {
@@ -294,10 +294,10 @@ const IconGrid = new Lang.Class({
             }
 
             if (columnIndex == 0) {
-                y += this._vItemSize + this._spacing;
+                y += this._vItemSize + spacing;
                 x = box.x1 + leftPadding;
             } else {
-                x += this._hItemSize + this._spacing;
+                x += this._hItemSize + spacing;
             }
         }
     },
@@ -313,16 +313,25 @@ const IconGrid = new Lang.Class({
     _computeLayout: function (forWidth) {
         let nColumns = 0;
         let usedWidth = 0;
+        let spacing = this._spacing;
+
+        if (this._colLimit) {
+            let itemWidth = this._hItemSize * this._colLimit;
+            let emptyArea = forWidth - itemWidth;
+            spacing = Math.max(this._spacing, emptyArea / (2 * this._colLimit));
+            spacing = Math.round(spacing);
+        }
+
         while ((this._colLimit == null || nColumns < this._colLimit) &&
                (usedWidth + this._hItemSize <= forWidth)) {
-            usedWidth += this._hItemSize + this._spacing;
+            usedWidth += this._hItemSize + spacing;
             nColumns += 1;
         }
 
         if (nColumns > 0)
-            usedWidth -= this._spacing;
+            usedWidth -= spacing;
 
-        return [nColumns, usedWidth];
+        return [nColumns, usedWidth, spacing];
     },
 
     _onStyleChanged: function() {


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