-
Notifications
You must be signed in to change notification settings - Fork 2
/
progress_bar.js
126 lines (106 loc) · 3.43 KB
/
progress_bar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
const St = imports.gi.St;
const Lang = imports.lang;
const Params = imports.misc.params;
const Tweener = imports.ui.tweener;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Utils = Me.imports.utils;
const EverpadProgressBar = new Lang.Class({
Name: "EverpadProgressBar",
_init: function(params) {
this._params = Params.parse(params, {
box_style_class: 'everpad-progress-bar-box',
progress_style_class: 'everpad-progress-bar',
animation_time: 0.7,
steps: 10,
expand: false,
x_fill: false,
y_fill: true,
x_align: St.Align.START,
y_align: St.Align.MIDDLE
});
this.actor = new St.Table({
style_class: this._params.box_style_class,
homogeneous: false
});
this.visible = true;
this._progress_bar = new St.BoxLayout({
style_class: this._params.progress_style_class
});
this.actor.add(this._progress_bar, {
row: 0,
col: 0,
expand: this._params.expand,
x_fill: this._params.x_fill,
y_fill: this._params.y_fill,
x_align: this._params.x_align,
y_align: this._params.y_align
});
this.reset();
},
set_progress: function(progress) {
let box_border = this.actor.get_theme_node().get_length('border');
let progress_border = this.actor.get_theme_node().get_length('border');
progress = Math.ceil(this.actor.width / this._params.steps * progress);
progress = progress - (box_border + progress_border);
Tweener.removeTweens(this._progress_bar);
Tweener.addTween(this._progress_bar, {
time: this._params.animation_time,
transition: "easeOutQuad",
width: progress
});
},
set_progress_label: function(text) {
if(!this._progress_label) {
this._progress_label = new St.Label({
style_class: 'everpad-progress-bar-label'
});
this.actor.add(this._progress_label, {
row: 0,
col: 0,
expand: false,
y_fill: false,
x_fill: false,
x_align: St.Align.MIDDLE,
y_align: St.Align.MIDDLE
});
}
this._progress_label.show();
Utils.label_transition(this._progress_label, text, 0.3);
},
reset: function() {
this._progress_bar.width = 0;
if(this._progress_label) {
this._progress_label.hide();
}
},
destroy: function() {
this.actor.destroy();
this._params = null;
},
show: function() {
if(this.visible) return;
this.visible = true;
this.actor.opacity = 0;
this.actor.show();
Tweener.removeTweens(this.actor);
Tweener.addTween(this.actor, {
time: 0.3,
transition: 'easeOutQuad',
opacity: 255
});
},
hide: function() {
if(!this.visible) return;
this.visible = false;
Tweener.removeTweens(this.actor);
Tweener.addTween(this.actor, {
time: 0.3,
transition: 'easeOutQuad',
opacity: 0,
onComplete: Lang.bind(this, function() {
this.actor.hide();
})
});
}
});