Skip to content

Commit 1fa489b

Browse files
author
thyttan
committed
voldisp: fix logic re hide/show widgets and how to goAway
Also small optimization.
1 parent 500296a commit 1fa489b

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

apps/voldisp/boot.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,28 @@
2626
}
2727
};
2828

29+
let isWeHidingTheWidgets = false;
2930
let timeout;
3031
let onMusicVolume = (volPercent)=>{
3132
if (timeout) {clearTimeout(timeout);}
3233

3334
if (Bangle.CLOCK) {
3435

3536
let isAllWidgetsHidden = true;
36-
if (global.WIDGETS) {
37-
for (var w of global.WIDGETS) {
38-
if (!w._draw) {
39-
isAllWidgetsHidden = false;
40-
break;
37+
if (!timeout) { // No need to do this if we already did it before and it wasn't undone. I.e. the timout to execute `goAway` never ran out.
38+
if (global.WIDGETS) {
39+
for (var w of global.WIDGETS) {
40+
if (!w._draw) {
41+
isAllWidgetsHidden = false;
42+
break;
43+
}
4144
}
4245
}
46+
if (!isAllWidgetsHidden) {
47+
WIDGET_UTILS_HIDE();
48+
isWeHidingTheWidgets = true; // Remember if it was we who hid the widgets between draws of the volume bar.
49+
}
4350
}
44-
if (!timeout) {WIDGET_UTILS_HIDE();}
4551
let barWidth = g.getWidth()*volPercent/100;
4652
g.
4753
setColor(0x0000).fillRect(0,0,g.getWidth(),24).
@@ -50,9 +56,10 @@
5056
drawString("volume",barWidth,1);
5157

5258
let goAway = ()=>{
53-
if (!isAllWidgetsHidden) {
59+
if (isWeHidingTheWidgets) {
5460
g.reset().clearRect(0,0,g.getWidth(),24);
5561
WIDGET_UTILS_SHOW();
62+
isWeHidingTheWidgets = false;
5663
} else if (Bangle.uiRedraw) {
5764
Bangle.uiRedraw();
5865
} else {

0 commit comments

Comments
 (0)