Skip to content

Commit fec5eb0

Browse files
author
thyttan
committed
voldisp: make sure widgets wont draw over volume bar
1 parent 0539ab9 commit fec5eb0

File tree

1 file changed

+41
-11
lines changed

1 file changed

+41
-11
lines changed

apps/voldisp/boot.js

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,44 @@
44
if (timeout) {clearTimeout(timeout); timeout=undefined;}
55

66
if (Bangle.CLOCK) {
7+
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+
35+
let isAllWidgetsHidden = true;
36+
if (global.WIDGETS) {
37+
for (var w of global.WIDGETS) {
38+
if (!w._draw) {
39+
isAllWidgetsHidden = false;
40+
break;
41+
}
42+
}
43+
}
44+
WIDGET_UTILS_HIDE();
745
let barWidth = g.getWidth()*volPercent/100;
846
g.
947
setColor(0x0000).fillRect(0,0,g.getWidth(),24).
@@ -12,17 +50,9 @@
1250
drawString("volume",barWidth,1);
1351

1452
let goAway = ()=>{
15-
let isAllWidgetsHidden = true;
16-
if (global.WIDGETS) {
17-
for (var w of global.WIDGETS) {
18-
if (!w._draw) {
19-
isAllWidgetsHidden = false;
20-
break;
21-
}
22-
}
23-
}
2453
if (!isAllWidgetsHidden) {
25-
Bangle.drawWidgets();
54+
g.reset().clearRect(0,0,g.getWidth(),24);
55+
WIDGET_UTILS_SHOW();
2656
} else if (Bangle.uiRedraw) {
2757
Bangle.uiRedraw();
2858
} else {
@@ -33,5 +63,5 @@
3363
}
3464
};
3565
Bangle.on("musicVolume", onMusicVolume);
36-
//GB({t:"audio",v:10});
66+
//GB({t:"audio",v:66});
3767
}

0 commit comments

Comments
 (0)