[gnome-shell/wip/paging] Calculation os spacing on each iconGrid parent
- From: Carlos Soriano <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/paging] Calculation os spacing on each iconGrid parent
- Date: Thu, 4 Jul 2013 12:55:20 +0000 (UTC)
commit ce364e939d3ebe1f4f5eaf1bfb35f2f6c70bc03e
Author: Carlos Soriano <carlos soriano89 gmail com>
Date: Thu Jul 4 14:53:24 2013 +0200
Calculation os spacing on each iconGrid parent
data/theme/gnome-shell.css | 4 +-
js/ui/appDisplay.js | 99 ++++++++++++++++++++++++++++++++++++-------
js/ui/boxpointer.js | 2 +-
js/ui/iconGrid.js | 88 +++++++++++++++++++-------------------
4 files changed, 130 insertions(+), 63 deletions(-)
---
diff --git a/data/theme/gnome-shell.css b/data/theme/gnome-shell.css
index 4576683..b298798 100644
--- a/data/theme/gnome-shell.css
+++ b/data/theme/gnome-shell.css
@@ -899,8 +899,8 @@ StScrollBar StButton#vhandle:active {
}
.search-display > StBoxLayout,
-.all-apps > StBoxLayout,
-.frequent-apps > StBoxLayout {
+.all-apps,
+.frequent-apps {
/* horizontal padding to make sure scrollbars or dash don't overlap content */
padding: 0px 88px;
}
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 926ab8c..afc38e4 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -122,11 +122,13 @@ const AlphabeticalView = new Lang.Class({
const FolderView = new Lang.Class({
Name: 'FolderView',
- _init: function() {
+ _init: function(parentView) {
this._grid = new IconGrid.IconGrid({ xAlign: St.Align.MIDDLE,
columnLimit: MAX_COLUMNS });
// Standard hack for ClutterBinLayout
this._grid.actor.x_expand = true;
+ this._parentView = parentView;
+
this.actor = new St.ScrollView({x_expand: true, y_expand:true, y_fill: true, x_fill:true,
overlay_scrollbars: true});
this.actor.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
this._box = new St.BoxLayout({vertical:true});
@@ -134,11 +136,26 @@ const FolderView = new Lang.Class({
this._widget.add_actor(this._grid.actor);
this._box.add(this._widget, { expand: true });
this.actor.add_actor(this._box);
- this.actor.set_size(1200, 800);
-
+ this.actor.connect('notify::allocation', Lang.bind(this, this._calculateGridSpacing));
this._items = {};
this._allItems = [];
},
+
+ _calculateGridSpacing: function(actor, params) {
+ this._grid.setSpacing(this._parentView.getSpacing());
+ //this.actor.queue_relayout();
+ /*
+ if(this._grid.getSpacing() != spacing) {
+ this._grid.setSpacing(spacing);
+ global.log("Frequent view Diferent");
+ global.log("Frequent view spacing " + spacing);
+ Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this, function() {
+ this.actor.queue_relayout();
+ return false;
+ }));
+ } else
+ global.log("Frequent view NO Diferent " + spacing);*/
+ },
_getItemId: function(item) {
return item.get_id();
@@ -213,6 +230,30 @@ const AppPages = new Lang.Class({
this.parent();
this.actor = this._grid.actor;
this._parent = parent;
+ this.actor.connect('notify::allocation', Lang.bind(this, this._calculateGridSpacing));
+ },
+
+ _calculateGridSpacing: function(actor, params) {
+
+ let availWidth = actor.allocation.x2 - actor.allocation.x1;
+ global.log("All view alloc " + availWidth);
+ let itemWidth = this._grid._hItemSize * MAX_COLUMNS;
+ let emptyArea = availWidth - itemWidth;
+ let spacing;
+ spacing = Math.max(this._grid._spacing, emptyArea / ( 2 * MAX_COLUMNS));
+ spacing = Math.round(spacing);
+ this._grid.setSpacing(spacing);
+ /*
+ if(this._grid.getSpacing() != spacing) {
+ this._grid.setSpacing(spacing);
+ global.log("All view Diferent");
+ global.log("All view spacing " + spacing);
+ Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this, function() {
+ this.actor.queue_relayout();
+ return false;
+ }));
+ } else
+ global.log("All view NO Diferent " + spacing);*/
},
_getItemId: function(item) {
@@ -240,7 +281,20 @@ const AppPages = new Lang.Class({
let nameB = GLib.utf8_collate_key(itemB.get_name(), -1);
return (nameA > nameB) ? 1 : (nameA < nameB ? -1 : 0);
},
-
+
+ getSpacing: function() {
+ return this._grid.getSpacing()
+ },
+
+ updateIconOpacities: function(folderOpen) {
+ for (let id in this._items) {
+ if (folderOpen && !this._items[id].actor.checked)
+ this._items[id].actor.opacity = INACTIVE_GRID_OPACITY;
+ else
+ this._items[id].actor.opacity = 255;
+ }
+ },
+
addItem: function(item) {
this._addItem(item);
},
@@ -424,24 +478,14 @@ const PaginationScrollView = new Lang.Class({
},
addFolderPopup: function(popup) {
- //popup.actor.set_width(1100);
this._stack.add_actor(popup.actor);
popup.connect('open-state-changed', Lang.bind(this,
function(popup, isOpen) {
this._eventBlocker.reactive = isOpen;
this._currentPopup = isOpen ? popup : null;
- this._updateIconOpacities(isOpen);
+ this._pages.updateIconOpacities(isOpen);
}));
},
-
- _updateIconOpacities: function(folderOpen) {
- for (let id in this._items) {
- if (folderOpen && !this._items[id].actor.checked)
- this._items[id].actor.opacity = INACTIVE_GRID_OPACITY;
- else
- this._items[id].actor.opacity = 255;
- }
- },
_onPan: function(action) {
this._clickAction.release();
@@ -642,6 +686,29 @@ const FrequentView = new Lang.Class({
this.actor.add_actor(this._grid.actor);
this._usage = Shell.AppUsage.get_default();
+ this.actor.connect('notify::allocation', Lang.bind(this, this._calculateGridSpacing));
+ },
+
+ _calculateGridSpacing: function(actor, params) {
+ let availWidth = actor.allocation.x2 - actor.allocation.x1;
+ global.log("frequent view alloc " + availWidth);
+ let itemWidth = this._grid._hItemSize * MAX_COLUMNS;
+ let emptyArea = availWidth - itemWidth;
+ let spacing;
+ spacing = Math.max(this._grid._spacing, emptyArea / ( 2 * MAX_COLUMNS));
+ spacing = Math.round(spacing);
+ this._grid.setSpacing(spacing);
+ /*
+ if(this._grid.getSpacing() != spacing) {
+ this._grid.setSpacing(spacing);
+ global.log("Frequent view Diferent");
+ global.log("Frequent view spacing " + spacing);
+ Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this, function() {
+ this.actor.queue_relayout();
+ return false;
+ }));
+ } else
+ global.log("Frequent view NO Diferent " + spacing);*/
},
removeAll: function() {
@@ -927,7 +994,7 @@ const FolderIcon = new Lang.Class({
this.actor.set_child(this.icon.actor);
this.actor.label_actor = this.icon.label;
- this.view = new FolderView();
+ this.view = new FolderView(parentView);
this.view.actor.reactive = false;
_loadCategory(dir, this.view);
this.view.loadGrid();
diff --git a/js/ui/boxpointer.js b/js/ui/boxpointer.js
index 5a7d057..57a4af4 100644
--- a/js/ui/boxpointer.js
+++ b/js/ui/boxpointer.js
@@ -220,7 +220,7 @@ const BoxPointer = new Lang.Class({
}
this.bin.allocate(childBox, flags);
- global.log("Box pointer alloc " + [availWidth, availHeight]);
+ //global.log("Box pointer alloc " + [availWidth, availHeight]);
if (this._sourceActor && this._sourceActor.mapped) {
this._reposition();
this._updateFlip();
diff --git a/js/ui/iconGrid.js b/js/ui/iconGrid.js
index 5f798e7..030f976 100644
--- a/js/ui/iconGrid.js
+++ b/js/ui/iconGrid.js
@@ -217,15 +217,15 @@ const IconGrid = new Lang.Class({
let children = this._grid.get_children();
let nColumns = this._colLimit ? Math.min(this._colLimit,
- children.length)
- : children.length;
- let spacing = this._spacing;
+ children.length)
+ : children.length;
+ let spacing = this._fixedSpacing ? this._fixedSpacing : this._spacing;
let totalSpacing = Math.max(0, nColumns - 1) * spacing;
- // Kind of a lie, but not really an issue right now. If
- // we wanted to support some sort of hidden/overflow that would
- // need higher level design
- alloc.min_size = this._hItemSize;
- alloc.natural_size = nColumns * this._hItemSize + totalSpacing;
+ // Kind of a lie, but not really an issue right now. If
+ // we wanted to support some sort of hidden/overflow that would
+ // need higher level design
+ alloc.min_size = this._hItemSize;
+ alloc.natural_size = nColumns * this._hItemSize + totalSpacing;
},
_getVisibleChildren: function() {
@@ -246,15 +246,11 @@ const IconGrid = new Lang.Class({
let nColumns, spacing;
if (forWidth < 0) {
nColumns = children.length;
- spacing = this._spacing;
} else {
- [nColumns, , spacing] = this._computeLayout(forWidth);
+ [nColumns, ] = this._computeLayout(forWidth);
}
-
- if(this._computedSpacing)
- spacing = this._computedSpacing;
- else
- this._computedSpacing = spacing;
+
+ let spacing = this._fixedSpacing ? this._fixedSpacing : this._spacing;
let nRows;
if (nColumns > 0)
@@ -265,7 +261,7 @@ const IconGrid = new Lang.Class({
nRows = Math.min(nRows, this._rowLimit);
let totalSpacing = Math.max(0, nRows - 1) * spacing;
let height = nRows * this._vItemSize + totalSpacing;
-
+
if(this._usePagination && this._nPages) {
alloc.min_size = this._rowsPerPage * this._spacePerRow * this._nPages +
this._spaceBetweenPagesTotal;
alloc.natural_size = this._rowsPerPage * this._spacePerRow * this._nPages +
this._spaceBetweenPagesTotal;
@@ -287,9 +283,9 @@ const IconGrid = new Lang.Class({
let availWidth = box.x2 - box.x1;
let availHeight = box.y2 - box.y1;
global.log("Size " + [availWidth, availHeight]);
- let [nColumns, usedWidth, spacing] = this._computeLayout(availWidth);
- if(this._usePagination && spacing != this._computedSpacing) {
- this._computedSpacing = spacing;
+ let spacing = this._fixedSpacing ? this._fixedSpacing : this._spacing;
+ let [nColumns, usedWidth] = this._computeLayout(availWidth);
+ if(this._usePagination) {
// ScrollView height
let parentBox = this._viewForPageSize.allocation;
let gridBox = this.actor.get_theme_node().get_content_box(parentBox);
@@ -303,16 +299,18 @@ const IconGrid = new Lang.Class({
nRows = 0;
if (this._rowLimit)
nRows = Math.min(nRows, this._rowLimit);
-
+ let oldNPages = this._nPages;
this._calculatePaginationValues(availHeightPerPage, nColumns, nRows);
- this.emit('n-pages-changed', this._nPages);
-
- Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this, function() {
- this._grid.queue_relayout();
- return false;
- }));
+ if(oldNPages != this._nPages) {
+ global.log("Next relayout");
+ this.emit('n-pages-changed', this._nPages);
+ Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this, function() {
+ this._grid.queue_relayout();
+ return false;
+ }));
+ }
}
-
+ global.log("ICONGRID spacing " + spacing);
let leftPadding;
switch(this._xAlign) {
case St.Align.START:
@@ -373,10 +371,11 @@ const IconGrid = new Lang.Class({
},
_calculatePaginationValues: function (availHeightPerPage, nColumns, nRows) {
- this._spacePerRow = this._vItemSize + this._computedSpacing;
+ let spacing = this._fixedSpacing ? this._fixedSpacing : this._spacing;
+ this._spacePerRow = this._vItemSize + spacing;
this._rowsPerPage = Math.floor(availHeightPerPage / this._spacePerRow);
this._nPages = Math.ceil(nRows / this._rowsPerPage);
- this._spaceBetweenPages = availHeightPerPage - (this._rowsPerPage * (this._vItemSize +
this._computedSpacing));
+ this._spaceBetweenPages = availHeightPerPage - (this._rowsPerPage * (this._vItemSize + spacing));
this._spaceBetweenPagesTotal = this._spaceBetweenPages * (this._nPages);
this._childrenPerPage = nColumns * this._rowsPerPage;
},
@@ -405,7 +404,7 @@ const IconGrid = new Lang.Class({
},
childrenInRow: function(rowWidth) {
- return this._computeLayout(rowWidth)[0]
+ return this._computeLayout(rowWidth)[0];
},
getRowLimit: function() {
@@ -415,14 +414,7 @@ const IconGrid = new Lang.Class({
_computeLayout: function (forWidth) {
let nColumns = 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);
- }
+ let spacing = this._fixedSpacing ? this._fixedSpacing : this._spacing;
while ((this._colLimit == null || nColumns < this._colLimit) &&
(usedWidth + this._hItemSize <= forWidth)) {
@@ -433,7 +425,7 @@ const IconGrid = new Lang.Class({
if (nColumns > 0)
usedWidth -= spacing;
- return [nColumns, usedWidth, spacing];
+ return [nColumns, usedWidth];
},
_onStyleChanged: function() {
@@ -477,12 +469,20 @@ const IconGrid = new Lang.Class({
return [childBox.x1, childBox.y1];
},
- getComputedSpacing: function() {
- return this._computedSpacing;
+ setSpacing: function(spacing) {
+ if(this._fixedSpacing != spacing) {
+ this._fixedSpacing = spacing;
+ Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this, function() {
+ this._grid.queue_relayout();
+ return false;
+ }));
+ }
+
+ },
+
+ getSpacing: function() {
+ return this._fixedSpacing ? this._fixedSpacing : this._spacing;
},
- getUsedWidth: function() {
- return this._usedWidth;
- }
});
Signals.addSignalMethods(IconGrid.prototype);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]