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,
|
let nColumns = this._colLimit ? Math.min(this._colLimit,
|
||||||
nChildren)
|
nChildren)
|
||||||
: 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
|
// Kind of a lie, but not really an issue right now. If
|
||||||
// we wanted to support some sort of hidden/overflow that would
|
// we wanted to support some sort of hidden/overflow that would
|
||||||
// need higher level design
|
// need higher level design
|
||||||
@ -231,13 +231,11 @@ const IconGrid = new Lang.Class({
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
let children = this._getVisibleChildren();
|
let children = this._getVisibleChildren();
|
||||||
let nColumns, spacing;
|
let nColumns;
|
||||||
if (forWidth < 0) {
|
if (forWidth < 0)
|
||||||
nColumns = children.length;
|
nColumns = children.length;
|
||||||
spacing = this._spacing;
|
else
|
||||||
} else {
|
[nColumns, ] = this._computeLayout(forWidth);
|
||||||
[nColumns, , spacing] = this._computeLayout(forWidth);
|
|
||||||
}
|
|
||||||
|
|
||||||
let nRows;
|
let nRows;
|
||||||
if (nColumns > 0)
|
if (nColumns > 0)
|
||||||
@ -246,7 +244,7 @@ const IconGrid = new Lang.Class({
|
|||||||
nRows = 0;
|
nRows = 0;
|
||||||
if (this._rowLimit)
|
if (this._rowLimit)
|
||||||
nRows = Math.min(nRows, 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;
|
let height = nRows * this._vItemSize + totalSpacing;
|
||||||
alloc.min_size = height;
|
alloc.min_size = height;
|
||||||
alloc.natural_size = height;
|
alloc.natural_size = height;
|
||||||
@ -263,8 +261,9 @@ const IconGrid = new Lang.Class({
|
|||||||
let children = this._getVisibleChildren();
|
let children = this._getVisibleChildren();
|
||||||
let availWidth = box.x2 - box.x1;
|
let availWidth = box.x2 - box.x1;
|
||||||
let availHeight = box.y2 - box.y1;
|
let availHeight = box.y2 - box.y1;
|
||||||
|
this.updateSpacingForSize(availWidth);
|
||||||
let [nColumns, usedWidth, spacing] = this._computeLayout(availWidth);
|
let spacing = this._getSpacing();
|
||||||
|
let [nColumns, usedWidth] = this._computeLayout(availWidth);
|
||||||
|
|
||||||
let leftPadding;
|
let leftPadding;
|
||||||
switch(this._xAlign) {
|
switch(this._xAlign) {
|
||||||
@ -342,14 +341,7 @@ const IconGrid = new Lang.Class({
|
|||||||
_computeLayout: function (forWidth) {
|
_computeLayout: function (forWidth) {
|
||||||
let nColumns = 0;
|
let nColumns = 0;
|
||||||
let usedWidth = 0;
|
let usedWidth = 0;
|
||||||
let spacing = this._spacing;
|
let spacing = this._getSpacing();
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((this._colLimit == null || nColumns < this._colLimit) &&
|
while ((this._colLimit == null || nColumns < this._colLimit) &&
|
||||||
(usedWidth + this._hItemSize <= forWidth)) {
|
(usedWidth + this._hItemSize <= forWidth)) {
|
||||||
@ -360,7 +352,7 @@ const IconGrid = new Lang.Class({
|
|||||||
if (nColumns > 0)
|
if (nColumns > 0)
|
||||||
usedWidth -= spacing;
|
usedWidth -= spacing;
|
||||||
|
|
||||||
return [nColumns, usedWidth, spacing];
|
return [nColumns, usedWidth];
|
||||||
},
|
},
|
||||||
|
|
||||||
_onStyleChanged: function() {
|
_onStyleChanged: function() {
|
||||||
@ -388,5 +380,25 @@ const IconGrid = new Lang.Class({
|
|||||||
|
|
||||||
visibleItemsCount: function() {
|
visibleItemsCount: function() {
|
||||||
return this._grid.get_n_children() - this._grid.get_n_skip_paint();
|
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…
x
Reference in New Issue
Block a user