iconGrid: Dynamically adjust spacing based on columnLimit
Adjust the spacing based on the available width when a columnLimit is set to evenly place the icons. https://bugzilla.gnome.org/show_bug.cgi?id=694215
This commit is contained in:
parent
b75fc2bde3
commit
b922035d4f
@ -63,6 +63,9 @@ const AlphabeticalView = new Lang.Class({
|
|||||||
this._grid = new IconGrid.IconGrid({ xAlign: St.Align.MIDDLE,
|
this._grid = new IconGrid.IconGrid({ xAlign: St.Align.MIDDLE,
|
||||||
columnLimit: MAX_COLUMNS });
|
columnLimit: MAX_COLUMNS });
|
||||||
|
|
||||||
|
// Standard hack for ClutterBinLayout
|
||||||
|
this._grid.actor.x_expand = true;
|
||||||
|
|
||||||
this._items = {};
|
this._items = {};
|
||||||
this._allItems = [];
|
this._allItems = [];
|
||||||
},
|
},
|
||||||
|
@ -241,7 +241,7 @@ const IconGrid = new Lang.Class({
|
|||||||
let availWidth = box.x2 - box.x1;
|
let availWidth = box.x2 - box.x1;
|
||||||
let availHeight = box.y2 - box.y1;
|
let availHeight = box.y2 - box.y1;
|
||||||
|
|
||||||
let [nColumns, usedWidth] = this._computeLayout(availWidth);
|
let [nColumns, usedWidth, spacing] = this._computeLayout(availWidth);
|
||||||
|
|
||||||
let leftPadding;
|
let leftPadding;
|
||||||
switch(this._xAlign) {
|
switch(this._xAlign) {
|
||||||
@ -294,10 +294,10 @@ const IconGrid = new Lang.Class({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (columnIndex == 0) {
|
if (columnIndex == 0) {
|
||||||
y += this._vItemSize + this._spacing;
|
y += this._vItemSize + spacing;
|
||||||
x = box.x1 + leftPadding;
|
x = box.x1 + leftPadding;
|
||||||
} else {
|
} else {
|
||||||
x += this._hItemSize + this._spacing;
|
x += this._hItemSize + spacing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -313,16 +313,25 @@ 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;
|
||||||
|
|
||||||
|
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)) {
|
||||||
usedWidth += this._hItemSize + this._spacing;
|
usedWidth += this._hItemSize + spacing;
|
||||||
nColumns += 1;
|
nColumns += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nColumns > 0)
|
if (nColumns > 0)
|
||||||
usedWidth -= this._spacing;
|
usedWidth -= spacing;
|
||||||
|
|
||||||
return [nColumns, usedWidth];
|
return [nColumns, usedWidth, spacing];
|
||||||
},
|
},
|
||||||
|
|
||||||
_onStyleChanged: function() {
|
_onStyleChanged: function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user