[baseIcon] Allow setting the icon size from code
The current design features a sidebar where the icon size shrinks automatically to fit more items. Add a setSizeManually parameter to BaseIcon, which disables sizes read from CSS and allows to use BaseIcon.setIconSize() to support this. https://bugzilla.gnome.org/show_bug.cgi?id=625887
This commit is contained in:
parent
8c1bf346a9
commit
01f4dc68b8
@ -15,7 +15,9 @@ function BaseIcon(label, createIcon) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BaseIcon.prototype = {
|
BaseIcon.prototype = {
|
||||||
_init : function(label, createIcon) {
|
_init : function(label, params) {
|
||||||
|
params = Params.parse(params, { createIcon: null,
|
||||||
|
setSizeManually: false });
|
||||||
this.actor = new St.Bin({ style_class: 'overview-icon',
|
this.actor = new St.Bin({ style_class: 'overview-icon',
|
||||||
x_fill: true,
|
x_fill: true,
|
||||||
y_fill: true });
|
y_fill: true });
|
||||||
@ -35,8 +37,9 @@ BaseIcon.prototype = {
|
|||||||
this._name = new St.Label({ text: label });
|
this._name = new St.Label({ text: label });
|
||||||
box.add_actor(this._name);
|
box.add_actor(this._name);
|
||||||
|
|
||||||
if (createIcon)
|
if (params.createIcon)
|
||||||
this.createIcon = createIcon;
|
this.createIcon = params.createIcon;
|
||||||
|
this._setSizeManually = params.setSizeManually;
|
||||||
|
|
||||||
this.icon = this.createIcon(this.iconSize);
|
this.icon = this.createIcon(this.iconSize);
|
||||||
this._iconBin.set_child(this.icon);
|
this._iconBin.set_child(this.icon);
|
||||||
@ -48,17 +51,29 @@ BaseIcon.prototype = {
|
|||||||
throw new Error('no implementation of createIcon in ' + this);
|
throw new Error('no implementation of createIcon in ' + this);
|
||||||
},
|
},
|
||||||
|
|
||||||
_onStyleChanged: function() {
|
setIconSize: function(size) {
|
||||||
let node = this.actor.get_theme_node();
|
if (!this._setSizeManually)
|
||||||
let [success, len] = node.get_length('icon-size', false);
|
throw new Error('setSizeManually has to be set to use setIconsize');
|
||||||
if (success) {
|
|
||||||
if (len == this.iconSize)
|
|
||||||
return;
|
|
||||||
|
|
||||||
this.icon.destroy();
|
this._setIconSize(size);
|
||||||
this.iconSize = len;
|
},
|
||||||
this.icon = this.createIcon(this.iconSize);
|
|
||||||
this._iconBin.set_child(this.icon);
|
_setIconSize: function(size) {
|
||||||
|
if (size == this.iconSize)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.icon.destroy();
|
||||||
|
this.iconSize = size;
|
||||||
|
this.icon = this.createIcon(this.iconSize);
|
||||||
|
this._iconBin.child = this.icon;
|
||||||
|
},
|
||||||
|
|
||||||
|
_onStyleChanged: function() {
|
||||||
|
if (!this._setSizeManually) {
|
||||||
|
let node = this.actor.get_theme_node();
|
||||||
|
let [success, len] = node.get_length('icon-size', false);
|
||||||
|
if (success)
|
||||||
|
this._setIconSize(len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user