From 127cb501b9b913219d91e4a944aed6edbe96714d Mon Sep 17 00:00:00 2001 From: Hank Date: Thu, 23 Jun 2022 17:05:08 +0200 Subject: [PATCH] More fixes --- apps/hwid_a_battery_widget/widget.js | 56 ++++++++++++++-------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/apps/hwid_a_battery_widget/widget.js b/apps/hwid_a_battery_widget/widget.js index 103ad2fb1..bd1c4e0c5 100644 --- a/apps/hwid_a_battery_widget/widget.js +++ b/apps/hwid_a_battery_widget/widget.js @@ -27,44 +27,42 @@ var s = 29; var x = this.x; var y = this.y; + if ((typeof x === 'undefined') || (typeof y === 'undefined')) { + } else { + const l = E.getBattery(); + let xl = x+4+l*(s-12)/100; + if (l != old_l){ // Delete the old value from screen + let xl_old = x+4+old_l*(s-12)/100; + g.setColor(COLORS.white); + // g.fillRect(x+2,y+5,x+s-6,y+18); + g.fillRect(x,y,xl+4,y+16+3); //Clear + g.setFontAlign(0,0); + g.setFont('Vector',16); + //g.fillRect(old_x,old_y,old_x+4+l*(s-12)/100,old_y+16+3); // clear (lazy) + g.drawString(old_l, old_x + 14, old_y + 10); + g.fillRect(x+4,y+14+3,xl_old,y+16+3); // charging bar + old_l = l; + } + + //console.log(old_x); - const l = E.getBattery(); - let xl = x+4+l*(s-12)/100; - if (l != old_l){ // Delete the old value from screen - let xl_old = x+4+old_l*(s-12)/100; - g.setColor(COLORS.white); - // g.fillRect(x+2,y+5,x+s-6,y+18); - g.fillRect(x,y,xl+4,y+16+3); //Clear + g.setColor(levelColor(l)); + g.fillRect(x+4,y+14+3,xl,y+16+3); // charging bar + g.fillRect((x+4+100*(s-12)/100)-1,y+14+3,x+4+100*(s-12)/100,y+16+3); // charging bar "full mark" + // Show percentage + g.setColor(COLORS.black); g.setFontAlign(0,0); g.setFont('Vector',16); - //g.fillRect(old_x,old_y,old_x+4+l*(s-12)/100,old_y+16+3); // clear (lazy) - g.drawString(old_l, old_x + 14, old_y + 10); - g.fillRect(x+4,y+14+3,xl_old,y+16+3); // charging bar - old_l = l; + g.drawString(l, x + 14, y + 10); + } - - //console.log(old_x); - old_x = this.x; - old_y = this.y; - - g.setColor(levelColor(l)); - g.fillRect(x+4,y+14+3,xl,y+16+3); // charging bar - g.fillRect((x+4+100*(s-12)/100)-1,y+14+3,x+4+100*(s-12)/100,y+16+3); // charging bar "full mark" - // Show percentage - g.setColor(COLORS.black); - g.setFontAlign(0,0); - g.setFont('Vector',16); - g.drawString(l, x + 14, y + 10); - - - + old_x = this.x; + old_y = this.y; if (Bangle.isCharging()) changeInterval(id, intervalHigh); else changeInterval(id, intervalLow); } - - Bangle.on('charging',function(charging) { draw(); }); var id = setInterval(()=>WIDGETS["wid_a_battery_widget"].draw(), intervalLow);