[gnome-shell] Fall back to fewer than 4 columns if space limited
- From: Colin Walters <walters src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-shell] Fall back to fewer than 4 columns if space limited
- Date: Fri, 25 Sep 2009 01:42:29 +0000 (UTC)
commit 2020d15a1ae992d0ad63693afac76a1a9a06f724
Author: Marina Zhurakhinskaya <marinaz redhat com>
Date: Thu Sep 24 00:01:57 2009 -0400
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.
js/ui/appDisplay.js | 40 ++++++++++++++++++++++++----------------
1 files changed, 24 insertions(+), 16 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 9fff7cb..9e437c2 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -23,7 +23,7 @@ const ENTERED_MENU_COLOR = new Clutter.Color();
ENTERED_MENU_COLOR.from_pixel(0x00ff0022);
const WELL_DEFAULT_COLUMNS = 4;
-const WELL_ITEM_HSPACING = 0;
+const WELL_ITEM_MIN_HSPACING = 4;
const WELL_ITEM_VSPACING = 4;
const MENU_ICON_SIZE = 24;
@@ -628,9 +628,8 @@ WellGrid.prototype = {
nColumns = children.length;
else
nColumns = WELL_DEFAULT_COLUMNS;
- let spacing = Math.max(nColumns - 1, 0) * WELL_ITEM_HSPACING;
- alloc.min_size = itemMin * nColumns + spacing;
- alloc.natural_size = itemNatural * nColumns + spacing;
+ alloc.min_size = itemMin;
+ alloc.natural_size = itemNatural * nColumns;
},
_getPreferredHeight: function (grid, forWidth, alloc) {
@@ -678,7 +677,7 @@ WellGrid.prototype = {
y += itemHeight + WELL_ITEM_VSPACING;
x = box.x1;
} else {
- x += itemWidth + WELL_ITEM_HSPACING;
+ x += itemWidth;
}
if (atSeparator) {
@@ -728,19 +727,28 @@ WellGrid.prototype = {
let children = this._getItemChildren();
if (children.length == 0)
return [0, WELL_DEFAULT_COLUMNS, 0, 0];
- let nColumns;
- if (children.length < WELL_DEFAULT_COLUMNS)
- nColumns = children.length;
- else
+ let nColumns = 0;
+ let usedWidth = 0;
+ if (forWidth < 0) {
nColumns = WELL_DEFAULT_COLUMNS;
+ } else {
+ while (nColumns < WELL_DEFAULT_COLUMNS &&
+ nColumns < children.length &&
+ 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++;
+ }
+ }
- if (forWidth >= 0 && forWidth < minWidth) {
- log("WellGrid: trying to allocate for width " + forWidth + " but min is " + minWidth);
- /* FIXME - we should fall back to fewer than WELL_DEFAULT_COLUMNS here */
+ if (nColumns == 0) {
+ log("WellGrid: couldn't fit a column in width " + forWidth);
+ /* FIXME - fall back to smaller icon size */
}
- let horizSpacingTotal = Math.max(nColumns - 1, 0) * WELL_ITEM_HSPACING;
- let minWidth = itemMinWidth * nColumns + horizSpacingTotal;
+ let minWidth = itemMinWidth * nColumns;
let lastColumnIndex = nColumns - 1;
let separatorColumns = lastColumnIndex - ((lastColumnIndex + this._separatorIndex) % nColumns);
@@ -750,7 +758,7 @@ WellGrid.prototype = {
if (forWidth < 0) {
itemWidth = itemNaturalWidth;
} else {
- itemWidth = Math.max(forWidth - horizSpacingTotal, 0) / nColumns;
+ itemWidth = Math.floor(forWidth / nColumns);
}
let itemNaturalHeight = 0;
@@ -760,7 +768,7 @@ WellGrid.prototype = {
itemNaturalHeight = childNatural;
}
- return [rows, WELL_DEFAULT_COLUMNS, itemWidth, itemNaturalHeight];
+ return [rows, nColumns, itemWidth, itemNaturalHeight];
},
_getItemPreferredWidth: function () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]