animation: Optionally animate spinner start/stop
In contrast to generic animated icons, it is reasonable to expect spinners to be invisible while inactive. Implement that behavior in the new Spinner class and optionally animate the transitions. https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/316
This commit is contained in:

committed by
Florian Müllner

parent
22e21ad7d1
commit
945a019974
@ -8,7 +8,11 @@ const St = imports.gi.St;
|
||||
const Signals = imports.signals;
|
||||
const Atk = imports.gi.Atk;
|
||||
|
||||
const Tweener = imports.ui.tweener;
|
||||
|
||||
var ANIMATED_ICON_UPDATE_TIMEOUT = 16;
|
||||
var SPINNER_ANIMATION_TIME = 0.3;
|
||||
var SPINNER_ANIMATION_DELAY = 1.0;
|
||||
|
||||
var Animation = new Lang.Class({
|
||||
Name: 'Animation',
|
||||
@ -92,8 +96,46 @@ var Spinner = new Lang.Class({
|
||||
Name: 'Spinner',
|
||||
Extends: AnimatedIcon,
|
||||
|
||||
_init(size) {
|
||||
_init(size, animate=false) {
|
||||
let file = Gio.File.new_for_uri('resource:///org/gnome/shell/theme/process-working.svg');
|
||||
this.parent(file, size);
|
||||
|
||||
this.actor.opacity = 0;
|
||||
this._animate = animate;
|
||||
},
|
||||
|
||||
play() {
|
||||
Tweener.removeTweens(this.actor);
|
||||
|
||||
if (this._animate) {
|
||||
this.parent();
|
||||
Tweener.addTween(this.actor, {
|
||||
opacity: 255,
|
||||
delay: SPINNER_ANIMATION_DELAY,
|
||||
time: SPINNER_ANIMATION_TIME,
|
||||
transition: 'linear'
|
||||
});
|
||||
} else {
|
||||
this.actor.opacity = 255;
|
||||
this.parent();
|
||||
}
|
||||
},
|
||||
|
||||
stop() {
|
||||
Tweener.removeTweens(this.actor);
|
||||
|
||||
if (this._animate) {
|
||||
Tweener.addTween(this.actor, {
|
||||
opacity: 0,
|
||||
time: SPINNER_ANIMATION_TIME,
|
||||
transition: 'linear',
|
||||
onComplete: () => {
|
||||
this.stop(false);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.actor.opacity = 0;
|
||||
this.parent();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user