[gnome-shell/wip/paging-release: 12/74] spacing calculated on AppDisplay



commit a21af91dcf52d5508a93d08feb9040a956f31243
Author: Carlos Soriano <carlos soriano89 gmail com>
Date:   Thu Jul 4 17:54:47 2013 +0200

    spacing calculated on AppDisplay

 js/ui/appDisplay.js |  100 +++++++++++++++++++++++++++++++++++++++++++--------
 js/ui/iconGrid.js   |   19 ++++++++--
 2 files changed, 101 insertions(+), 18 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 8f18287..f91dc8e 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -135,7 +135,7 @@ const FolderView = new Lang.Class({
         this._widget.add_actor(this._grid.actor);
         this._box.add(this._widget, { expand: true });
         this.actor.add_actor(this._box);
-        this.actor.connect('notify::allocation', Lang.bind(this, this._calculateGridSpacing));
+        //this.actor.connect('notify::allocation', Lang.bind(this, this._calculateGridSpacing));
         this._items = {};
         this._allItems = [];
     },
@@ -218,6 +218,15 @@ const FolderView = new Lang.Class({
                 continue;
             this._grid.addItem(this._items[id].actor);
         }
+    },
+    
+    updateSpacing: function(width) {
+        let itemWidth = this._grid._hItemSize * MAX_COLUMNS;
+        let emptyArea = width - itemWidth;
+        let spacing;
+        spacing = Math.max(this._grid._spacing, emptyArea / ( 2 *  MAX_COLUMNS));
+        spacing = Math.round(spacing);
+        this._grid.setSpacing(spacing);
     }
 });
 
@@ -229,7 +238,8 @@ const AppPages = new Lang.Class({
         this.parent();
         this.actor = this._grid.actor;
         this._parent = parent;
-        this.actor.connect('notify::allocation', Lang.bind(this, this._calculateGridSpacing));
+        this._folderIcons = [];
+        //this.actor.connect('notify::allocation', Lang.bind(this, this._calculateGridSpacing));
     },
     
     _calculateGridSpacing: function(actor, params) {
@@ -267,9 +277,11 @@ const AppPages = new Lang.Class({
     _createItemIcon: function(item) {
         if (item instanceof Shell.App)
             return new AppIcon(item);
-        else if (item instanceof GMenu.TreeDirectory)
-            return new FolderIcon(item, this);
-        else
+        else if (item instanceof GMenu.TreeDirectory) {
+            let folderIcon = new FolderIcon(item, this);
+            this._folderIcons.push(folderIcon);
+            return folderIcon;
+        } else
             return null;
     },
 
@@ -281,10 +293,6 @@ const AppPages = new Lang.Class({
         return (nameA > nameB) ? 1 : (nameA < nameB ? -1 : 0);
     },
     
-    getSpacing: function() {
-        return this._grid.getSpacing()
-    },
-    
     updateIconOpacities: function(folderOpen) {
         for (let id in this._items) {
             if (folderOpen && !this._items[id].actor.checked)
@@ -312,6 +320,24 @@ const AppPages = new Lang.Class({
     
     addFolderPopup: function(popup) {
         this._parent.addFolderPopup(popup);
+    },
+    
+    removeAll: function() {
+        this._folderIcons = [];
+        this.parent();
+    },
+    
+    updateSpacing: function(width) {
+        let itemWidth = this._grid._hItemSize * MAX_COLUMNS;
+        let emptyArea = width - itemWidth;
+        let spacing;
+        spacing = Math.max(this._grid._spacing, emptyArea / ( 2 *  MAX_COLUMNS));
+        spacing = Math.round(spacing);
+        this._grid.setSpacing(spacing);
+        for(let id in this._folderIcons) {
+            global.log("FOLDER ICON " + this._folderIcons[id]);
+            this._folderIcons[id].updateFolderViewSpacing(width);
+        }
     }
 });
 
@@ -504,6 +530,10 @@ const PaginationScrollView = new Lang.Class({
             }
         } else
             this._parent.goToPage(this._currentPage, action);
+    },
+    
+    updateSpacing: function(width) {
+        this._pages.updateSpacing(width);
     }
     
 });
@@ -677,6 +707,10 @@ const AllView = new Lang.Class({
         this._paginationIndicator.get_child_at_index(this._paginationView.currentPage()).set_checked(false);
         this._paginationView.goToPage(index, action);
         this._paginationIndicator.get_child_at_index(this._paginationView.currentPage()).set_checked(true);
+    },
+    
+    updateSpacing: function(width) {
+        this._paginationView.updateSpacing(width);
     }
 });
 
@@ -692,7 +726,7 @@ const FrequentView = new Lang.Class({
         this.actor.add_actor(this._grid.actor);
 
         this._usage = Shell.AppUsage.get_default();
-        this.actor.connect('notify::allocation', Lang.bind(this, this._calculateGridSpacing));
+        //this.actor.connect('notify::allocation', Lang.bind(this, this._calculateGridSpacing));
     },
     
     _calculateGridSpacing: function(actor, params) {
@@ -703,7 +737,7 @@ const FrequentView = new Lang.Class({
         let spacing;
         spacing = Math.max(this._grid._spacing, emptyArea / ( 2 *  MAX_COLUMNS));
         spacing = Math.round(spacing);
-        this._grid.setSpacing(spacing);
+        
         /*
         if(this._grid.getSpacing() != spacing) {
             this._grid.setSpacing(spacing);
@@ -729,6 +763,15 @@ const FrequentView = new Lang.Class({
             let appIcon = new AppIcon(mostUsed[i]);
             this._grid.addItem(appIcon.actor, -1);
         }
+    },
+    
+    updateSpacing: function(width) {
+        let itemWidth = this._grid._hItemSize * MAX_COLUMNS;
+        let emptyArea = width - itemWidth;
+        let spacing;
+        spacing = Math.max(this._grid._spacing, emptyArea / ( 2 *  MAX_COLUMNS));
+        spacing = Math.round(spacing);
+        this._grid.setSpacing(spacing);
     }
 });
 
@@ -762,6 +805,20 @@ const ControlsBoxLayout = Lang.Class({
     }
 });
 
+const AppDisplayActor = new Lang.Class({
+    Name: 'AppDisplayActor',
+    Extends: St.BoxLayout,
+    
+    vfunc_allocate: function (box, flags) {
+        let availWidth = box.x2 - box.x1;
+        global.log("Signal to emit " + availWidth);
+        this.emit('allocated-width-changed', availWidth);
+        global.log("Signal emitted " + availWidth);
+        this.parent(box, flags);
+    }
+});
+Signals.addSignalMethods(AppDisplayActor.prototype);
+
 const AppDisplay = new Lang.Class({
     Name: 'AppDisplay',
 
@@ -797,9 +854,10 @@ const AppDisplay = new Lang.Class({
                                  x_expand: true });
         this._views[Views.ALL] = { 'view': view, 'control': button };
 
-        this.actor = new St.BoxLayout({ style_class: 'app-display',
+        this.actor = new AppDisplayActor({ style_class: 'app-display',
                                         vertical: true,
                                         x_expand: true, y_expand: true });
+        this.actor.connect('allocated-width-changed', Lang.bind(this, this._updateViewsSpacing));
 
         this._viewStack = new St.Widget({ layout_manager: new Clutter.BinLayout(),
                                           x_expand: true, y_expand: true });
@@ -910,6 +968,14 @@ const AppDisplay = new Lang.Class({
             if (focused)
                 this.actor.navigate_focus(null, Gtk.DirectionType.TAB_FORWARD, false);
         }
+    },
+    
+    _updateViewsSpacing: function(actor, width) {
+        global.log("AppDsplay updating..-");
+        for (let i = 0; i < this._views.length; i++) {
+            this._views[i].view.updateSpacing(width);
+        }
+        global.log("AppDsplay End updating..-");
     }
 });
 
@@ -974,7 +1040,6 @@ const FolderIcon = new Lang.Class({
 
     _init: function(dir, parentView) {
         this._dir = dir;
-        this._parentView = parentView;
 
         this.actor = new St.Button({ style_class: 'app-well-app app-folder',
                                      button_mask: St.ButtonMask.ONE,
@@ -983,6 +1048,7 @@ const FolderIcon = new Lang.Class({
                                      x_fill: true,
                                      y_fill: true });
         this.actor._delegate = this;
+        this._parentView = parentView;
 
         let label = this._dir.get_name();
         this.icon = new IconGrid.BaseIcon(label,
@@ -990,7 +1056,7 @@ const FolderIcon = new Lang.Class({
         this.actor.set_child(this.icon.actor);
         this.actor.label_actor = this.icon.label;
 
-        this.view = new FolderView(parentView);
+        this.view = new FolderView();
         this.view.actor.reactive = false;
         _loadCategory(dir, this.view);
         this.view.loadGrid();
@@ -1008,7 +1074,7 @@ const FolderIcon = new Lang.Class({
     },
 
     _createIcon: function(size) {
-        return this.view.createFolderIcon(size);
+        return this.view.createFolderIcon(size, this);
     },
 
     _ensurePopup: function() {
@@ -1041,6 +1107,10 @@ const FolderIcon = new Lang.Class({
                     this.actor.checked = false;
             }));
     },
+    
+    updateFolderViewSpacing: function(width) {
+        this.view.updateSpacing(width);
+    }
 });
 
 const AppFolderPopup = new Lang.Class({
diff --git a/js/ui/iconGrid.js b/js/ui/iconGrid.js
index 7566a31..99196db 100644
--- a/js/ui/iconGrid.js
+++ b/js/ui/iconGrid.js
@@ -300,6 +300,7 @@ const IconGrid = new Lang.Class({
             if (this._rowLimit)
                 nRows = Math.min(nRows, this._rowLimit);
             let oldNPages = this._nPages;
+            global.log("NPAGES!!! " + this._nPages);
             this._calculatePaginationValues(availHeightPerPage, nColumns, nRows);
             if(oldNPages != this._nPages) {
                 global.log("Next relayout");
@@ -335,13 +336,15 @@ const IconGrid = new Lang.Class({
             let childBox = this._calculateChildrenBox(children[i], x, y);
             if(!this._usePagination) {
                 if (this._rowLimit && rowIndex >= this._rowLimit ||
-                        this._fillParent && childBox.y2 > availHeight) {
+                        this._fillParent && childBox.y2 >= availHeight) {
                     this._grid.set_skip_paint(children[i], true);
                 } else {
+                    global.log("childBox.y2 "+ [childBox.y1, childBox.y2, availHeight]);
                     children[i].allocate(childBox, flags);
                     this._grid.set_skip_paint(children[i], false);
                 }
             } else {
+                global.log("PAginatio childBox.y2 "+ [childBox.y1, childBox.y2, availHeight]);
                 children[i].allocate(childBox, flags);
                 this._grid.set_skip_paint(children[i], false);
             }
@@ -372,8 +375,18 @@ const IconGrid = new Lang.Class({
     
     _calculatePaginationValues: function (availHeightPerPage, nColumns, nRows) {
         let spacing = this._fixedSpacing ? this._fixedSpacing : this._spacing;
+        global.log("### CALCULATING PAGES ###");
+        global.log("availHeightPerPage "+ availHeightPerPage);
+        global.log("nColumns "+ nColumns);
+        global.log("nRows "+ nRows);
+        global.log("spacing "+ spacing);
         this._spacePerRow = this._vItemSize + spacing;
+        global.log("this._spacePerRow "+ this._spacePerRow);
         this._rowsPerPage = Math.floor(availHeightPerPage / this._spacePerRow);
+        // Check if deleting spacing from bottom there's enough space for another row
+        let spaceWithOneMoreRow = (this._rowsPerPage + 1) * this._spacePerRow - spacing;
+        this._rowsPerPage = spaceWithOneMoreRow <= availHeightPerPage? this._rowsPerPage + 1 : 
this._rowsPerPage;
+        global.log("this._rowsPerPage "+ this._rowsPerPage);
         this._nPages = Math.ceil(nRows / this._rowsPerPage);
         this._spaceBetweenPages = availHeightPerPage - (this._rowsPerPage * (this._vItemSize + spacing));
         this._spaceBetweenPagesTotal = this._spaceBetweenPages * (this._nPages);
@@ -472,10 +485,10 @@ const IconGrid = new Lang.Class({
     setSpacing: function(spacing) {
         if(this._fixedSpacing != spacing) {
             this._fixedSpacing = spacing;
-            Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this, function() {
+            /*Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this, function() {
                 this._grid.queue_relayout();
                 return false;
-            }));
+            }));*/
         }
         
     },


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