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
This commit is contained in:
parent
cc5198205d
commit
cfb80266c2
@ -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);
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user