2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2010-07-21 02:22:19 +00:00
|
|
|
|
|
|
|
const Clutter = imports.gi.Clutter;
|
2013-09-01 19:49:57 +00:00
|
|
|
const Gtk = imports.gi.Gtk;
|
2013-08-15 08:38:17 +00:00
|
|
|
const Meta = imports.gi.Meta;
|
2010-07-21 02:22:19 +00:00
|
|
|
const Shell = imports.gi.Shell;
|
2013-09-01 19:49:57 +00:00
|
|
|
const Signals = imports.signals;
|
2010-07-21 02:22:19 +00:00
|
|
|
const St = imports.gi.St;
|
|
|
|
|
|
|
|
const Lang = imports.lang;
|
|
|
|
const Params = imports.misc.params;
|
2013-09-01 19:49:57 +00:00
|
|
|
const Tweener = imports.ui.tweener;
|
2014-06-17 10:47:00 +00:00
|
|
|
const Main = imports.ui.main;
|
2010-07-21 02:22:19 +00:00
|
|
|
|
2013-08-15 08:38:17 +00:00
|
|
|
const ICON_SIZE = 96;
|
|
|
|
const MIN_ICON_SIZE = 16;
|
2010-07-21 02:22:19 +00:00
|
|
|
|
2013-09-01 19:49:57 +00:00
|
|
|
const EXTRA_SPACE_ANIMATION_TIME = 0.25;
|
2010-07-21 02:22:19 +00:00
|
|
|
|
2014-06-17 10:47:00 +00:00
|
|
|
const ANIMATION_TIME_IN = 0.350;
|
2014-06-17 17:10:54 +00:00
|
|
|
const ANIMATION_TIME_OUT = 1/2 * ANIMATION_TIME_IN;
|
2014-06-17 10:47:00 +00:00
|
|
|
const ANIMATION_MAX_DELAY_FOR_ITEM = 2/3 * ANIMATION_TIME_IN;
|
2014-09-19 17:25:35 +00:00
|
|
|
const ANIMATION_BASE_DELAY_FOR_ITEM = 1/4 * ANIMATION_MAX_DELAY_FOR_ITEM;
|
2014-06-17 17:10:54 +00:00
|
|
|
const ANIMATION_MAX_DELAY_OUT_FOR_ITEM = 2/3 * ANIMATION_TIME_OUT;
|
|
|
|
const ANIMATION_FADE_IN_TIME_FOR_ITEM = 1/4 * ANIMATION_TIME_IN;
|
2014-06-17 10:47:00 +00:00
|
|
|
|
|
|
|
const ANIMATION_BOUNCE_ICON_SCALE = 1.1;
|
|
|
|
|
|
|
|
const AnimationDirection = {
|
2014-06-17 17:10:54 +00:00
|
|
|
IN: 0,
|
|
|
|
OUT: 1
|
2014-06-17 10:47:00 +00:00
|
|
|
};
|
|
|
|
|
2014-06-17 19:31:53 +00:00
|
|
|
const APPICON_ANIMATION_OUT_SCALE = 3;
|
|
|
|
const APPICON_ANIMATION_OUT_TIME = 0.25;
|
|
|
|
|
2011-11-20 16:07:14 +00:00
|
|
|
const BaseIcon = new Lang.Class({
|
|
|
|
Name: 'BaseIcon',
|
2010-07-21 02:22:19 +00:00
|
|
|
|
2010-08-30 12:59:45 +00:00
|
|
|
_init : function(label, params) {
|
|
|
|
params = Params.parse(params, { createIcon: null,
|
2011-01-20 14:25:25 +00:00
|
|
|
setSizeManually: false,
|
|
|
|
showLabel: true });
|
2013-08-31 13:05:53 +00:00
|
|
|
|
|
|
|
let styleClass = 'overview-icon';
|
|
|
|
if (params.showLabel)
|
|
|
|
styleClass += ' overview-icon-with-label';
|
|
|
|
|
|
|
|
this.actor = new St.Bin({ style_class: styleClass,
|
2010-07-21 02:22:19 +00:00
|
|
|
x_fill: true,
|
|
|
|
y_fill: true });
|
|
|
|
this.actor._delegate = this;
|
|
|
|
this.actor.connect('style-changed',
|
|
|
|
Lang.bind(this, this._onStyleChanged));
|
2012-12-01 01:35:04 +00:00
|
|
|
this.actor.connect('destroy',
|
|
|
|
Lang.bind(this, this._onDestroy));
|
2010-07-21 02:22:19 +00:00
|
|
|
|
2010-08-30 12:59:36 +00:00
|
|
|
this._spacing = 0;
|
|
|
|
|
|
|
|
let box = new Shell.GenericContainer();
|
|
|
|
box.connect('allocate', Lang.bind(this, this._allocate));
|
|
|
|
box.connect('get-preferred-width',
|
|
|
|
Lang.bind(this, this._getPreferredWidth));
|
|
|
|
box.connect('get-preferred-height',
|
|
|
|
Lang.bind(this, this._getPreferredHeight));
|
2010-07-21 02:22:19 +00:00
|
|
|
this.actor.set_child(box);
|
|
|
|
|
|
|
|
this.iconSize = ICON_SIZE;
|
2011-12-20 18:11:07 +00:00
|
|
|
this._iconBin = new St.Bin({ x_align: St.Align.MIDDLE,
|
|
|
|
y_align: St.Align.MIDDLE });
|
2010-07-21 02:22:19 +00:00
|
|
|
|
2010-08-30 12:59:36 +00:00
|
|
|
box.add_actor(this._iconBin);
|
2010-07-21 02:22:19 +00:00
|
|
|
|
2011-01-20 14:25:25 +00:00
|
|
|
if (params.showLabel) {
|
2011-03-08 18:33:57 +00:00
|
|
|
this.label = new St.Label({ text: label });
|
|
|
|
box.add_actor(this.label);
|
2011-01-20 14:25:25 +00:00
|
|
|
} else {
|
2011-03-08 18:33:57 +00:00
|
|
|
this.label = null;
|
2011-01-20 14:25:25 +00:00
|
|
|
}
|
2010-07-21 02:22:19 +00:00
|
|
|
|
2010-08-30 12:59:45 +00:00
|
|
|
if (params.createIcon)
|
|
|
|
this.createIcon = params.createIcon;
|
|
|
|
this._setSizeManually = params.setSizeManually;
|
2010-07-21 02:22:19 +00:00
|
|
|
|
2011-03-02 23:25:23 +00:00
|
|
|
this.icon = null;
|
2012-12-01 01:35:04 +00:00
|
|
|
|
|
|
|
let cache = St.TextureCache.get_default();
|
|
|
|
this._iconThemeChangedId = cache.connect('icon-theme-changed', Lang.bind(this, this._onIconThemeChanged));
|
2010-07-21 02:22:19 +00:00
|
|
|
},
|
|
|
|
|
2010-08-30 12:59:36 +00:00
|
|
|
_allocate: function(actor, box, flags) {
|
|
|
|
let availWidth = box.x2 - box.x1;
|
|
|
|
let availHeight = box.y2 - box.y1;
|
|
|
|
|
2011-01-20 14:25:25 +00:00
|
|
|
let iconSize = availHeight;
|
|
|
|
|
2010-08-30 12:59:36 +00:00
|
|
|
let [iconMinHeight, iconNatHeight] = this._iconBin.get_preferred_height(-1);
|
2011-02-11 19:37:27 +00:00
|
|
|
let [iconMinWidth, iconNatWidth] = this._iconBin.get_preferred_width(-1);
|
2011-01-20 14:25:25 +00:00
|
|
|
let preferredHeight = iconNatHeight;
|
2010-08-30 12:59:36 +00:00
|
|
|
|
|
|
|
let childBox = new Clutter.ActorBox();
|
|
|
|
|
2011-03-08 18:33:57 +00:00
|
|
|
if (this.label) {
|
|
|
|
let [labelMinHeight, labelNatHeight] = this.label.get_preferred_height(-1);
|
2011-01-20 14:25:25 +00:00
|
|
|
preferredHeight += this._spacing + labelNatHeight;
|
|
|
|
|
|
|
|
let labelHeight = availHeight >= preferredHeight ? labelNatHeight
|
|
|
|
: labelMinHeight;
|
|
|
|
iconSize -= this._spacing + labelHeight;
|
|
|
|
|
|
|
|
childBox.x1 = 0;
|
|
|
|
childBox.x2 = availWidth;
|
|
|
|
childBox.y1 = iconSize + this._spacing;
|
|
|
|
childBox.y2 = childBox.y1 + labelHeight;
|
2011-03-08 18:33:57 +00:00
|
|
|
this.label.allocate(childBox, flags);
|
2011-01-20 14:25:25 +00:00
|
|
|
}
|
|
|
|
|
2011-02-11 19:37:27 +00:00
|
|
|
childBox.x1 = Math.floor((availWidth - iconNatWidth) / 2);
|
|
|
|
childBox.y1 = Math.floor((iconSize - iconNatHeight) / 2);
|
|
|
|
childBox.x2 = childBox.x1 + iconNatWidth;
|
|
|
|
childBox.y2 = childBox.y1 + iconNatHeight;
|
2010-08-30 12:59:36 +00:00
|
|
|
this._iconBin.allocate(childBox, flags);
|
|
|
|
},
|
|
|
|
|
|
|
|
_getPreferredWidth: function(actor, forHeight, alloc) {
|
|
|
|
this._getPreferredHeight(actor, -1, alloc);
|
|
|
|
},
|
|
|
|
|
|
|
|
_getPreferredHeight: function(actor, forWidth, alloc) {
|
|
|
|
let [iconMinHeight, iconNatHeight] = this._iconBin.get_preferred_height(forWidth);
|
2011-01-20 14:25:25 +00:00
|
|
|
alloc.min_size = iconMinHeight;
|
|
|
|
alloc.natural_size = iconNatHeight;
|
|
|
|
|
2011-03-08 18:33:57 +00:00
|
|
|
if (this.label) {
|
|
|
|
let [labelMinHeight, labelNatHeight] = this.label.get_preferred_height(forWidth);
|
2011-01-20 14:25:25 +00:00
|
|
|
alloc.min_size += this._spacing + labelMinHeight;
|
|
|
|
alloc.natural_size += this._spacing + labelNatHeight;
|
|
|
|
}
|
2010-08-30 12:59:36 +00:00
|
|
|
},
|
|
|
|
|
2010-07-21 02:22:19 +00:00
|
|
|
// This can be overridden by a subclass, or by the createIcon
|
|
|
|
// parameter to _init()
|
|
|
|
createIcon: function(size) {
|
|
|
|
throw new Error('no implementation of createIcon in ' + this);
|
|
|
|
},
|
|
|
|
|
2010-08-30 12:59:45 +00:00
|
|
|
setIconSize: function(size) {
|
|
|
|
if (!this._setSizeManually)
|
|
|
|
throw new Error('setSizeManually has to be set to use setIconsize');
|
|
|
|
|
|
|
|
if (size == this.iconSize)
|
|
|
|
return;
|
|
|
|
|
2011-03-02 23:25:23 +00:00
|
|
|
this._createIconTexture(size);
|
|
|
|
},
|
|
|
|
|
|
|
|
_createIconTexture: function(size) {
|
|
|
|
if (this.icon)
|
|
|
|
this.icon.destroy();
|
2010-08-30 12:59:45 +00:00
|
|
|
this.iconSize = size;
|
|
|
|
this.icon = this.createIcon(this.iconSize);
|
2011-02-10 15:30:28 +00:00
|
|
|
|
2011-12-20 18:11:07 +00:00
|
|
|
this._iconBin.child = this.icon;
|
2010-08-30 12:59:45 +00:00
|
|
|
},
|
|
|
|
|
2010-07-21 02:22:19 +00:00
|
|
|
_onStyleChanged: function() {
|
2010-08-30 12:59:36 +00:00
|
|
|
let node = this.actor.get_theme_node();
|
StThemeNode: simplify use of get_color/get_double/get_length
Although within St itself there are situations where the semantics of
these functions (return TRUE or FALSE and return the actual value in
an out parameter) is useful, it's mostly just annoying at the
application level, where you generally know that the CSS property is
going to specified, and there is no especially sane fallback if it's
not.
So rename the current methods to lookup_color, lookup_double, and
lookup_length, and add new get_color, get_double, and get_length
methods that don't take an "inherit" parameter, and return their
values directly. (Well, except for get_color, due to the lack of (out
caller-allocates) in gjs.)
And update the code to use either the old or new methods as appropriate.
https://bugzilla.gnome.org/show_bug.cgi?id=632590
2010-09-26 21:38:36 +00:00
|
|
|
this._spacing = node.get_length('spacing');
|
2010-08-30 12:59:36 +00:00
|
|
|
|
2011-03-02 23:25:23 +00:00
|
|
|
let size;
|
|
|
|
if (this._setSizeManually) {
|
|
|
|
size = this.iconSize;
|
|
|
|
} else {
|
|
|
|
let [found, len] = node.lookup_length('icon-size', false);
|
|
|
|
size = found ? len : ICON_SIZE;
|
|
|
|
}
|
2010-08-30 12:59:36 +00:00
|
|
|
|
2012-12-01 01:35:04 +00:00
|
|
|
if (this.iconSize == size && this._iconBin.child)
|
|
|
|
return;
|
|
|
|
|
2011-03-02 23:25:23 +00:00
|
|
|
this._createIconTexture(size);
|
2012-12-01 01:35:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_onDestroy: function() {
|
|
|
|
if (this._iconThemeChangedId > 0) {
|
|
|
|
let cache = St.TextureCache.get_default();
|
|
|
|
cache.disconnect(this._iconThemeChangedId);
|
|
|
|
this._iconThemeChangedId = 0;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_onIconThemeChanged: function() {
|
|
|
|
this._createIconTexture(this.iconSize);
|
2014-06-17 19:31:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
animateZoomOut: function() {
|
|
|
|
// Animate only the child instead of the entire actor, so the
|
|
|
|
// styles like hover and running are not applied while
|
|
|
|
// animating.
|
|
|
|
zoomOutActor(this.actor.child);
|
2010-07-21 02:22:19 +00:00
|
|
|
}
|
2011-11-20 16:07:14 +00:00
|
|
|
});
|
2010-07-21 02:22:19 +00:00
|
|
|
|
2014-06-17 19:31:53 +00:00
|
|
|
function clamp(value, min, max) {
|
|
|
|
return Math.max(Math.min(value, max), min);
|
|
|
|
};
|
|
|
|
|
|
|
|
function zoomOutActor(actor) {
|
|
|
|
let actorClone = new Clutter.Clone({ source: actor,
|
|
|
|
reactive: false });
|
|
|
|
let [width, height] = actor.get_transformed_size();
|
|
|
|
let [x, y] = actor.get_transformed_position();
|
|
|
|
actorClone.set_size(width, height);
|
|
|
|
actorClone.set_position(x, y);
|
|
|
|
actorClone.opacity = 255;
|
|
|
|
actorClone.set_pivot_point(0.5, 0.5);
|
|
|
|
|
|
|
|
Main.uiGroup.add_actor(actorClone);
|
|
|
|
|
|
|
|
// Avoid monitor edges to not zoom outside the current monitor
|
|
|
|
let monitor = Main.layoutManager.findMonitorForActor(actor);
|
|
|
|
let scaledWidth = width * APPICON_ANIMATION_OUT_SCALE;
|
|
|
|
let scaledHeight = height * APPICON_ANIMATION_OUT_SCALE;
|
|
|
|
let scaledX = x - (scaledWidth - width) / 2;
|
|
|
|
let scaledY = y - (scaledHeight - height) / 2;
|
|
|
|
let containedX = clamp(scaledX, monitor.x, monitor.x + monitor.width - scaledWidth);
|
|
|
|
let containedY = clamp(scaledY, monitor.y, monitor.y + monitor.height - scaledHeight);
|
|
|
|
|
|
|
|
Tweener.addTween(actorClone,
|
|
|
|
{ time: APPICON_ANIMATION_OUT_TIME,
|
|
|
|
scale_x: APPICON_ANIMATION_OUT_SCALE,
|
|
|
|
scale_y: APPICON_ANIMATION_OUT_SCALE,
|
|
|
|
translation_x: containedX - scaledX,
|
|
|
|
translation_y: containedY - scaledY,
|
|
|
|
opacity: 0,
|
|
|
|
transition: 'easeOutQuad',
|
|
|
|
onComplete: function() {
|
|
|
|
actorClone.destroy();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-11-20 17:56:27 +00:00
|
|
|
const IconGrid = new Lang.Class({
|
|
|
|
Name: 'IconGrid',
|
2010-07-21 02:22:19 +00:00
|
|
|
|
|
|
|
_init: function(params) {
|
2010-10-14 12:27:22 +00:00
|
|
|
params = Params.parse(params, { rowLimit: null,
|
|
|
|
columnLimit: null,
|
2013-08-27 19:23:13 +00:00
|
|
|
minRows: 1,
|
|
|
|
minColumns: 1,
|
2013-02-22 03:23:34 +00:00
|
|
|
fillParent: false,
|
2013-08-23 09:14:21 +00:00
|
|
|
xAlign: St.Align.MIDDLE,
|
|
|
|
padWithSpacing: false });
|
2010-07-21 02:22:19 +00:00
|
|
|
this._rowLimit = params.rowLimit;
|
|
|
|
this._colLimit = params.columnLimit;
|
2013-08-27 19:23:13 +00:00
|
|
|
this._minRows = params.minRows;
|
|
|
|
this._minColumns = params.minColumns;
|
2010-10-14 12:27:22 +00:00
|
|
|
this._xAlign = params.xAlign;
|
2013-02-22 03:23:34 +00:00
|
|
|
this._fillParent = params.fillParent;
|
2013-08-23 09:14:21 +00:00
|
|
|
this._padWithSpacing = params.padWithSpacing;
|
|
|
|
|
|
|
|
this.topPadding = 0;
|
|
|
|
this.bottomPadding = 0;
|
|
|
|
this.rightPadding = 0;
|
|
|
|
this.leftPadding = 0;
|
2010-07-21 02:22:19 +00:00
|
|
|
|
|
|
|
this.actor = new St.BoxLayout({ style_class: 'icon-grid',
|
|
|
|
vertical: true });
|
2013-08-29 21:25:13 +00:00
|
|
|
this._items = [];
|
2010-07-21 02:22:19 +00:00
|
|
|
// Pulled from CSS, but hardcode some defaults here
|
|
|
|
this._spacing = 0;
|
2012-02-14 15:30:40 +00:00
|
|
|
this._hItemSize = this._vItemSize = ICON_SIZE;
|
2013-08-15 08:38:17 +00:00
|
|
|
this._fixedHItemSize = this._fixedVItemSize = undefined;
|
2010-07-21 02:22:19 +00:00
|
|
|
this._grid = new Shell.GenericContainer();
|
|
|
|
this.actor.add(this._grid, { expand: true, y_align: St.Align.START });
|
|
|
|
this.actor.connect('style-changed', Lang.bind(this, this._onStyleChanged));
|
|
|
|
|
|
|
|
this._grid.connect('get-preferred-width', Lang.bind(this, this._getPreferredWidth));
|
|
|
|
this._grid.connect('get-preferred-height', Lang.bind(this, this._getPreferredHeight));
|
|
|
|
this._grid.connect('allocate', Lang.bind(this, this._allocate));
|
|
|
|
},
|
|
|
|
|
|
|
|
_getPreferredWidth: function (grid, forHeight, alloc) {
|
2013-02-22 03:23:34 +00:00
|
|
|
if (this._fillParent)
|
|
|
|
// Ignore all size requests of children and request a size of 0;
|
|
|
|
// later we'll allocate as many children as fit the parent
|
|
|
|
return;
|
|
|
|
|
2013-02-20 16:02:34 +00:00
|
|
|
let nChildren = this._grid.get_n_children();
|
2010-07-21 02:22:19 +00:00
|
|
|
let nColumns = this._colLimit ? Math.min(this._colLimit,
|
2013-02-20 16:02:34 +00:00
|
|
|
nChildren)
|
|
|
|
: nChildren;
|
2013-08-21 17:31:09 +00:00
|
|
|
let totalSpacing = Math.max(0, nColumns - 1) * this._getSpacing();
|
2010-07-21 02:22:19 +00:00
|
|
|
// 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
|
2013-08-15 08:38:17 +00:00
|
|
|
alloc.min_size = this._getHItemSize() + this.leftPadding + this.rightPadding;
|
|
|
|
alloc.natural_size = nColumns * this._getHItemSize() + totalSpacing + this.leftPadding + this.rightPadding;
|
2010-07-21 02:22:19 +00:00
|
|
|
},
|
|
|
|
|
2010-12-18 19:09:58 +00:00
|
|
|
_getVisibleChildren: function() {
|
2010-07-21 02:22:19 +00:00
|
|
|
let children = this._grid.get_children();
|
2010-12-18 19:09:58 +00:00
|
|
|
children = children.filter(function(actor) {
|
|
|
|
return actor.visible;
|
|
|
|
});
|
|
|
|
return children;
|
|
|
|
},
|
|
|
|
|
|
|
|
_getPreferredHeight: function (grid, forWidth, alloc) {
|
2013-02-22 03:23:34 +00:00
|
|
|
if (this._fillParent)
|
|
|
|
// Ignore all size requests of children and request a size of 0;
|
|
|
|
// later we'll allocate as many children as fit the parent
|
|
|
|
return;
|
|
|
|
|
2010-12-18 19:09:58 +00:00
|
|
|
let children = this._getVisibleChildren();
|
2013-08-21 17:31:09 +00:00
|
|
|
let nColumns;
|
|
|
|
if (forWidth < 0)
|
2012-07-01 16:38:28 +00:00
|
|
|
nColumns = children.length;
|
2013-08-21 17:31:09 +00:00
|
|
|
else
|
|
|
|
[nColumns, ] = this._computeLayout(forWidth);
|
2013-02-20 02:18:48 +00:00
|
|
|
|
2010-07-21 02:22:19 +00:00
|
|
|
let nRows;
|
|
|
|
if (nColumns > 0)
|
|
|
|
nRows = Math.ceil(children.length / nColumns);
|
|
|
|
else
|
|
|
|
nRows = 0;
|
|
|
|
if (this._rowLimit)
|
|
|
|
nRows = Math.min(nRows, this._rowLimit);
|
2013-08-21 17:31:09 +00:00
|
|
|
let totalSpacing = Math.max(0, nRows - 1) * this._getSpacing();
|
2013-08-15 08:38:17 +00:00
|
|
|
let height = nRows * this._getVItemSize() + totalSpacing + this.topPadding + this.bottomPadding;
|
2010-07-21 02:22:19 +00:00
|
|
|
alloc.min_size = height;
|
|
|
|
alloc.natural_size = height;
|
|
|
|
},
|
|
|
|
|
|
|
|
_allocate: function (grid, box, flags) {
|
2013-02-22 03:23:34 +00:00
|
|
|
if (this._fillParent) {
|
|
|
|
// Reset the passed in box to fill the parent
|
|
|
|
let parentBox = this.actor.get_parent().allocation;
|
|
|
|
let gridBox = this.actor.get_theme_node().get_content_box(parentBox);
|
|
|
|
box = this._grid.get_theme_node().get_content_box(gridBox);
|
|
|
|
}
|
|
|
|
|
2010-12-18 19:09:58 +00:00
|
|
|
let children = this._getVisibleChildren();
|
2010-07-21 02:22:19 +00:00
|
|
|
let availWidth = box.x2 - box.x1;
|
|
|
|
let availHeight = box.y2 - box.y1;
|
2013-08-21 17:31:09 +00:00
|
|
|
let spacing = this._getSpacing();
|
|
|
|
let [nColumns, usedWidth] = this._computeLayout(availWidth);
|
2010-07-21 02:22:19 +00:00
|
|
|
|
2013-08-23 09:14:21 +00:00
|
|
|
let leftEmptySpace;
|
2010-10-14 12:27:22 +00:00
|
|
|
switch(this._xAlign) {
|
|
|
|
case St.Align.START:
|
2013-08-23 09:14:21 +00:00
|
|
|
leftEmptySpace = 0;
|
2010-10-14 12:27:22 +00:00
|
|
|
break;
|
|
|
|
case St.Align.MIDDLE:
|
2013-08-23 09:14:21 +00:00
|
|
|
leftEmptySpace = Math.floor((availWidth - usedWidth) / 2);
|
2010-10-14 12:27:22 +00:00
|
|
|
break;
|
|
|
|
case St.Align.END:
|
2013-08-23 09:14:21 +00:00
|
|
|
leftEmptySpace = availWidth - usedWidth;
|
2010-10-14 12:27:22 +00:00
|
|
|
}
|
2010-07-21 02:22:19 +00:00
|
|
|
|
2013-08-23 09:14:21 +00:00
|
|
|
let x = box.x1 + leftEmptySpace + this.leftPadding;
|
|
|
|
let y = box.y1 + this.topPadding;
|
2010-07-21 02:22:19 +00:00
|
|
|
let columnIndex = 0;
|
|
|
|
let rowIndex = 0;
|
|
|
|
for (let i = 0; i < children.length; i++) {
|
2013-08-21 17:16:58 +00:00
|
|
|
let childBox = this._calculateChildBox(children[i], x, y, box);
|
2010-07-21 02:22:19 +00:00
|
|
|
|
2013-02-22 03:23:34 +00:00
|
|
|
if (this._rowLimit && rowIndex >= this._rowLimit ||
|
2013-08-23 09:14:21 +00:00
|
|
|
this._fillParent && childBox.y2 > availHeight - this.bottomPadding) {
|
2010-07-21 02:22:19 +00:00
|
|
|
this._grid.set_skip_paint(children[i], true);
|
|
|
|
} else {
|
|
|
|
children[i].allocate(childBox, flags);
|
|
|
|
this._grid.set_skip_paint(children[i], false);
|
|
|
|
}
|
|
|
|
|
|
|
|
columnIndex++;
|
|
|
|
if (columnIndex == nColumns) {
|
|
|
|
columnIndex = 0;
|
|
|
|
rowIndex++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (columnIndex == 0) {
|
2013-08-15 08:38:17 +00:00
|
|
|
y += this._getVItemSize() + spacing;
|
2013-08-23 09:14:21 +00:00
|
|
|
x = box.x1 + leftEmptySpace + this.leftPadding;
|
2010-07-21 02:22:19 +00:00
|
|
|
} else {
|
2013-08-15 08:38:17 +00:00
|
|
|
x += this._getHItemSize() + spacing;
|
2010-07-21 02:22:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-06-17 10:47:00 +00:00
|
|
|
/**
|
|
|
|
* Intended to be override by subclasses if they need a different
|
|
|
|
* set of items to be animated.
|
|
|
|
*/
|
|
|
|
_getChildrenToAnimate: function() {
|
|
|
|
return this._getVisibleChildren();
|
|
|
|
},
|
|
|
|
|
|
|
|
_animationDone: function() {
|
|
|
|
this._animating = false;
|
|
|
|
this.emit('animation-done');
|
|
|
|
},
|
|
|
|
|
|
|
|
animatePulse: function(animationDirection) {
|
|
|
|
if (animationDirection != AnimationDirection.IN)
|
|
|
|
throw new Error("Pulse animation only implements 'in' animation direction");
|
|
|
|
|
|
|
|
if (this._animating)
|
|
|
|
return;
|
2013-08-21 17:16:58 +00:00
|
|
|
|
2014-06-17 10:47:00 +00:00
|
|
|
this._animating = true;
|
|
|
|
|
|
|
|
let actors = this._getChildrenToAnimate();
|
|
|
|
if (actors.length == 0) {
|
|
|
|
this._animationDone();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-19 17:25:35 +00:00
|
|
|
// For few items the animation can be slow, so use a smaller
|
|
|
|
// delay when there are less than 4 items
|
|
|
|
// (ANIMATION_BASE_DELAY_FOR_ITEM = 1/4 *
|
|
|
|
// ANIMATION_MAX_DELAY_FOR_ITEM)
|
|
|
|
let maxDelay = Math.min(ANIMATION_BASE_DELAY_FOR_ITEM * actors.length,
|
|
|
|
ANIMATION_MAX_DELAY_FOR_ITEM);
|
|
|
|
|
2014-06-17 10:47:00 +00:00
|
|
|
for (let index = 0; index < actors.length; index++) {
|
|
|
|
let actor = actors[index];
|
2014-09-02 20:49:10 +00:00
|
|
|
actor.reactive = false;
|
2014-09-18 12:29:35 +00:00
|
|
|
actor.set_scale(0, 0);
|
|
|
|
actor.set_pivot_point(0.5, 0.5);
|
2014-06-17 10:47:00 +00:00
|
|
|
|
2014-09-19 17:25:35 +00:00
|
|
|
let delay = index / actors.length * maxDelay;
|
2014-06-17 10:47:00 +00:00
|
|
|
let bounceUpTime = ANIMATION_TIME_IN / 4;
|
|
|
|
let isLastItem = index == actors.length - 1;
|
2014-09-18 12:29:35 +00:00
|
|
|
Tweener.addTween(actor,
|
2014-06-17 10:47:00 +00:00
|
|
|
{ time: bounceUpTime,
|
|
|
|
transition: 'easeInOutQuad',
|
|
|
|
delay: delay,
|
|
|
|
scale_x: ANIMATION_BOUNCE_ICON_SCALE,
|
|
|
|
scale_y: ANIMATION_BOUNCE_ICON_SCALE,
|
|
|
|
onComplete: Lang.bind(this, function() {
|
2014-09-18 12:29:35 +00:00
|
|
|
Tweener.addTween(actor,
|
2014-06-17 10:47:00 +00:00
|
|
|
{ time: ANIMATION_TIME_IN - bounceUpTime,
|
|
|
|
transition: 'easeInOutQuad',
|
|
|
|
scale_x: 1,
|
|
|
|
scale_y: 1,
|
|
|
|
onComplete: Lang.bind(this, function() {
|
|
|
|
if (isLastItem)
|
|
|
|
this._animationDone();
|
2014-09-02 20:49:10 +00:00
|
|
|
actor.reactive = true;
|
2014-06-17 10:47:00 +00:00
|
|
|
})
|
|
|
|
});
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-06-17 17:10:54 +00:00
|
|
|
animateSpring: function(animationDirection, sourceActor) {
|
|
|
|
if (this._animating)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._animating = true;
|
|
|
|
|
|
|
|
let actors = this._getChildrenToAnimate();
|
|
|
|
if (actors.length == 0) {
|
|
|
|
this._animationDone();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let [sourceX, sourceY] = sourceActor.get_transformed_position();
|
|
|
|
let [sourceWidth, sourceHeight] = sourceActor.get_size();
|
|
|
|
// Get the center
|
|
|
|
let [sourceCenterX, sourceCenterY] = [sourceX + sourceWidth / 2, sourceY + sourceHeight / 2];
|
|
|
|
// Design decision, 1/2 of the source actor size.
|
|
|
|
let [sourceScaledWidth, sourceScaledHeight] = [sourceWidth / 2, sourceHeight / 2];
|
|
|
|
|
|
|
|
actors.forEach(function(actor) {
|
|
|
|
let [actorX, actorY] = actor._transformedPosition = actor.get_transformed_position();
|
|
|
|
let [x, y] = [actorX - sourceX, actorY - sourceY];
|
|
|
|
actor._distance = Math.sqrt(x * x + y * y);
|
|
|
|
});
|
|
|
|
let maxDist = actors.reduce(function(prev, cur) {
|
|
|
|
return Math.max(prev, cur._distance);
|
|
|
|
}, 0);
|
|
|
|
let minDist = actors.reduce(function(prev, cur) {
|
|
|
|
return Math.min(prev, cur._distance);
|
|
|
|
}, Infinity);
|
|
|
|
let normalization = maxDist - minDist;
|
|
|
|
|
|
|
|
for (let index = 0; index < actors.length; index++) {
|
|
|
|
let actor = actors[index];
|
|
|
|
actor.opacity = 0;
|
2014-09-02 20:49:10 +00:00
|
|
|
actor.reactive = false;
|
2014-06-17 17:10:54 +00:00
|
|
|
|
|
|
|
let actorClone = new Clutter.Clone({ source: actor });
|
|
|
|
Main.uiGroup.add_actor(actorClone);
|
|
|
|
|
|
|
|
let [width, height,,] = this._getAllocatedChildSizeAndSpacing(actor);
|
|
|
|
actorClone.set_size(width, height);
|
|
|
|
let scaleX = sourceScaledWidth / width;
|
|
|
|
let scaleY = sourceScaledHeight / height;
|
2014-09-02 21:24:19 +00:00
|
|
|
let [adjustedSourcePositionX, adjustedSourcePositionY] = [sourceCenterX - sourceScaledWidth / 2, sourceCenterY - sourceScaledHeight / 2];
|
2014-06-17 17:10:54 +00:00
|
|
|
|
|
|
|
let movementParams, fadeParams;
|
|
|
|
if (animationDirection == AnimationDirection.IN) {
|
2014-09-06 10:47:33 +00:00
|
|
|
let isLastItem = actor._distance == minDist;
|
|
|
|
|
2014-06-17 17:10:54 +00:00
|
|
|
actorClone.opacity = 0;
|
|
|
|
actorClone.set_scale(scaleX, scaleY);
|
|
|
|
|
|
|
|
actorClone.set_position(adjustedSourcePositionX, adjustedSourcePositionY);
|
|
|
|
|
|
|
|
let delay = (1 - (actor._distance - minDist) / normalization) * ANIMATION_MAX_DELAY_FOR_ITEM;
|
|
|
|
let [finalX, finalY] = actor._transformedPosition;
|
|
|
|
movementParams = { time: ANIMATION_TIME_IN,
|
|
|
|
transition: 'easeInOutQuad',
|
|
|
|
delay: delay,
|
|
|
|
x: finalX,
|
|
|
|
y: finalY,
|
|
|
|
scale_x: 1,
|
|
|
|
scale_y: 1,
|
|
|
|
onComplete: Lang.bind(this, function() {
|
|
|
|
if (isLastItem)
|
|
|
|
this._animationDone();
|
|
|
|
|
|
|
|
actor.opacity = 255;
|
2014-09-02 20:49:10 +00:00
|
|
|
actor.reactive = true;
|
2014-06-17 17:10:54 +00:00
|
|
|
actorClone.destroy();
|
|
|
|
})};
|
|
|
|
fadeParams = { time: ANIMATION_FADE_IN_TIME_FOR_ITEM,
|
|
|
|
transition: 'easeInOutQuad',
|
|
|
|
delay: delay,
|
|
|
|
opacity: 255 };
|
|
|
|
} else {
|
2014-09-06 12:07:22 +00:00
|
|
|
let isLastItem = actor._distance == maxDist;
|
2014-09-06 10:47:33 +00:00
|
|
|
|
2014-06-17 17:10:54 +00:00
|
|
|
let [startX, startY] = actor._transformedPosition;
|
|
|
|
actorClone.set_position(startX, startY);
|
|
|
|
|
|
|
|
let delay = (actor._distance - minDist) / normalization * ANIMATION_MAX_DELAY_OUT_FOR_ITEM;
|
|
|
|
movementParams = { time: ANIMATION_TIME_OUT,
|
|
|
|
transition: 'easeInOutQuad',
|
|
|
|
delay: delay,
|
|
|
|
x: adjustedSourcePositionX,
|
|
|
|
y: adjustedSourcePositionY,
|
|
|
|
scale_x: scaleX,
|
|
|
|
scale_y: scaleY,
|
|
|
|
onComplete: Lang.bind(this, function() {
|
|
|
|
if (isLastItem) {
|
|
|
|
this._animationDone();
|
|
|
|
this._restoreItemsOpacity();
|
|
|
|
}
|
2014-09-07 08:22:26 +00:00
|
|
|
actor.reactive = true;
|
2014-06-17 17:10:54 +00:00
|
|
|
actorClone.destroy();
|
|
|
|
})};
|
|
|
|
fadeParams = { time: ANIMATION_FADE_IN_TIME_FOR_ITEM,
|
|
|
|
transition: 'easeInOutQuad',
|
|
|
|
delay: ANIMATION_TIME_OUT + delay - ANIMATION_FADE_IN_TIME_FOR_ITEM,
|
|
|
|
opacity: 0 };
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Tweener.addTween(actorClone, movementParams);
|
|
|
|
Tweener.addTween(actorClone, fadeParams);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_restoreItemsOpacity: function() {
|
|
|
|
for (let index = 0; index < this._items.length; index++) {
|
|
|
|
this._items[index].actor.opacity = 255;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-06-17 10:47:00 +00:00
|
|
|
_getAllocatedChildSizeAndSpacing: function(child) {
|
|
|
|
let [,, natWidth, natHeight] = child.get_preferred_size();
|
|
|
|
let width = Math.min(this._getHItemSize(), natWidth);
|
|
|
|
let xSpacing = Math.max(0, width - natWidth) / 2;
|
|
|
|
let height = Math.min(this._getVItemSize(), natHeight);
|
|
|
|
let ySpacing = Math.max(0, height - natHeight) / 2;
|
|
|
|
return [width, height, xSpacing, ySpacing];
|
|
|
|
},
|
|
|
|
|
|
|
|
_calculateChildBox: function(child, x, y, box) {
|
2013-08-21 17:16:58 +00:00
|
|
|
/* Center the item in its allocation horizontally */
|
2014-06-17 10:47:00 +00:00
|
|
|
let [width, height, childXSpacing, childYSpacing] =
|
|
|
|
this._getAllocatedChildSizeAndSpacing(child);
|
2013-08-21 17:16:58 +00:00
|
|
|
|
|
|
|
let childBox = new Clutter.ActorBox();
|
|
|
|
if (Clutter.get_default_text_direction() == Clutter.TextDirection.RTL) {
|
|
|
|
let _x = box.x2 - (x + width);
|
|
|
|
childBox.x1 = Math.floor(_x - childXSpacing);
|
|
|
|
} else {
|
|
|
|
childBox.x1 = Math.floor(x + childXSpacing);
|
|
|
|
}
|
|
|
|
childBox.y1 = Math.floor(y + childYSpacing);
|
|
|
|
childBox.x2 = childBox.x1 + width;
|
|
|
|
childBox.y2 = childBox.y1 + height;
|
|
|
|
return childBox;
|
|
|
|
},
|
|
|
|
|
2013-08-22 21:27:05 +00:00
|
|
|
columnsForWidth: function(rowWidth) {
|
2011-03-21 22:53:07 +00:00
|
|
|
return this._computeLayout(rowWidth)[0];
|
|
|
|
},
|
|
|
|
|
2012-05-08 20:03:17 +00:00
|
|
|
getRowLimit: function() {
|
|
|
|
return this._rowLimit;
|
|
|
|
},
|
|
|
|
|
2010-07-21 02:22:19 +00:00
|
|
|
_computeLayout: function (forWidth) {
|
|
|
|
let nColumns = 0;
|
2013-08-23 09:14:21 +00:00
|
|
|
let usedWidth = this.leftPadding + this.rightPadding;
|
2013-08-21 17:31:09 +00:00
|
|
|
let spacing = this._getSpacing();
|
2013-02-19 23:38:11 +00:00
|
|
|
|
2010-07-21 02:22:19 +00:00
|
|
|
while ((this._colLimit == null || nColumns < this._colLimit) &&
|
2013-08-15 08:38:17 +00:00
|
|
|
(usedWidth + this._getHItemSize() <= forWidth)) {
|
|
|
|
usedWidth += this._getHItemSize() + spacing;
|
2010-07-21 02:22:19 +00:00
|
|
|
nColumns += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nColumns > 0)
|
2013-02-19 23:38:11 +00:00
|
|
|
usedWidth -= spacing;
|
2010-07-21 02:22:19 +00:00
|
|
|
|
2013-08-21 17:31:09 +00:00
|
|
|
return [nColumns, usedWidth];
|
2010-07-21 02:22:19 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_onStyleChanged: function() {
|
|
|
|
let themeNode = this.actor.get_theme_node();
|
StThemeNode: simplify use of get_color/get_double/get_length
Although within St itself there are situations where the semantics of
these functions (return TRUE or FALSE and return the actual value in
an out parameter) is useful, it's mostly just annoying at the
application level, where you generally know that the CSS property is
going to specified, and there is no especially sane fallback if it's
not.
So rename the current methods to lookup_color, lookup_double, and
lookup_length, and add new get_color, get_double, and get_length
methods that don't take an "inherit" parameter, and return their
values directly. (Well, except for get_color, due to the lack of (out
caller-allocates) in gjs.)
And update the code to use either the old or new methods as appropriate.
https://bugzilla.gnome.org/show_bug.cgi?id=632590
2010-09-26 21:38:36 +00:00
|
|
|
this._spacing = themeNode.get_length('spacing');
|
2012-02-14 15:30:40 +00:00
|
|
|
this._hItemSize = themeNode.get_length('-shell-grid-horizontal-item-size') || ICON_SIZE;
|
|
|
|
this._vItemSize = themeNode.get_length('-shell-grid-vertical-item-size') || ICON_SIZE;
|
2010-07-21 02:22:19 +00:00
|
|
|
this._grid.queue_relayout();
|
|
|
|
},
|
|
|
|
|
2013-08-30 16:50:35 +00:00
|
|
|
nRows: function(forWidth) {
|
|
|
|
let children = this._getVisibleChildren();
|
|
|
|
let nColumns = (forWidth < 0) ? children.length : this._computeLayout(forWidth)[0];
|
|
|
|
let nRows = (nColumns > 0) ? Math.ceil(children.length / nColumns) : 0;
|
|
|
|
if (this._rowLimit)
|
|
|
|
nRows = Math.min(nRows, this._rowLimit);
|
|
|
|
return nRows;
|
|
|
|
},
|
|
|
|
|
|
|
|
rowsForHeight: function(forHeight) {
|
2013-08-15 08:38:17 +00:00
|
|
|
return Math.floor((forHeight - (this.topPadding + this.bottomPadding) + this._getSpacing()) / (this._getVItemSize() + this._getSpacing()));
|
2013-08-30 16:50:35 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
usedHeightForNRows: function(nRows) {
|
2013-08-15 08:38:17 +00:00
|
|
|
return (this._getVItemSize() + this._getSpacing()) * nRows - this._getSpacing() + this.topPadding + this.bottomPadding;
|
2013-08-30 16:50:35 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
usedWidth: function(forWidth) {
|
2013-08-15 08:38:17 +00:00
|
|
|
return this.usedWidthForNColumns(this.columnsForWidth(forWidth));
|
|
|
|
},
|
|
|
|
|
|
|
|
usedWidthForNColumns: function(columns) {
|
|
|
|
let usedWidth = columns * (this._getHItemSize() + this._getSpacing());
|
2013-08-30 16:50:35 +00:00
|
|
|
usedWidth -= this._getSpacing();
|
|
|
|
return usedWidth + this.leftPadding + this.rightPadding;
|
|
|
|
},
|
|
|
|
|
2012-05-30 00:36:45 +00:00
|
|
|
removeAll: function() {
|
2013-02-08 23:59:15 +00:00
|
|
|
this._items = [];
|
|
|
|
this._grid.remove_all_children();
|
|
|
|
},
|
|
|
|
|
|
|
|
destroyAll: function() {
|
2013-08-29 21:25:13 +00:00
|
|
|
this._items = [];
|
2012-05-30 00:36:45 +00:00
|
|
|
this._grid.destroy_all_children();
|
2010-07-21 02:22:19 +00:00
|
|
|
},
|
|
|
|
|
2014-10-16 17:51:30 +00:00
|
|
|
_keyFocusIn: function(actor) {
|
|
|
|
this.emit('key-focus-in', actor._associatedItem);
|
|
|
|
},
|
|
|
|
|
2013-08-29 21:25:13 +00:00
|
|
|
addItem: function(item, index) {
|
2013-10-30 17:05:20 +00:00
|
|
|
if (!item.icon instanceof BaseIcon)
|
|
|
|
throw new Error('Only items with a BaseIcon icon property can be added to IconGrid');
|
2013-08-29 21:25:13 +00:00
|
|
|
|
|
|
|
this._items.push(item);
|
2012-06-11 17:53:32 +00:00
|
|
|
if (index !== undefined)
|
2013-08-29 21:25:13 +00:00
|
|
|
this._grid.insert_child_at_index(item.actor, index);
|
2012-06-11 17:53:32 +00:00
|
|
|
else
|
2013-08-29 21:25:13 +00:00
|
|
|
this._grid.add_actor(item.actor);
|
2014-10-16 17:51:30 +00:00
|
|
|
|
|
|
|
// Maybe the item actor acts as a container, so ask the item if
|
|
|
|
// it has a specific actor to track focus
|
|
|
|
let focusReceiver = item.actor;
|
|
|
|
if (item.getFocusReceiver)
|
|
|
|
focusReceiver = item.getFocusReceiver();
|
|
|
|
|
|
|
|
focusReceiver._associatedItem = item.actor;
|
|
|
|
focusReceiver._iconGridKeyFocusInId = focusReceiver.connect('key-focus-in', Lang.bind(this, this._keyFocusIn));
|
2010-07-21 02:22:19 +00:00
|
|
|
},
|
|
|
|
|
2014-01-28 16:36:57 +00:00
|
|
|
removeItem: function(item) {
|
2014-10-16 17:51:30 +00:00
|
|
|
let focusReceiver = item.actor;
|
|
|
|
if (item.getFocusReceiver)
|
|
|
|
focusReceiver = item.getFocusReceiver();
|
|
|
|
|
|
|
|
|
|
|
|
focusReceiver._associatedItem = null;
|
|
|
|
focusReceiver.disconnect(focusReceiver._iconGridKeyFocusInId);
|
|
|
|
|
2014-01-28 16:36:57 +00:00
|
|
|
this._grid.remove_child(item.actor);
|
|
|
|
},
|
|
|
|
|
2010-07-21 02:22:19 +00:00
|
|
|
getItemAtIndex: function(index) {
|
2012-05-30 00:36:45 +00:00
|
|
|
return this._grid.get_child_at_index(index);
|
2010-07-21 02:22:19 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
visibleItemsCount: function() {
|
2012-05-30 00:36:45 +00:00
|
|
|
return this._grid.get_n_children() - this._grid.get_n_skip_paint();
|
2013-08-21 17:31:09 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
setSpacing: function(spacing) {
|
|
|
|
this._fixedSpacing = spacing;
|
|
|
|
},
|
|
|
|
|
|
|
|
_getSpacing: function() {
|
|
|
|
return this._fixedSpacing ? this._fixedSpacing : this._spacing;
|
|
|
|
},
|
|
|
|
|
2013-08-15 08:38:17 +00:00
|
|
|
_getHItemSize: function() {
|
|
|
|
return this._fixedHItemSize ? this._fixedHItemSize : this._hItemSize;
|
|
|
|
},
|
|
|
|
|
|
|
|
_getVItemSize: function() {
|
|
|
|
return this._fixedVItemSize ? this._fixedVItemSize : this._vItemSize;
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateSpacingForSize: function(availWidth, availHeight) {
|
|
|
|
let maxEmptyVArea = availHeight - this._minRows * this._getVItemSize();
|
|
|
|
let maxEmptyHArea = availWidth - this._minColumns * this._getHItemSize();
|
2013-08-27 19:23:13 +00:00
|
|
|
let maxHSpacing, maxVSpacing;
|
|
|
|
|
2013-08-23 09:14:21 +00:00
|
|
|
if (this._padWithSpacing) {
|
|
|
|
// minRows + 1 because we want to put spacing before the first row, so it is like we have one more row
|
|
|
|
// to divide the empty space
|
|
|
|
maxVSpacing = Math.floor(maxEmptyVArea / (this._minRows +1));
|
|
|
|
maxHSpacing = Math.floor(maxEmptyHArea / (this._minColumns +1));
|
|
|
|
} else {
|
|
|
|
if (this._minRows <= 1)
|
|
|
|
maxVSpacing = maxEmptyVArea;
|
|
|
|
else
|
|
|
|
maxVSpacing = Math.floor(maxEmptyVArea / (this._minRows - 1));
|
|
|
|
|
|
|
|
if (this._minColumns <= 1)
|
|
|
|
maxHSpacing = maxEmptyHArea;
|
|
|
|
else
|
|
|
|
maxHSpacing = Math.floor(maxEmptyHArea / (this._minColumns - 1));
|
|
|
|
}
|
2013-08-27 19:23:13 +00:00
|
|
|
|
|
|
|
let maxSpacing = Math.min(maxHSpacing, maxVSpacing);
|
|
|
|
// Limit spacing to the item size
|
2013-08-15 08:38:17 +00:00
|
|
|
maxSpacing = Math.min(maxSpacing, Math.min(this._getVItemSize(), this._getHItemSize()));
|
|
|
|
// The minimum spacing, regardless of whether it satisfies the row/columng minima,
|
2013-08-27 19:23:13 +00:00
|
|
|
// is the spacing we get from CSS.
|
2013-08-23 09:14:21 +00:00
|
|
|
let spacing = Math.max(this._spacing, maxSpacing);
|
|
|
|
this.setSpacing(spacing);
|
|
|
|
if (this._padWithSpacing)
|
|
|
|
this.topPadding = this.rightPadding = this.bottomPadding = this.leftPadding = spacing;
|
2013-08-15 08:38:17 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function must to be called before iconGrid allocation,
|
|
|
|
* to know how much spacing can the grid has
|
|
|
|
*/
|
|
|
|
adaptToSize: function(availWidth, availHeight) {
|
|
|
|
this._fixedHItemSize = this._hItemSize;
|
|
|
|
this._fixedVItemSize = this._vItemSize;
|
|
|
|
this._updateSpacingForSize(availWidth, availHeight);
|
|
|
|
let spacing = this._getSpacing();
|
|
|
|
|
|
|
|
if (this.columnsForWidth(availWidth) < this._minColumns || this.rowsForHeight(availHeight) < this._minRows) {
|
|
|
|
let neededWidth = this.usedWidthForNColumns(this._minColumns) - availWidth ;
|
|
|
|
let neededHeight = this.usedHeightForNRows(this._minRows) - availHeight ;
|
|
|
|
|
|
|
|
let neededSpacePerItem = (neededWidth > neededHeight) ? Math.ceil(neededWidth / this._minColumns)
|
|
|
|
: Math.ceil(neededHeight / this._minRows);
|
|
|
|
this._fixedHItemSize = Math.max(this._hItemSize - neededSpacePerItem, MIN_ICON_SIZE);
|
|
|
|
this._fixedVItemSize = Math.max(this._vItemSize - neededSpacePerItem, MIN_ICON_SIZE);
|
|
|
|
|
|
|
|
this._updateSpacingForSize(availWidth, availHeight);
|
|
|
|
}
|
2014-08-17 17:44:52 +00:00
|
|
|
Meta.later_add(Meta.LaterType.BEFORE_REDRAW,
|
|
|
|
Lang.bind(this, this._updateIconSizes));
|
2013-08-15 08:38:17 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Note that this is ICON_SIZE as used by BaseIcon, not elsewhere in IconGrid; it's a bit messed up
|
2014-08-17 17:44:52 +00:00
|
|
|
_updateIconSizes: function() {
|
|
|
|
let scale = Math.min(this._fixedHItemSize, this._fixedVItemSize) / Math.max(this._hItemSize, this._vItemSize);
|
2014-06-17 22:04:34 +00:00
|
|
|
let newIconSize = Math.floor(ICON_SIZE * scale);
|
2013-08-15 08:38:17 +00:00
|
|
|
for (let i in this._items) {
|
|
|
|
this._items[i].icon.setIconSize(newIconSize);
|
|
|
|
}
|
2013-08-27 19:23:13 +00:00
|
|
|
}
|
2013-08-20 08:14:25 +00:00
|
|
|
});
|
2014-03-20 13:48:58 +00:00
|
|
|
Signals.addSignalMethods(IconGrid.prototype);
|
2013-08-20 08:14:25 +00:00
|
|
|
|
|
|
|
const PaginatedIconGrid = new Lang.Class({
|
|
|
|
Name: 'PaginatedIconGrid',
|
|
|
|
Extends: IconGrid,
|
|
|
|
|
|
|
|
_init: function(params) {
|
|
|
|
this.parent(params);
|
|
|
|
this._nPages = 0;
|
2014-06-17 17:10:54 +00:00
|
|
|
this.currentPage = 0;
|
2013-09-05 15:59:41 +00:00
|
|
|
this._rowsPerPage = 0;
|
|
|
|
this._spaceBetweenPages = 0;
|
|
|
|
this._childrenPerPage = 0;
|
2013-08-20 08:14:25 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_getPreferredHeight: function (grid, forWidth, alloc) {
|
2013-08-23 09:14:21 +00:00
|
|
|
alloc.min_size = (this._availableHeightPerPageForItems() + this.bottomPadding + this.topPadding) * this._nPages + this._spaceBetweenPages * this._nPages;
|
|
|
|
alloc.natural_size = (this._availableHeightPerPageForItems() + this.bottomPadding + this.topPadding) * this._nPages + this._spaceBetweenPages * this._nPages;
|
2013-08-20 08:14:25 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_allocate: function (grid, box, flags) {
|
|
|
|
if (this._childrenPerPage == 0)
|
|
|
|
log('computePages() must be called before allocate(); pagination will not work.');
|
|
|
|
|
|
|
|
if (this._fillParent) {
|
|
|
|
// Reset the passed in box to fill the parent
|
|
|
|
let parentBox = this.actor.get_parent().allocation;
|
|
|
|
let gridBox = this.actor.get_theme_node().get_content_box(parentBox);
|
|
|
|
box = this._grid.get_theme_node().get_content_box(gridBox);
|
|
|
|
}
|
|
|
|
let children = this._getVisibleChildren();
|
|
|
|
let availWidth = box.x2 - box.x1;
|
|
|
|
let availHeight = box.y2 - box.y1;
|
|
|
|
let spacing = this._getSpacing();
|
|
|
|
let [nColumns, usedWidth] = this._computeLayout(availWidth);
|
|
|
|
|
2013-08-23 09:14:21 +00:00
|
|
|
let leftEmptySpace;
|
2013-08-20 08:14:25 +00:00
|
|
|
switch(this._xAlign) {
|
|
|
|
case St.Align.START:
|
2013-08-23 09:14:21 +00:00
|
|
|
leftEmptySpace = 0;
|
2013-08-20 08:14:25 +00:00
|
|
|
break;
|
|
|
|
case St.Align.MIDDLE:
|
2013-08-23 09:14:21 +00:00
|
|
|
leftEmptySpace = Math.floor((availWidth - usedWidth) / 2);
|
2013-08-20 08:14:25 +00:00
|
|
|
break;
|
|
|
|
case St.Align.END:
|
2013-08-23 09:14:21 +00:00
|
|
|
leftEmptySpace = availWidth - usedWidth;
|
2013-08-20 08:14:25 +00:00
|
|
|
}
|
|
|
|
|
2013-08-23 09:14:21 +00:00
|
|
|
let x = box.x1 + leftEmptySpace + this.leftPadding;
|
|
|
|
let y = box.y1 + this.topPadding;
|
2013-08-20 08:14:25 +00:00
|
|
|
let columnIndex = 0;
|
|
|
|
let rowIndex = 0;
|
|
|
|
|
|
|
|
for (let i = 0; i < children.length; i++) {
|
|
|
|
let childBox = this._calculateChildBox(children[i], x, y, box);
|
|
|
|
children[i].allocate(childBox, flags);
|
|
|
|
this._grid.set_skip_paint(children[i], false);
|
|
|
|
|
|
|
|
columnIndex++;
|
|
|
|
if (columnIndex == nColumns) {
|
|
|
|
columnIndex = 0;
|
|
|
|
rowIndex++;
|
|
|
|
}
|
|
|
|
if (columnIndex == 0) {
|
2013-08-15 08:38:17 +00:00
|
|
|
y += this._getVItemSize() + spacing;
|
2013-08-20 08:14:25 +00:00
|
|
|
if ((i + 1) % this._childrenPerPage == 0)
|
2013-08-15 08:38:17 +00:00
|
|
|
y += this._spaceBetweenPages - spacing + this.bottomPadding + this.topPadding;
|
2013-08-23 09:14:21 +00:00
|
|
|
x = box.x1 + leftEmptySpace + this.leftPadding;
|
2013-08-15 08:38:17 +00:00
|
|
|
} else
|
|
|
|
x += this._getHItemSize() + spacing;
|
2013-08-20 08:14:25 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-06-17 17:10:54 +00:00
|
|
|
// Overriden from IconGrid
|
|
|
|
_getChildrenToAnimate: function() {
|
|
|
|
let children = this._getVisibleChildren();
|
|
|
|
let firstIndex = this._childrenPerPage * this.currentPage;
|
|
|
|
let lastIndex = firstIndex + this._childrenPerPage;
|
|
|
|
|
|
|
|
return children.slice(firstIndex, lastIndex);
|
|
|
|
},
|
|
|
|
|
2013-08-15 08:38:17 +00:00
|
|
|
_computePages: function (availWidthPerPage, availHeightPerPage) {
|
2013-08-20 08:14:25 +00:00
|
|
|
let [nColumns, usedWidth] = this._computeLayout(availWidthPerPage);
|
|
|
|
let nRows;
|
|
|
|
let children = this._getVisibleChildren();
|
|
|
|
if (nColumns > 0)
|
|
|
|
nRows = Math.ceil(children.length / nColumns);
|
|
|
|
else
|
|
|
|
nRows = 0;
|
|
|
|
if (this._rowLimit)
|
|
|
|
nRows = Math.min(nRows, this._rowLimit);
|
|
|
|
|
|
|
|
let spacing = this._getSpacing();
|
2013-08-23 09:14:21 +00:00
|
|
|
// We want to contain the grid inside the parent box with padding
|
2013-08-30 16:50:35 +00:00
|
|
|
this._rowsPerPage = this.rowsForHeight(availHeightPerPage);
|
2013-08-20 08:14:25 +00:00
|
|
|
this._nPages = Math.ceil(nRows / this._rowsPerPage);
|
2013-08-30 16:50:35 +00:00
|
|
|
this._spaceBetweenPages = availHeightPerPage - (this.topPadding + this.bottomPadding) - this._availableHeightPerPageForItems();
|
2013-08-20 08:14:25 +00:00
|
|
|
this._childrenPerPage = nColumns * this._rowsPerPage;
|
|
|
|
},
|
|
|
|
|
2013-08-15 08:38:17 +00:00
|
|
|
adaptToSize: function(availWidth, availHeight) {
|
|
|
|
this.parent(availWidth, availHeight);
|
|
|
|
this._computePages(availWidth, availHeight);
|
|
|
|
},
|
|
|
|
|
2013-08-20 08:14:25 +00:00
|
|
|
_availableHeightPerPageForItems: function() {
|
2013-08-30 16:50:35 +00:00
|
|
|
return this.usedHeightForNRows(this._rowsPerPage) - (this.topPadding + this.bottomPadding);
|
2013-08-20 08:14:25 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
nPages: function() {
|
|
|
|
return this._nPages;
|
|
|
|
},
|
|
|
|
|
appDisplay: Make page panning smoother on touch
Currently, our logic for page panning isn't great. If the user starts a
pan upwards and hesitates over a new page, we'll go to the *next* page
on release, since the difference is greater, but the velocity wound down
to 0.
Instead of trying to treat it like page down or scrolls, simply do the
math to find the page where the user scrolled to.
This is unfortunately broken for fast swipes, since the user doesn't get
far enough into the new page to make a difference. I'm getting the
impression we'll need a gesture recognizer for this, though, however
crude. Simple hacks I tried, like a velocity multiplier, didn't work
properly.
https://bugzilla.gnome.org/show_bug.cgi?id=729064
2014-04-27 15:18:04 +00:00
|
|
|
getPageHeight: function() {
|
|
|
|
return this._availableHeightPerPageForItems();
|
|
|
|
},
|
|
|
|
|
2013-08-20 08:14:25 +00:00
|
|
|
getPageY: function(pageNumber) {
|
|
|
|
if (!this._nPages)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
let firstPageItem = pageNumber * this._childrenPerPage
|
|
|
|
let childBox = this._getVisibleChildren()[firstPageItem].get_allocation_box();
|
2013-08-23 09:14:21 +00:00
|
|
|
return childBox.y1 - this.topPadding;
|
2013-08-27 19:22:16 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getItemPage: function(item) {
|
|
|
|
let children = this._getVisibleChildren();
|
|
|
|
let index = children.indexOf(item);
|
|
|
|
if (index == -1) {
|
|
|
|
throw new Error('Item not found.');
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return Math.floor(index / this._childrenPerPage);
|
2013-09-01 19:49:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* openExtraSpace:
|
|
|
|
* @sourceItem: the item for which to create extra space
|
|
|
|
* @side: where @sourceItem should be located relative to the created space
|
|
|
|
* @nRows: the amount of space to create
|
|
|
|
*
|
|
|
|
* Pan view to create extra space for @nRows above or below @sourceItem.
|
|
|
|
*/
|
|
|
|
openExtraSpace: function(sourceItem, side, nRows) {
|
|
|
|
let children = this._getVisibleChildren();
|
|
|
|
let index = children.indexOf(sourceItem.actor);
|
|
|
|
if (index == -1) {
|
|
|
|
throw new Error('Item not found.');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let pageIndex = Math.floor(index / this._childrenPerPage);
|
|
|
|
let pageOffset = pageIndex * this._childrenPerPage;
|
|
|
|
|
|
|
|
let childrenPerRow = this._childrenPerPage / this._rowsPerPage;
|
|
|
|
let sourceRow = Math.floor((index - pageOffset) / childrenPerRow);
|
|
|
|
|
|
|
|
let nRowsAbove = (side == St.Side.TOP) ? sourceRow + 1
|
|
|
|
: sourceRow;
|
|
|
|
let nRowsBelow = this._rowsPerPage - nRowsAbove;
|
|
|
|
|
|
|
|
let nRowsUp, nRowsDown;
|
|
|
|
if (side == St.Side.TOP) {
|
|
|
|
nRowsDown = Math.min(nRowsBelow, nRows);
|
|
|
|
nRowsUp = nRows - nRowsDown;
|
|
|
|
} else {
|
|
|
|
nRowsUp = Math.min(nRowsAbove, nRows);
|
|
|
|
nRowsDown = nRows - nRowsUp;
|
|
|
|
}
|
|
|
|
|
|
|
|
let childrenDown = children.splice(pageOffset +
|
|
|
|
nRowsAbove * childrenPerRow,
|
|
|
|
nRowsBelow * childrenPerRow);
|
|
|
|
let childrenUp = children.splice(pageOffset,
|
|
|
|
nRowsAbove * childrenPerRow);
|
|
|
|
|
|
|
|
// Special case: On the last row with no rows below the icon,
|
|
|
|
// there's no need to move any rows either up or down
|
|
|
|
if (childrenDown.length == 0 && nRowsUp == 0) {
|
|
|
|
this._translatedChildren = [];
|
|
|
|
this.emit('space-opened');
|
|
|
|
} else {
|
|
|
|
this._translateChildren(childrenUp, Gtk.DirectionType.UP, nRowsUp);
|
|
|
|
this._translateChildren(childrenDown, Gtk.DirectionType.DOWN, nRowsDown);
|
|
|
|
this._translatedChildren = childrenUp.concat(childrenDown);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_translateChildren: function(children, direction, nRows) {
|
2013-09-04 07:34:50 +00:00
|
|
|
let translationY = nRows * (this._getVItemSize() + this._getSpacing());
|
2013-09-01 19:49:57 +00:00
|
|
|
if (translationY == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (direction == Gtk.DirectionType.UP)
|
|
|
|
translationY *= -1;
|
|
|
|
|
|
|
|
for (let i = 0; i < children.length; i++) {
|
|
|
|
children[i].translation_y = 0;
|
|
|
|
let params = { translation_y: translationY,
|
|
|
|
time: EXTRA_SPACE_ANIMATION_TIME,
|
|
|
|
transition: 'easeInOutQuad'
|
|
|
|
};
|
|
|
|
if (i == (children.length - 1))
|
|
|
|
params.onComplete = Lang.bind(this,
|
|
|
|
function() {
|
|
|
|
this.emit('space-opened');
|
|
|
|
});
|
|
|
|
Tweener.addTween(children[i], params);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
closeExtraSpace: function() {
|
|
|
|
if (!this._translatedChildren || !this._translatedChildren.length) {
|
|
|
|
this.emit('space-closed');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0; i < this._translatedChildren.length; i++) {
|
|
|
|
if (!this._translatedChildren[i].translation_y)
|
|
|
|
continue;
|
|
|
|
Tweener.addTween(this._translatedChildren[i],
|
|
|
|
{ translation_y: 0,
|
|
|
|
time: EXTRA_SPACE_ANIMATION_TIME,
|
|
|
|
transition: 'easeInOutQuad',
|
|
|
|
onComplete: Lang.bind(this,
|
|
|
|
function() {
|
|
|
|
this.emit('space-closed');
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
2010-07-21 02:22:19 +00:00
|
|
|
}
|
2011-11-20 17:56:27 +00:00
|
|
|
});
|
2013-09-01 19:49:57 +00:00
|
|
|
Signals.addSignalMethods(PaginatedIconGrid.prototype);
|