Skip to content

Commit 500296a

Browse files
author
thyttan
committed
voldisp: some optimization
Hopefully. And also, probably not needed...
1 parent fec5eb0 commit 500296a

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

apps/voldisp/boot.js

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
{
2+
const WIDGET_UTILS_HIDE = function() {
3+
//exports.cleanup();
4+
if (!global.WIDGETS) return;
5+
g.reset(); // reset colors
6+
for (var w of global.WIDGETS) {
7+
if (w._draw) return; // already hidden
8+
w._draw = w.draw;
9+
w.draw = () => {};
10+
w._area = w.area;
11+
w.area = "";
12+
if (w.x!=undefined) g.clearRect(w.x,w.y,w.x+w.width-1,w.y+23);
13+
}
14+
};
15+
/// Show any hidden widgets
16+
const WIDGET_UTILS_SHOW = function() {
17+
//exports.cleanup();
18+
if (!global.WIDGETS) return;
19+
for (var w of global.WIDGETS) {
20+
if (!w._draw) return; // not hidden
21+
w.draw = w._draw;
22+
w.area = w._area;
23+
delete w._draw;
24+
delete w._area;
25+
w.draw(w);
26+
}
27+
};
28+
229
let timeout;
330
let onMusicVolume = (volPercent)=>{
4-
if (timeout) {clearTimeout(timeout); timeout=undefined;}
31+
if (timeout) {clearTimeout(timeout);}
532

633
if (Bangle.CLOCK) {
734

8-
const WIDGET_UTILS_HIDE = function() {
9-
//exports.cleanup();
10-
if (!global.WIDGETS) return;
11-
g.reset(); // reset colors
12-
for (var w of global.WIDGETS) {
13-
if (w._draw) return; // already hidden
14-
w._draw = w.draw;
15-
w.draw = () => {};
16-
w._area = w.area;
17-
w.area = "";
18-
if (w.x!=undefined) g.clearRect(w.x,w.y,w.x+w.width-1,w.y+23);
19-
}
20-
};
21-
/// Show any hidden widgets
22-
const WIDGET_UTILS_SHOW = function() {
23-
//exports.cleanup();
24-
if (!global.WIDGETS) return;
25-
for (var w of global.WIDGETS) {
26-
if (!w._draw) return; // not hidden
27-
w.draw = w._draw;
28-
w.area = w._area;
29-
delete w._draw;
30-
delete w._area;
31-
w.draw(w);
32-
}
33-
};
34-
3535
let isAllWidgetsHidden = true;
3636
if (global.WIDGETS) {
3737
for (var w of global.WIDGETS) {
@@ -41,7 +41,7 @@
4141
}
4242
}
4343
}
44-
WIDGET_UTILS_HIDE();
44+
if (!timeout) {WIDGET_UTILS_HIDE();}
4545
let barWidth = g.getWidth()*volPercent/100;
4646
g.
4747
setColor(0x0000).fillRect(0,0,g.getWidth(),24).
@@ -58,6 +58,7 @@
5858
} else {
5959
Bangle.load();
6060
}
61+
timeout = undefined;
6162
};
6263
timeout = setTimeout(goAway, 3*1000);
6364
}

0 commit comments

Comments
 (0)