[gnome-shell/wip/paging-release2: 8/23] iconGrid: Use minimum rows/columns properties to adjust spacing



commit e46b308b8f180fa640ebeb3a6bddf0dbfee18126
Author: Carlos Soriano <carlos soriano89 gmail com>
Date:   Tue Aug 27 21:23:13 2013 +0200

    iconGrid: Use minimum rows/columns properties to adjust spacing
    
    Use properties to allow iconGrid satisfy the rows/columns
    minima properties reducing spacing acordingly.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=706081

 js/ui/appDisplay.js |    4 ++++
 js/ui/iconGrid.js   |   35 +++++++++++++++++++++++++----------
 2 files changed, 29 insertions(+), 10 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index dfe09bd..7300c85 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -30,6 +30,8 @@ const Util = imports.misc.util;
 const MAX_APPLICATION_WORK_MILLIS = 75;
 const MENU_POPUP_TIMEOUT = 600;
 const MAX_COLUMNS = 6;
+const MIN_COLUMNS = 4;
+const MIN_ROWS = 4;
 
 const INACTIVE_GRID_OPACITY = 77;
 const INACTIVE_GRID_OPACITY_ANIMATION_TIME = 0.15;
@@ -63,6 +65,8 @@ const AlphabeticalView = new Lang.Class({
     _init: function(params, gridParams) {
         gridParams = Params.parse(gridParams, { xAlign: St.Align.MIDDLE,
                                                 columnLimit: MAX_COLUMNS,
+                                                minRows: MIN_ROWS,
+                                                minColumns: MIN_COLUMNS,
                                                 fillParent: false });
         params = Params.parse(params, { usePagination: false });
         
diff --git a/js/ui/iconGrid.js b/js/ui/iconGrid.js
index e118f2d..ce00787 100644
--- a/js/ui/iconGrid.js
+++ b/js/ui/iconGrid.js
@@ -176,10 +176,14 @@ 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 });
         this._rowLimit = params.rowLimit;
         this._colLimit = params.columnLimit;
+        this._minRows = params.minRows;
+        this._minColumns = params.minColumns;
         this._xAlign = params.xAlign;
         this._fillParent = params.fillParent;
 
@@ -397,16 +401,27 @@ const IconGrid = new Lang.Class({
      * This function must to be called before iconGrid allocation,
      * to know how much spacing can the grid has
      */
-    updateSpacingForSize: function(availWidth) {
-        let spacing = this._spacing;
-
-        if (this._colLimit) {
-            let itemWidth = this._hItemSize * this._colLimit;
-            let emptyArea = availWidth - itemWidth;
-            spacing = Math.max(spacing, emptyArea / (2 * this._colLimit));
-            spacing = Math.round(spacing);
-        }
-        this.setSpacing(spacing);
+    updateSpacingForSize: function(availWidth, availHeight) {
+
+        let maxEmptyVArea = availHeight - this._minRows * this._vItemSize;
+        let maxEmptyHArea = availWidth - this._minColumns * this._hItemSize;
+        let maxHSpacing, maxVSpacing;
+        if (this._minRows == 1)
+            maxVSpacing = maxEmptyVArea;
+        else
+            maxVSpacing = Math.floor(maxEmptyVArea / (this._minRows - 1));
+
+        if (this._minColumns == 1)
+            maxHSpacing = maxEmptyHArea;
+        else
+            maxHSpacing = Math.floor(maxEmptyHArea / (this._minColumns - 1));
+
+        let maxSpacing = Math.min(maxHSpacing, maxVSpacing);
+        // Limit spacing to the item size
+        maxSpacing = Math.min(maxSpacing, Math.min(this._vItemSize, this._hItemSize));
+        // The minimum spacing, regardless it doesn't achieve the row/columng minima,
+        // is the spacing we get from CSS.
+        this.setSpacing(Math.max(this._spacing, maxSpacing));
     },
 });
 


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