[gnome-shell/wip/paging-release2: 2/23] iconGrid: Move spacing calculation to its own function
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/paging-release2: 2/23] iconGrid: Move spacing calculation to its own function
- Date: Mon, 2 Sep 2013 14:30:57 +0000 (UTC)
commit 33964279309fa323bbd201c93fbedf832d4c4654
Author: Carlos Soriano <carlos soriano89 gmail com>
Date: Wed Aug 21 19:31:09 2013 +0200
iconGrid: Move spacing calculation to its own function
Move spacing calculation to a function, which makes
it reusable and overwritable by subclasses
https://bugzilla.gnome.org/show_bug.cgi?id=706081
js/ui/iconGrid.js | 50 +++++++++++++++++++++++++++++++-------------------
1 files changed, 31 insertions(+), 19 deletions(-)
---
diff --git a/js/ui/iconGrid.js b/js/ui/iconGrid.js
index cb8cbf8..9ed82ba 100644
--- a/js/ui/iconGrid.js
+++ b/js/ui/iconGrid.js
@@ -208,7 +208,7 @@ const IconGrid = new Lang.Class({
let nColumns = this._colLimit ? Math.min(this._colLimit,
nChildren)
: nChildren;
- let totalSpacing = Math.max(0, nColumns - 1) * this._spacing;
+ let totalSpacing = Math.max(0, nColumns - 1) * this._getSpacing();
// 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
@@ -231,13 +231,11 @@ const IconGrid = new Lang.Class({
return;
let children = this._getVisibleChildren();
- let nColumns, spacing;
- if (forWidth < 0) {
+ let nColumns;
+ if (forWidth < 0)
nColumns = children.length;
- spacing = this._spacing;
- } else {
- [nColumns, , spacing] = this._computeLayout(forWidth);
- }
+ else
+ [nColumns, ] = this._computeLayout(forWidth);
let nRows;
if (nColumns > 0)
@@ -246,7 +244,7 @@ const IconGrid = new Lang.Class({
nRows = 0;
if (this._rowLimit)
nRows = Math.min(nRows, this._rowLimit);
- let totalSpacing = Math.max(0, nRows - 1) * spacing;
+ let totalSpacing = Math.max(0, nRows - 1) * this._getSpacing();
let height = nRows * this._vItemSize + totalSpacing;
alloc.min_size = height;
alloc.natural_size = height;
@@ -263,8 +261,9 @@ const IconGrid = new Lang.Class({
let children = this._getVisibleChildren();
let availWidth = box.x2 - box.x1;
let availHeight = box.y2 - box.y1;
-
- let [nColumns, usedWidth, spacing] = this._computeLayout(availWidth);
+ this.updateSpacingForSize(availWidth);
+ let spacing = this._getSpacing();
+ let [nColumns, usedWidth] = this._computeLayout(availWidth);
let leftPadding;
switch(this._xAlign) {
@@ -342,14 +341,7 @@ 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);
- }
+ let spacing = this._getSpacing();
while ((this._colLimit == null || nColumns < this._colLimit) &&
(usedWidth + this._hItemSize <= forWidth)) {
@@ -360,7 +352,7 @@ const IconGrid = new Lang.Class({
if (nColumns > 0)
usedWidth -= spacing;
- return [nColumns, usedWidth, spacing];
+ return [nColumns, usedWidth];
},
_onStyleChanged: function() {
@@ -388,5 +380,25 @@ const IconGrid = new Lang.Class({
visibleItemsCount: function() {
return this._grid.get_n_children() - this._grid.get_n_skip_paint();
+ },
+
+ setSpacing: function(spacing) {
+ this._fixedSpacing = spacing;
+ },
+
+ _getSpacing: function() {
+ return this._fixedSpacing ? this._fixedSpacing : this._spacing;
+ },
+
+ 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);
}
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]