2022-07-07 11:08:39 +00:00
|
|
|
(()=>{
|
2022-07-07 09:54:41 +00:00
|
|
|
function getWidth() {
|
2023-01-05 22:20:24 +00:00
|
|
|
return E.getBattery() <= 30 || Bangle.isCharging() ? 40 : 0;
|
2022-07-07 09:54:41 +00:00
|
|
|
}
|
|
|
|
WIDGETS.minbat={area:"tr",width:getWidth(),draw:function() {
|
|
|
|
if(this.width < 40) return;
|
|
|
|
var s = 39;
|
|
|
|
var bat = E.getBattery();
|
|
|
|
var x = this.x, y = this.y;
|
|
|
|
g.reset();
|
2022-07-07 11:08:39 +00:00
|
|
|
g.clearRect(x,y,x+s,y+24);
|
2022-07-07 09:54:41 +00:00
|
|
|
g.setColor(g.theme.fg).fillRect(x,y+2,x+s-4,y+21).clearRect(x+2,y+4,x+s-6,y+19).fillRect(x+s-3,y+10,x+s,y+14);
|
|
|
|
var barWidth = bat*(s-12)/100;
|
2023-01-05 22:20:24 +00:00
|
|
|
var color = bat < 15 ? "#f00" : (bat <= 30 ? "#f80" : "#0f0");
|
2022-07-07 09:54:41 +00:00
|
|
|
g.setColor(color).fillRect(x+4,y+6,x+4+barWidth,y+17);
|
2022-07-07 11:08:39 +00:00
|
|
|
},update: function() {
|
2022-07-07 09:54:41 +00:00
|
|
|
var newWidth = getWidth();
|
|
|
|
if(newWidth != this.width) {
|
|
|
|
this.width = newWidth;
|
2022-07-07 11:08:39 +00:00
|
|
|
Bangle.drawWidgets();//relayout
|
|
|
|
}else{
|
|
|
|
this.draw();
|
2022-07-07 09:54:41 +00:00
|
|
|
}
|
|
|
|
}};
|
|
|
|
setInterval(()=>{
|
|
|
|
var widget = WIDGETS.minbat;
|
2022-07-07 11:08:39 +00:00
|
|
|
if(widget) {widget.update();}
|
2022-07-07 09:54:41 +00:00
|
|
|
}, 10*60*1000);
|
|
|
|
})();
|