From 37236b254e88f06742d82b16da7351d9a70c70d4 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sun, 11 Jun 2023 22:05:18 +0100 Subject: [PATCH] hwid-batt: simplify clearing old widget --- apps/hwid_a_battery_widget/widget.js | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/apps/hwid_a_battery_widget/widget.js b/apps/hwid_a_battery_widget/widget.js index 2c7bd2568..027535051 100644 --- a/apps/hwid_a_battery_widget/widget.js +++ b/apps/hwid_a_battery_widget/widget.js @@ -1,7 +1,6 @@ (function(){ const intervalLow = 60000; // update time when not charging const intervalHigh = 2000; // update time when charging - var old_l; var old_x = this.x; var old_y = this.y; @@ -22,29 +21,15 @@ }; function draw() { - if (typeof old_x === 'undefined') old_x = this.x; - if (typeof old_y === 'undefined') old_y = this.y; var s = width - 1; var x = this.x; var y = this.y; if ((typeof x === 'undefined') || (typeof y === 'undefined')) { } else { + g.clearRect(old_x, old_y, old_x + width, old_y + height); + const l = E.getBattery(); // debug: Math.floor(Math.random() * 101); let xl = x+4+l*(s-12)/100; - if ((l != old_l) && (typeof old_l != 'undefined') ){ // 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); g.setColor(levelColor(l)); g.fillRect(x+4,y+14+3,xl,y+16+3); // charging bar @@ -65,6 +50,7 @@ Bangle.on('charging',function(charging) { draw(); }); var id = setInterval(()=>WIDGETS["hwid_a_battery_widget"].draw(), intervalLow); var width = 30; + var height = 19; WIDGETS["hwid_a_battery_widget"]={area:"tr",width,draw:draw}; })();