Fall back to fewer than 4 columns if space limited

First eliminate the variable WELL_ITEM_HSPACING since it was 0
and thus effectively was not used.

Add a new variable WELL_ITEM_MIN_HSPACING which is the minimum
space between grid items we allow.  When computing layout, allow
for a number of columns less than 4 by using the minimum item
size.

https://bugzilla.gnome.org/show_bug.cgi?id=595023

Based on a patch from Colin Walters.
This commit is contained in:
Marina Zhurakhinskaya 2009-09-24 00:01:57 -04:00 committed by Colin Walters
parent 64d8d7a91c
commit 2020d15a1a

View File

@ -23,7 +23,7 @@ const ENTERED_MENU_COLOR = new Clutter.Color();
ENTERED_MENU_COLOR.from_pixel(0x00ff0022); ENTERED_MENU_COLOR.from_pixel(0x00ff0022);
const WELL_DEFAULT_COLUMNS = 4; const WELL_DEFAULT_COLUMNS = 4;
const WELL_ITEM_HSPACING = 0; const WELL_ITEM_MIN_HSPACING = 4;
const WELL_ITEM_VSPACING = 4; const WELL_ITEM_VSPACING = 4;
const MENU_ICON_SIZE = 24; const MENU_ICON_SIZE = 24;
@ -628,9 +628,8 @@ WellGrid.prototype = {
nColumns = children.length; nColumns = children.length;
else else
nColumns = WELL_DEFAULT_COLUMNS; nColumns = WELL_DEFAULT_COLUMNS;
let spacing = Math.max(nColumns - 1, 0) * WELL_ITEM_HSPACING; alloc.min_size = itemMin;
alloc.min_size = itemMin * nColumns + spacing; alloc.natural_size = itemNatural * nColumns;
alloc.natural_size = itemNatural * nColumns + spacing;
}, },
_getPreferredHeight: function (grid, forWidth, alloc) { _getPreferredHeight: function (grid, forWidth, alloc) {
@ -678,7 +677,7 @@ WellGrid.prototype = {
y += itemHeight + WELL_ITEM_VSPACING; y += itemHeight + WELL_ITEM_VSPACING;
x = box.x1; x = box.x1;
} else { } else {
x += itemWidth + WELL_ITEM_HSPACING; x += itemWidth;
} }
if (atSeparator) { if (atSeparator) {
@ -728,19 +727,28 @@ WellGrid.prototype = {
let children = this._getItemChildren(); let children = this._getItemChildren();
if (children.length == 0) if (children.length == 0)
return [0, WELL_DEFAULT_COLUMNS, 0, 0]; return [0, WELL_DEFAULT_COLUMNS, 0, 0];
let nColumns; let nColumns = 0;
if (children.length < WELL_DEFAULT_COLUMNS) let usedWidth = 0;
nColumns = children.length; if (forWidth < 0) {
else
nColumns = WELL_DEFAULT_COLUMNS; nColumns = WELL_DEFAULT_COLUMNS;
} else {
if (forWidth >= 0 && forWidth < minWidth) { while (nColumns < WELL_DEFAULT_COLUMNS &&
log("WellGrid: trying to allocate for width " + forWidth + " but min is " + minWidth); nColumns < children.length &&
/* FIXME - we should fall back to fewer than WELL_DEFAULT_COLUMNS here */ usedWidth + itemMinWidth <= forWidth) {
// By including WELL_ITEM_MIN_HSPACING in usedWidth, we are ensuring
// that the number of columns we end up with will allow the spacing
// between the columns to be at least that value.
usedWidth += itemMinWidth + WELL_ITEM_MIN_HSPACING;
nColumns++;
}
} }
let horizSpacingTotal = Math.max(nColumns - 1, 0) * WELL_ITEM_HSPACING; if (nColumns == 0) {
let minWidth = itemMinWidth * nColumns + horizSpacingTotal; log("WellGrid: couldn't fit a column in width " + forWidth);
/* FIXME - fall back to smaller icon size */
}
let minWidth = itemMinWidth * nColumns;
let lastColumnIndex = nColumns - 1; let lastColumnIndex = nColumns - 1;
let separatorColumns = lastColumnIndex - ((lastColumnIndex + this._separatorIndex) % nColumns); let separatorColumns = lastColumnIndex - ((lastColumnIndex + this._separatorIndex) % nColumns);
@ -750,7 +758,7 @@ WellGrid.prototype = {
if (forWidth < 0) { if (forWidth < 0) {
itemWidth = itemNaturalWidth; itemWidth = itemNaturalWidth;
} else { } else {
itemWidth = Math.max(forWidth - horizSpacingTotal, 0) / nColumns; itemWidth = Math.floor(forWidth / nColumns);
} }
let itemNaturalHeight = 0; let itemNaturalHeight = 0;
@ -760,7 +768,7 @@ WellGrid.prototype = {
itemNaturalHeight = childNatural; itemNaturalHeight = childNatural;
} }
return [rows, WELL_DEFAULT_COLUMNS, itemWidth, itemNaturalHeight]; return [rows, nColumns, itemWidth, itemNaturalHeight];
}, },
_getItemPreferredWidth: function () { _getItemPreferredWidth: function () {