iconGrid: Account for non-icon content and padding/spacing when scaling

_updateIconSizes() was assuming that the icon is the only content of
an item when scaling the icon size to ensure the item size matches
_fixedHItemSize/_fixedVItemSize. However the icon may have padding and
there might be a label and spacing between the icon and the label. This
resulted in items being larger than their slots.

Fixes https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/2234
This commit is contained in:
Sebastian Keller 2020-07-19 14:41:18 +02:00 committed by Florian Müllner
parent ab59b74124
commit 6b86b6a3e2

View File

@ -845,8 +845,10 @@ var IconGrid = GObject.registerClass({
// Note that this is ICON_SIZE as used by BaseIcon, not elsewhere in IconGrid; it's a bit messed up // Note that this is ICON_SIZE as used by BaseIcon, not elsewhere in IconGrid; it's a bit messed up
_updateIconSizes() { _updateIconSizes() {
this._updateIconSizesLaterId = 0; this._updateIconSizesLaterId = 0;
let scale = Math.min(this._fixedHItemSize, this._fixedVItemSize) / Math.max(this._hItemSize, this._vItemSize); let extraWidth = Math.max(0, this._hItemSize - ICON_SIZE);
let newIconSize = Math.floor(ICON_SIZE * scale); let extraHeight = Math.max(0, this._vItemSize - ICON_SIZE);
let newIconSize = Math.min(this._fixedHItemSize - extraWidth,
this._fixedVItemSize - extraHeight);
for (let i in this._items) for (let i in this._items)
this._items[i].icon.setIconSize(newIconSize); this._items[i].icon.setIconSize(newIconSize);