Battery Widget: make color depend on level
parent
6b775da0c1
commit
2c84fbd3ae
|
|
@ -326,7 +326,7 @@
|
|||
{ "id": "widbat",
|
||||
"name": "Battery Level Widget",
|
||||
"icon": "widget.png",
|
||||
"version":"0.04",
|
||||
"version":"0.05",
|
||||
"description": "Show the current battery level and charging status in the top right of the clock",
|
||||
"tags": "widget,battery",
|
||||
"type":"widget",
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
0.02: Now refresh battery monitor every minute if LCD on
|
||||
0.03: Tweaks for variable size widget system
|
||||
0.04: Ensure redrawing works with variable size widget system
|
||||
0.05: Change color depending on battery level
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
(function(){
|
||||
var CHARGING = 0x07E0;
|
||||
const levelColor = (l) => {
|
||||
if (Bangle.isCharging()) return 0x07E0; // "Green"
|
||||
if (l >= 50) return 0x05E0; // slightly darker green
|
||||
if (l >= 15) return 0xFD20; // "Orange"
|
||||
return 0xF800; // "Red"
|
||||
}
|
||||
|
||||
function setWidth() {
|
||||
WIDGETS["bat"].width = 40 + (Bangle.isCharging()?16:0);
|
||||
|
|
@ -7,15 +12,17 @@ function setWidth() {
|
|||
function draw() {
|
||||
var s = 39;
|
||||
var x = this.x, y = this.y;
|
||||
const l = E.getBattery(), c = levelColor(l);
|
||||
if (Bangle.isCharging()) {
|
||||
g.setColor(CHARGING).drawImage(atob("DhgBHOBzgc4HOP////////////////////3/4HgB4AeAHgB4AeAHgB4AeAHg"),x,y);
|
||||
g.setColor(c).drawImage(atob(
|
||||
"DhgBHOBzgc4HOP////////////////////3/4HgB4AeAHgB4AeAHgB4AeAHg"),x,y);
|
||||
x+=16;
|
||||
}
|
||||
g.setColor(-1);
|
||||
g.fillRect(x,y+2,x+s-4,y+21);
|
||||
g.clearRect(x+2,y+4,x+s-6,y+19);
|
||||
g.fillRect(x+s-3,y+10,x+s,y+14);
|
||||
g.setColor(CHARGING).fillRect(x+4,y+6,x+4+E.getBattery()*(s-12)/100,y+17);
|
||||
g.setColor(c).fillRect(x+4,y+6,x+4+l*(s-12)/100,y+17);
|
||||
g.setColor(-1);
|
||||
}
|
||||
Bangle.on('charging',function(charging) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue