[gnome-shell/wip/paging-release2: 9/9] Adapt spacing and icons size to available screen size. That is a good start to responsive design



commit 1b7cbcb7000d305254ef0a5e9e6b50e9e52c3eac
Author: Carlos Soriano <carlos soriano89 gmail com>
Date:   Thu Aug 15 10:38:17 2013 +0200

    Adapt spacing and icons size to available screen size. That is a good start to responsive design
    
    https://bugzilla.gnome.org/show_bug.cgi?id=706081

 js/ui/appDisplay.js    |   84 ++++++++++++++---------
 js/ui/iconGrid.js      |  174 +++++++++++++++++++++++++++++++++++++-----------
 js/ui/searchDisplay.js |    4 +-
 3 files changed, 186 insertions(+), 76 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 361c198..11dc3a2 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -69,9 +69,13 @@ const AlphabeticalView = new Lang.Class({
     Name: 'AlphabeticalView',
     Abstract: true,
 
-    _init: function() {
-        this._grid = new IconGrid.IconGrid({ xAlign: St.Align.MIDDLE,
-                                                                     columnLimit: MAX_COLUMNS });
+    _init: function(gridParams) {
+        gridParams = Params.parse(gridParams,  { xAlign: St.Align.MIDDLE,
+                                                 columnLimit: MAX_COLUMNS,
+                                                 minRows: MIN_ROWS,
+                                                 minColumns: MIN_COLUMNS,
+                                                 useSurroundingSpacing: false });
+        this._grid = new IconGrid.IconGrid(gridParams);
         // Standard hack for ClutterBinLayout
         this._grid.actor.x_expand = true;
         this._items = {};
@@ -115,7 +119,7 @@ const AlphabeticalView = new Lang.Class({
             let id = this._getItemId(this._allItems[i]);
             if (!id)
                 continue;
-            this._grid.addItem(this._items[id].actor);
+            this._grid.addItem(this._items[id]);
         }
     }
 });
@@ -124,9 +128,13 @@ const PaginatedAlphabeticalView = new Lang.Class({
     Name: 'PaginatedAlphabeticalView',
     Extends: AlphabeticalView,
 
-    _init: function() {
-         this._grid = new IconGrid.PaginatedIconGrid({ xAlign: St.Align.MIDDLE,
-                                                                                      columnLimit: 
MAX_COLUMNS });
+    _init: function(gridParams) {
+        gridParams = Params.parse(gridParams,  { xAlign: St.Align.MIDDLE,
+                                                 columnLimit: MAX_COLUMNS,
+                                                 minRows: MIN_ROWS,
+                                                 minColumns: MIN_COLUMNS,
+                                                 useSurroundingSpacing: false });
+        this._grid = new IconGrid.PaginatedIconGrid(gridParams);
         // Standard hack for ClutterBinLayout
         this._grid.actor.x_expand = true;
         this._items = {};
@@ -187,7 +195,7 @@ const PaginationIconIndicator = new Lang.Class({
     },
 
     _onClicked: function(actor, button) {        
-        this._parent.goToPage(this.actor._index, true); 
+        this._parent.goToPage(this.actor._index); 
         return false;
     },
 
@@ -268,7 +276,7 @@ const AllView = new Lang.Class({
     Extends: PaginatedAlphabeticalView,
    
     _init: function() {
-        this.parent();
+        this.parent({ useSurroundingSpacing: true });
         this._paginationView = new PaginationScrollView(this, {style_class: 'all-apps'});
         this._paginationIndicator = new PaginationIndicator({style_class: 'pages-indicator'});
         let layout = new Clutter.BinLayout();
@@ -527,8 +535,8 @@ const AllView = new Lang.Class({
                 for(let childrenId in rowsDown[rowId]) {
                     rowsDown[rowId][childrenId].translate_y = 0;
                     let tweenerParams = { translate_y: height,
-                                                           time: POPUP_FOLDER_VIEW_ANIMATION,
-                                                           onUpdate: function() {this.queue_relayout();} };
+                                          time: POPUP_FOLDER_VIEW_ANIMATION,
+                                          onUpdate: function() {this.queue_relayout();} };
                     if((rowId == rowsDown.length - 1) && (childrenId == rowsDown[rowId].length - 1)) {
                         tweenerParams['onComplete'] = Lang.bind(iconActor, 
iconActor.onCompleteMakeSpaceForPopUp);
                     }
@@ -684,14 +692,7 @@ const AllView = new Lang.Class({
         box = this._grid.actor.get_theme_node().get_content_box(box);
         let availWidth = box.x2 - box.x1;
         let availHeight = box.y2 - box.y1;
-
-        // Update grid dinamyc spacing based on display width
-        let spacing = this._grid.maxSpacingForWidthHeight(availWidth, availHeight, MIN_COLUMNS, MIN_ROWS, 
true);
-        this._grid.top_padding = spacing;
-        this._grid.bottom_padding = spacing;
-        this._grid.left_padding = spacing;
-        this._grid.right_padding = spacing;
-        this._grid.setSpacing(spacing);
+        this._grid.calculateResponsiveGrid(availWidth, availHeight);
         // Update folder views
         for(let id in this._folderIcons) {
             this._folderIcons[id].onUpdatedDisplaySize(availWidth, availHeight);
@@ -705,7 +706,10 @@ const FrequentView = new Lang.Class({
     _init: function() {
         this._grid = new IconGrid.IconGrid({ xAlign: St.Align.MIDDLE,
                                              fillParent: true,
-                                             columnLimit: MAX_COLUMNS });
+                                             columnLimit: MAX_COLUMNS,
+                                             minRows: MIN_ROWS,
+                                             minColumns: MIN_COLUMNS,
+                                             useSurroundingSpacing: true });
         this.actor = new St.Widget({ style_class: 'frequent-apps',
                                      x_expand: true, y_expand: true });
         this.actor.add_actor(this._grid.actor);
@@ -723,7 +727,7 @@ const FrequentView = new Lang.Class({
             if (!mostUsed[i].get_app_info().should_show())
                 continue;
             let appIcon = new AppIcon(mostUsed[i]);
-            this._grid.addItem(appIcon.actor, -1);
+            this._grid.addItem(appIcon, -1);
         }
     },
 
@@ -737,12 +741,7 @@ const FrequentView = new Lang.Class({
         box = this._grid.actor.get_theme_node().get_content_box(box);
         let availWidth = box.x2 - box.x1;
         let availHeight = box.y2 - box.y1;
-        let spacing = this._grid.maxSpacingForWidthHeight(availWidth, availHeight, MIN_COLUMNS, MIN_ROWS, 
true);
-        this._grid.top_padding = spacing;
-        this._grid.bottom_padding = spacing;
-        this._grid.left_padding = spacing;
-        this._grid.right_padding = spacing;
-        this._grid.setSpacing(spacing);
+        this._grid.calculateResponsiveGrid(availWidth, availHeight);
     }
 });
 
@@ -1029,7 +1028,7 @@ const FolderView = new Lang.Class({
     Extends: AlphabeticalView,
 
     _init: function() {
-        this.parent({ xAlign: St.Align.MIDDLE});
+       this.parent({ useSurroundingSpacing: true });
         // If it not expand, the parent doesn't take into account its preferred_width when allocating
         // the second time it allocates, so we apply the "Standard hack for ClutterBinLayout"
         this._grid.actor.x_expand = true;
@@ -1084,11 +1083,11 @@ const FolderView = new Lang.Class({
         this._appDisplayWidth = width;
         this._appDisplayHeight = height;
         // Update grid dinamyc spacing based on display width
-        let spacing = this._grid.maxSpacingForWidthHeight(width, height, MIN_COLUMNS, MIN_ROWS, true);
-        this._grid.setSpacing(spacing);
+        this._grid.calculateResponsiveGrid(width, height);
         if(!Object.keys(this._boxPointerOffsets).length)
             return;
 
+        let spacing = this._grid.getSpacing();
         let boxPointerTotalOffset = this._boxPointerOffsets['arrowHeight'] + 
this._boxPointerOffsets['padding'] * 2 + this._boxPointerOffsets['closeButtonOverlap'];
         let offsetForEachSide = Math.ceil(boxPointerTotalOffset / 2);
         this._offsetForEachSide = offsetForEachSide;
@@ -1120,7 +1119,7 @@ const FolderView = new Lang.Class({
 
     usedHeight: function() {
         // Then calculate the real maxUsedHeight
-        return this._grid.usedHeightForNRows(this.nRowsDisplayedAtOnce()) + this._grid.top_padding + 
this._grid.bottom_padding;
+        return this._grid.usedHeightForNRows(this.nRowsDisplayedAtOnce());
     },   
 
     nRowsDisplayedAtOnce: function() {
@@ -1190,7 +1189,7 @@ const FolderIcon = new Lang.Class({
 
         let label = this._dir.get_name();
         this.icon = new IconGrid.BaseIcon(label,
-                                          { createIcon: Lang.bind(this, this._createIcon) });
+                                          { createIcon: Lang.bind(this, this._createIcon), setSizeManually: 
true });
         this.actor.set_child(this.icon.actor);
         this.actor.label_actor = this.icon.label;
 
@@ -1214,8 +1213,16 @@ const FolderIcon = new Lang.Class({
         }));
     },
 
-    _createIcon: function(size) {
-        return this.view.createFolderIcon(size, this);
+    _createIcon: function(iconSize) {
+        return this.view.createFolderIcon(iconSize, this);
+    },
+
+    getIconSize: function() {
+        return this.icon.iconSize;
+    },
+
+    setIconSize: function(size) {
+        this.icon.setIconSize(size);
     },
 
     _popUpGridWidth: function() {
@@ -1480,6 +1487,7 @@ const AppIcon = new Lang.Class({
             iconParams = {};
 
         iconParams['createIcon'] = Lang.bind(this, this._createIcon);
+        iconParams['setSizeManually'] = true;
         this.icon = new IconGrid.BaseIcon(app.get_name(), iconParams);
         this.actor.set_child(this.icon.actor);
 
@@ -1527,6 +1535,14 @@ const AppIcon = new Lang.Class({
         return this.app.create_icon_texture(iconSize);
     },
 
+    getIconSize: function() {
+        return this.icon.iconSize;
+    },
+
+    setIconSize: function(size) {
+        this.icon.setIconSize(size);
+    },
+
     _removeMenuTimeout: function() {
         if (this._menuTimeoutId > 0) {
             Mainloop.source_remove(this._menuTimeoutId);
diff --git a/js/ui/iconGrid.js b/js/ui/iconGrid.js
index ed63aad..effd2e4 100644
--- a/js/ui/iconGrid.js
+++ b/js/ui/iconGrid.js
@@ -7,9 +7,10 @@ const St = imports.gi.St;
 const Signals = imports.signals;
 const Lang = imports.lang;
 const Params = imports.misc.params;
+const Meta = imports.gi.Meta;
 
-const ICON_SIZE = 48;
-
+const ICON_SIZE = 96;
+const MIN_ICON_SIZE = 16;
 
 const BaseIcon = new Lang.Class({
     Name: 'BaseIcon',
@@ -180,12 +181,18 @@ const IconGrid = new Lang.Class({
     _init: function(params) {
         params = Params.parse(params, { rowLimit: null,
                                         columnLimit: null,
+                                        minRows: 1,
+                                        minColumns: 1,
                                         fillParent: false,
-                                        xAlign: St.Align.MIDDLE });
+                                        xAlign: St.Align.MIDDLE,
+                                        useSurroundingSpacing: true});
         this._rowLimit = params.rowLimit;
         this._colLimit = params.columnLimit;
+        this._minRows = params.minRows;
+        this._minColumns = params.minColumns;
         this._xAlign = params.xAlign;
         this._fillParent = params.fillParent;
+        this._useSurroundingSpacing = params.useSurroundingSpacing;
 
         this.top_padding = 0;
         this.bottom_padding = 0;
@@ -193,10 +200,12 @@ const IconGrid = new Lang.Class({
         this.left_padding = 0;
 
         this.actor = new St.BoxLayout({ style_class: 'icon-grid',
-                                                                vertical: true });
+                                        vertical: true });
+        this._items = [];
         // Pulled from CSS, but hardcode some defaults here
         this._spacing = 0;
         this._hItemSize = this._vItemSize = ICON_SIZE;
+        this._fixedHItemSize = this._fixedVItemSize = undefined;
         this._grid = new Shell.GenericContainer();
         this.actor.add(this._grid, { expand: true, y_align: St.Align.START });
         this.actor.connect('style-changed', Lang.bind(this, this._onStyleChanged));
@@ -220,8 +229,8 @@ const IconGrid = new Lang.Class({
         // Kind of a lie, but not really an issue right now.  If
         // we wanted to support some sort of hidden/overflow that would
         // need higher level design
-        alloc.min_size = this._hItemSize + this.left_padding + this.right_padding;
-        alloc.natural_size = nColumns * this._hItemSize + totalSpacing + this.left_padding + 
this.right_padding;
+        alloc.min_size = this.getHItemSize() + this.left_padding + this.right_padding;
+        alloc.natural_size = nColumns * this.getHItemSize() + totalSpacing + this.left_padding + 
this.right_padding;
     },
 
     _getPreferredHeight: function (grid, forWidth, alloc) {
@@ -244,8 +253,10 @@ const IconGrid = new Lang.Class({
             nRows = 0;
         if (this._rowLimit)
             nRows = Math.min(nRows, this._rowLimit);
+
         let totalSpacing = Math.max(0, nRows - 1) * this.getSpacing();
-        let height = nRows * this._vItemSize + totalSpacing + this.top_padding + this.bottom_padding;
+        let height = nRows * this.getVItemSize() + totalSpacing + this.top_padding + this.bottom_padding;
+
         alloc.min_size = height;
         alloc.natural_size = height;
     },
@@ -263,7 +274,7 @@ const IconGrid = new Lang.Class({
         let availHeight = box.y2 - box.y1;
         let spacing = this.getSpacing();
         let [nColumns, usedWidth] = this._computeLayout(availWidth);
-       
+
         let leftEmptySpace;
         switch(this._xAlign) {
             case St.Align.START:
@@ -300,10 +311,10 @@ const IconGrid = new Lang.Class({
                 rowIndex++;
             }
             if (columnIndex == 0) {
-                y += this._vItemSize + spacing;
+                y += this.getVItemSize() + spacing;
                 x = box.x1 + leftEmptySpace + this.left_padding;
             } else {
-                x += this._hItemSize + spacing;
+                x += this.getHItemSize() + spacing;
             }
         }
     },
@@ -313,9 +324,9 @@ const IconGrid = new Lang.Class({
         = child.get_preferred_size();
 
         /* Center the item in its allocation horizontally */
-        let width = Math.min(this._hItemSize, childNaturalWidth);
+        let width = Math.min(this.getHItemSize(), childNaturalWidth);
         let childXSpacing = Math.max(0, width - childNaturalWidth) / 2;
-        let height = Math.min(this._vItemSize, childNaturalHeight);
+        let height = Math.min(this.getVItemSize(), childNaturalHeight);
         let childYSpacing = Math.max(0, height - childNaturalHeight) / 2;
 
         let childBox = new Clutter.ActorBox();
@@ -337,8 +348,8 @@ const IconGrid = new Lang.Class({
         let spacing = this.getSpacing();
 
         while ((this._colLimit == null || nColumns < this._colLimit) &&
-               (usedWidth + this._hItemSize <= forWidth)) {
-            usedWidth += this._hItemSize + spacing;
+               (usedWidth + this.getHItemSize() <= forWidth)) {
+            usedWidth += this.getHItemSize() + spacing;
             nColumns += 1;
         }
 
@@ -363,7 +374,7 @@ const IconGrid = new Lang.Class({
         return children;
     },
 
-    childrenInRow: function(rowWidth) {
+    columnsForWidth: function(rowWidth) {
         return this._computeLayout(rowWidth)[0];
     },
 
@@ -392,7 +403,7 @@ const IconGrid = new Lang.Class({
 
     rowsForHeight: function(forHeight) {
         forHeight -= this.top_padding + this.bottom_padding;
-        let spacePerRow = this._vItemSize + this.getSpacing();
+        let spacePerRow = this.getVItemSize() + this.getSpacing();
         let rowsPerPage = Math.floor(forHeight / spacePerRow);
         // Check if deleting spacing from bottom there's enough space for another row
         let spaceWithOneMoreRow = (rowsPerPage + 1) * spacePerRow - this.getSpacing();
@@ -402,25 +413,33 @@ const IconGrid = new Lang.Class({
 
     usedHeightForNRows: function(nRows) {
         let spacePerRow = this.rowHeight();
-        return spacePerRow * nRows - this.getSpacing();
+        return spacePerRow * nRows - this.getSpacing() + this.top_padding + this.bottom_padding;
     },
 
     usedWidth: function(forWidth) {
-        let childrenInRow = this.childrenInRow(forWidth);
-        let usedWidth = childrenInRow  * (this._hItemSize + this.getSpacing());
+        let columnsForWidth = this.columnsForWidth(forWidth);
+        let usedWidth = columnsForWidth  * (this.getHItemSize() + this.getSpacing());
+        usedWidth -= this.getSpacing();
+        return usedWidth + this.left_padding + this.right_padding;
+    },
+
+    usedWidthForNColumns: function(columns) {
+        let usedWidth = columns  * (this.getHItemSize() + this.getSpacing());
         usedWidth -= this.getSpacing();
         return usedWidth + this.left_padding + this.right_padding;
     },
 
     removeAll: function() {
+        this._items = [];
         this._grid.destroy_all_children();
     },
 
-    addItem: function(actor, index) {
+    addItem: function(item, index) {
+        this._items.push(item);
         if (index !== undefined)
-            this._grid.insert_child_at_index(actor, index);
+            this._grid.insert_child_at_index(item.actor, index);
         else
-            this._grid.add_actor(actor);
+            this._grid.add_actor(item.actor);
     },
 
     getItemAtIndex: function(index) {
@@ -439,33 +458,42 @@ const IconGrid = new Lang.Class({
         return this._fixedSpacing ? this._fixedSpacing : this._spacing;
     },
 
-     /**
-     * This functions is intended to use before iconGrid allocation, to know how much spacing can we have at 
the grid
+    getHItemSize: function() {
+        return this._fixedHItemSize ? this._fixedHItemSize : this._hItemSize;
+    },
+
+    getVItemSize: function() {
+        return this._fixedVItemSize ? this._fixedVItemSize : this._vItemSize;
+    },
+
+    /**
+     * This function is intended to use before iconGrid allocation, to know how much spacing can we have at 
the grid
      * but also to set manually the top/bottom rigth/left padding accordnly to the spacing calculated here.
      * To take into account the spacing also for before the first row and for after the last row mark 
usingSurroundingSpacing true
      * This function doesn't take into account the dynamic padding rigth now, since in fact we want to 
calculate also that.
      */
-    maxSpacingForWidthHeight: function(availWidth, availHeight, minColumns, minRows, 
usingSurroundingSpacing) {
+    maxSpacingForWidthHeight: function(availWidth, availHeight) {
         // Maximum spacing will be the icon item size. It doesn't make any sense to have more spacing than 
items.
-        let maxSpacing = Math.floor(Math.min(this._vItemSize, this._hItemSize));
-        let minEmptyVerticalArea = (availHeight - minRows * this._vItemSize);
-        let minEmptyHorizontalArea = (availWidth - minColumns * this._hItemSize);
+        let maxSpacing = Math.floor(Math.min(this.getVItemSize(), this.getHItemSize()));
+        let minEmptyVerticalArea = (availHeight - this._minRows * this.getVItemSize());
+        let minEmptyHorizontalArea = (availWidth - this._minColumns * this.getHItemSize());
         let spacing;
-        if(usingSurroundingSpacing) {
+        if(this._useSurroundingSpacing) {
             // minRows + 1 because we want to put spacing before the first row, so it is like we have one 
more row
             // to divide the empty space
-            let maxSpacingForRows = Math.floor(minEmptyVerticalArea / (minRows +1));
-            let maxSpacingForColumns = Math.floor(minEmptyHorizontalArea / (minColumns +1));
+            let maxSpacingForRows = Math.floor(minEmptyVerticalArea / (this._minRows +1));
+            let maxSpacingForColumns = Math.floor(minEmptyHorizontalArea / (this._minColumns +1));
             let spacingToEnsureMinimums = Math.min(maxSpacingForRows, maxSpacingForColumns);
             let spacingNotTooBig = Math.min(spacingToEnsureMinimums, maxSpacing);
             spacing = Math.max(this._spacing, spacingNotTooBig);
         } else {
-            if(minRows == 1) {
-                let maxSpacingForRows = Math.floor(minEmptyVerticalArea / minRows);
-                let maxSpacingForColumns = Math.floor(minEmptyHorizontalArea / minColumns);
+            let maxSpacingForRows, maxSpacingForColumns;
+            if(this._minRows == 1) {
+                maxSpacingForRows = Math.floor(minEmptyVerticalArea / this._minRows);
+                maxSpacingForColumns = Math.floor(minEmptyHorizontalArea / this._minColumns);
             } else {
-                let maxSpacingForRows = Math.floor(minEmptyVerticalArea / (minRows - 1));
-                let maxSpacingForColumns = Math.floor(minEmptyHorizontalArea / (minColumns - 1));
+                maxSpacingForRows = Math.floor(minEmptyVerticalArea / (this._minRows - 1));
+                maxSpacingForColumns = Math.floor(minEmptyHorizontalArea / (this._minColumns - 1));
             }
             let spacingToEnsureMinimums = Math.min(maxSpacingForRows, maxSpacingForColumns);
             let spacingNotTooBig = Math.min(spacingToEnsureMinimums, maxSpacing);
@@ -474,8 +502,70 @@ const IconGrid = new Lang.Class({
         return spacing;
     },
 
+    calculateResponsiveGrid: function(availWidth, availHeight) {
+        this._fixedHItemSize = this._hItemSize;
+        this._fixedVItemSize = this._vItemSize;
+        let spacing = this.maxSpacingForWidthHeight(availWidth, availHeight);
+        this.setSpacing(spacing);
+        if(this._useSurroundingSpacing)
+            this.top_padding = this.bottom_padding = this.right_padding = this.left_padding = spacing;
+
+        let count = 0;
+        if(this.columnsForWidth(availWidth) < this._minColumns || this.rowsForHeight(availHeight) < 
this._minRows) {
+            let neededWidth, neededHeight;
+            if(this._useSurroundingSpacing)
+                neededWidth = this.usedWidthForNColumns(this._minColumns) - availWidth ;
+            else
+                neededWidth = this.usedWidthForNColumns(this._minColumns) - availWidth ;
+
+            if(this._useSurroundingSpacing)
+                neededHeight = this.usedHeightForNRows(this._minRows) - availHeight;
+            else
+                neededHeight = this.usedHeightForNRows(this._minRows) - availHeight ;
+
+            if(neededWidth > neededHeight) {
+                let neededSpaceForEachItem = Math.ceil(neededWidth / this._minColumns);
+                this._fixedHItemSize = this._hItemSize - neededSpaceForEachItem;
+                this._fixedVItemSize = this._vItemSize - neededSpaceForEachItem;
+            } else {
+                let neededSpaceForEachItem = Math.ceil(neededHeight / this._minRows);
+                this._fixedHItemSize = this._hItemSize - neededSpaceForEachItem;
+                this._fixedVItemSize = this._vItemSize - neededSpaceForEachItem;
+            }
+
+            if(this._fixedHItemSize < MIN_ICON_SIZE)
+                this._fixedHItemSize = MIN_ICON_SIZE;
+            if(this._fixedVItemSize < MIN_ICON_SIZE)
+                this._fixedVItemSize = MIN_ICON_SIZE;
+
+            let spacing = this.maxSpacingForWidthHeight(availWidth, availHeight);
+            this.setSpacing(spacing);
+            if(this._useSurroundingSpacing)
+                this.top_padding = this.bottom_padding = this.right_padding = this.left_padding = spacing;
+        }
+        let scale = Math.min(this._fixedHItemSize, this._fixedVItemSize) / Math.max(this._hItemSize, 
this._vItemSize);
+        this.updateChildrenScale(scale);
+    },
+
+    /**
+     * We are supossing that the this._items contain some item that we can set its size. 
+     * Also, we suposse that they are icons, and the original size is ICON_SIZE, to let the good icon size 
when updating the size.
+     * Also, we supose that we need a Meta.later, since when we call calculateResponsiveGrid that calls 
updateChildrenScale
+     * we are inside the allocation of the AppDisplay, and modifinyg icon size can cause allocation cycles
+     * So this functions is not intentded to be called outside this class, lets think a little about that. 
Now reescaling icons
+     * works fine at least.
+     */
+    updateChildrenScale: function(scale) {
+        Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this, function() {
+            for(let i in this._items) {
+                let newIconSize = Math.floor(ICON_SIZE * scale);
+                this._items[i].setIconSize(newIconSize);
+            }
+        }));
+    },
+
     rowHeight: function() {
-        return this._vItemSize + this.getSpacing();
+        return this.getVItemSize() + this.getSpacing();
     }
 });
 Signals.addSignalMethods(IconGrid.prototype);
@@ -534,6 +624,10 @@ const PaginatedIconGrid = new Lang.Class({
         // maybe the number of pages doesn't change
         if(oldNPages != this._nPages || oldHeightUsedPerPage != this.usedHeightPerPage()) {
             this.emit('n-pages-changed', this._nPages);
+            Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this, function() {
+                this._grid.queue_relayout();
+                return false;
+            }));
         }
 
         let leftEmptySpace;
@@ -568,20 +662,20 @@ const PaginatedIconGrid = new Lang.Class({
                 rowIndex++;
             }
             if (columnIndex == 0) {
-                y += this._vItemSize + spacing;
+                y += this.getVItemSize() + spacing;
                 if((i + 1) % this._childrenPerPage == 0) {
                     y+= - spacing + this._spaceBetweenPages + this.bottom_padding + this.top_padding ;
                 }
                 x = box.x1 + leftEmptySpace + this.left_padding;
             } else {
-                x += this._hItemSize + spacing;
+                x += this.getHItemSize() + spacing;
             }
         }
     },
 
     _calculatePaginationValues: function (availHeightPerPage, nColumns, nRows) {
         let spacing = this.getSpacing();
-        this._spacePerRow = this._vItemSize + spacing;
+        this._spacePerRow = this.getVItemSize() + spacing;
         // We want to contain the grid inside the parent box with padding
         availHeightPerPage -= this.top_padding + this.bottom_padding;
         this._rowsPerPage = Math.floor(availHeightPerPage / this._spacePerRow);
diff --git a/js/ui/searchDisplay.js b/js/ui/searchDisplay.js
index 2177874..a7a1cde 100644
--- a/js/ui/searchDisplay.js
+++ b/js/ui/searchDisplay.js
@@ -320,14 +320,14 @@ const GridSearchResults = new Lang.Class({
     },
 
     _getMaxDisplayedResults: function() {
-        return this._grid.childrenInRow(this._bin.width) * this._grid.getRowLimit();
+        return this._grid.columnsForWidth(this._bin.width) * this._grid.getRowLimit();
     },
 
     _renderResults: function(metas) {
         for (let i = 0; i < metas.length; i++) {
             let display = new GridSearchResult(this.provider, metas[i], this._terms);
             display.actor.connect('key-focus-in', Lang.bind(this, this._keyFocusIn));
-            this._grid.addItem(display.actor);
+            this._grid.addItem(display);
         }
     },
 


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