dash: Rework _adjustIconSize()

The current code uses the dash's height and current icon size to
calculate the new icon size. However, the height does not correctly
relate to the icon size while the icons are animating, in which
case the resulting icon size may be wrong.
Rework the function to be independent from the actual icon sizes,
so that a correct size is calculated even when called during an
animation.

https://bugzilla.gnome.org/show_bug.cgi?id=649248
This commit is contained in:
Florian Müllner 2011-09-20 17:59:25 +02:00
parent 790b9d3371
commit a4b69db8af

View File

@ -394,8 +394,18 @@ Dash.prototype = {
}, },
_adjustIconSize: function() { _adjustIconSize: function() {
let children = this._box.get_children(); // For the icon size, we only consider children which are "proper"
if (children.length == 0) { // icons (i.e. ignoring drag placeholders) and which are not
// animating out (which means they will be destroyed at the end of
// the animation)
let iconChildren = this._box.get_children().filter(function(actor) {
return actor._delegate.child &&
actor._delegate.child._delegate &&
actor._delegate.child._delegate.icon &&
!actor._delegate.animatingOut;
});
if (iconChildren.length == 0) {
this._box.add_style_pseudo_class('empty'); this._box.add_style_pseudo_class('empty');
return; return;
} }
@ -405,36 +415,39 @@ Dash.prototype = {
if (this._maxHeight == -1) if (this._maxHeight == -1)
return; return;
// Hide actors which are about to be removed to not take
// them into account when adjusting the icon size ...
let hidingChildren = children.filter(function(actor) {
return actor._delegate.animatingOut;
});
for (let i = 0; i < hidingChildren.length; i++) let themeNode = this.actor.get_theme_node();
hidingChildren[i].hide(); let maxAllocation = new Clutter.ActorBox({ x1: 0, y1: 0,
x2: 42 /* whatever */,
let iconChildren = children.filter(function(actor) { y2: this._maxHeight });
return actor.visible && let maxContent = themeNode.get_content_box(maxAllocation);
actor._delegate.child && let availHeight = maxContent.y2 - maxContent.y1;
actor._delegate.child._delegate && let spacing = themeNode.get_length('spacing');
actor._delegate.child._delegate.icon;
});
// Compute the amount of extra space (or missing space) we have let firstIcon = iconChildren[0]._delegate.child._delegate.icon;
// per icon with the current icon size
let [minHeight, natHeight] = this.actor.get_preferred_height(-1);
let diff = (this._maxHeight - natHeight) / iconChildren.length;
for (let i = 0; i < hidingChildren.length; i++) // Icons may be animating, so enforce the current icon size
hidingChildren[i].show(); // during the size request
let [currentWidth, currentHeight] = firstIcon.icon.get_size();
firstIcon.icon.set_size(this.iconSize, this.iconSize);
let [minHeight, natHeight] = iconChildren[0].get_preferred_height(-1);
firstIcon.icon.set_size(currentWidth, currentHeight);
// Subtract icon padding and box spacing from the available height
availHeight -= iconChildren.length * (natHeight - this.iconSize) +
(iconChildren.length - 1) * spacing;
let availSize = availHeight / iconChildren.length;
let iconSizes = [ 16, 22, 24, 32, 48, 64 ]; let iconSizes = [ 16, 22, 24, 32, 48, 64 ];
let newIconSize = 16; let newIconSize = 16;
for (let i = 0; i < iconSizes.length; i++) { for (let i = 0; i < iconSizes.length; i++) {
if (iconSizes[i] < this.iconSize + diff) if (iconSizes[i] < availSize)
newIconSize = iconSizes[i]; newIconSize = iconSizes[i];
} }