[gnome-shell/wip/paging-release: 31/38] we don't need anymore the pagination calculation at allocation time, since we calcualte the responsi



commit f9a402c301f45f18d7f8ba61dd7928d5ac4b11c2
Author: Carlos Soriano <carlos soriano89 gmail com>
Date:   Fri Aug 2 13:52:13 2013 +0200

    we don't need anymore the pagination calculation at allocation time,
    since we calcualte the responsive grid in parents allocation before

 js/ui/appDisplay.js    |   12 ------------
 js/ui/iconGrid.js      |   38 +++++++++++++++++++++++++++++++++-----
 js/ui/searchDisplay.js |    2 +-
 3 files changed, 34 insertions(+), 18 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index ccccc32..db906cb 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -1118,15 +1118,6 @@ const FolderView = new Lang.Class({
 
     _init: function() {
         this.parent({ useSurroundingSpacing: true });
-
-        /*this._grid = new IconGrid.IconGrid({ xAlign: St.Align.MIDDLE,
-                                             columnLimit: MAX_COLUMNS,
-                                             minRows: MIN_ROWS,
-                                             minColumns: MIN_COLUMNS,
-                                             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;
         
         this.actor = new St.ScrollView({overlay_scrollbars: true});
         this.actor.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
@@ -1135,9 +1126,6 @@ const FolderView = new Lang.Class({
         this._widget.add_child(this._grid.actor);
         this._box.add_actor(this._widget);
         this.actor.add_actor(this._box);
-        this._items = {};
-        this._allItems = [];
-        
         this._boxPointerOffsets = {};
     },
 
diff --git a/js/ui/iconGrid.js b/js/ui/iconGrid.js
index 17675c5..fbc6aad 100644
--- a/js/ui/iconGrid.js
+++ b/js/ui/iconGrid.js
@@ -302,7 +302,7 @@ const IconGrid = new Lang.Class({
         let availHeight = box.y2 - box.y1;
         let spacing = this.getSpacing();
         let [nColumns, usedWidth] = this._computeLayout(availWidth);
-        if(this._usePagination) {
+        /*if(this._usePagination) {
             // Calculate icongrid box inside the scrollView
             let parentBox = this._viewForPageSize.allocation;
             let gridBox = this.actor.get_theme_node().get_content_box(parentBox);
@@ -328,7 +328,7 @@ const IconGrid = new Lang.Class({
                     return false;
                 }));
             }
-        }
+        }*/
         let leftPadding;
         switch(this._xAlign) {
             case St.Align.START:
@@ -387,10 +387,22 @@ const IconGrid = new Lang.Class({
             } else {
                 x += this.getHItemSize() + spacing;
             }
-        }       
+        }
     },
     
-    _calculatePaginationValues: function (availHeightPerPage, nColumns, nRows) {
+    _calculatePaginationValues: function (availWidthPerPage, availHeightPerPage) {
+        let [nColumns, usedWidth] = this._computeLayout(availWidthPerPage);
+        let nRows;
+        let children = this._getVisibleChildren();
+        if (nColumns > 0)
+            nRows = Math.ceil(children.length / nColumns);
+        else
+            nRows = 0;
+        if (this._rowLimit)
+            nRows = Math.min(nRows, this._rowLimit);
+        let oldHeightUsedPerPage = this.usedHeightPerPage();
+        let oldNPages = this._nPages;
+        
         let spacing = this.getSpacing();
         this._spacePerRow = this.getVItemSize() + spacing;
         // We want to contain the grid inside the parent box with padding
@@ -403,6 +415,19 @@ const IconGrid = new Lang.Class({
         this._spaceBetweenPages = availHeightPerPage - (this._rowsPerPage * (this.getVItemSize() + spacing) 
- spacing);
         this._spaceBetweenPagesTotal = this._spaceBetweenPages * (this._nPages);
         this._childrenPerPage = nColumns * this._rowsPerPage;
+        
+        global.log("nPages "  + this._nPages);
+        global.log("availHeightPerPage, availWidthPerPage")
+        // Take into account when the number of pages changed (then the height of the entire grid changed 
for sure)
+        // and also when the spacing is changed, sure the hegiht per page changed and the entire grid height 
changes, althougt
+        // 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;
+            }));*/
+        }
     },
     
     _calculateChildrenBox: function(child, x, y, box) {
@@ -451,7 +476,7 @@ const IconGrid = new Lang.Class({
         this._vItemSize = themeNode.get_length('-shell-grid-vertical-item-size') || ICON_SIZE;
         this._grid.queue_relayout();
     },
-
+    
     columnsForWidth: function(rowWidth) {
         return this._computeLayout(rowWidth)[0];
     },
@@ -600,6 +625,7 @@ const IconGrid = new Lang.Class({
     calculateResponsiveGrid: function(availWidth, availHeight) {
         this._fixedHItemSize = this._hItemSize;
         this._fixedVItemSize = this._vItemSize;
+
         let spacing = this.maxSpacingForWidthHeight(availWidth, availHeight);
         this.setSpacing(spacing);
         if(this._useSurroundingSpacing)
@@ -641,6 +667,8 @@ const IconGrid = new Lang.Class({
         
         let scale = Math.min(this._fixedHItemSize, this._fixedVItemSize) / Math.max(this._hItemSize, 
this._vItemSize);
         this.updateChildrenScale(scale);
+        if(this._usePagination)
+            this._calculatePaginationValues(availWidth, availHeight);
     },
     /**
      * FLORIAN REVIEW
diff --git a/js/ui/searchDisplay.js b/js/ui/searchDisplay.js
index 2177874..9d47e44 100644
--- a/js/ui/searchDisplay.js
+++ b/js/ui/searchDisplay.js
@@ -320,7 +320,7 @@ 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) {


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