From 66e4a01bf18da642a636dc250c717431624ffd82 Mon Sep 17 00:00:00 2001 From: olivierbarriere Date: Mon, 27 Mar 2023 11:31:15 -0400 Subject: [PATCH] Vertical Battery Widget: make color depend on level --- apps/widbatv/widget.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/widbatv/widget.js b/apps/widbatv/widget.js index cc52a0f8e..efc42fdad 100644 --- a/apps/widbatv/widget.js +++ b/apps/widbatv/widget.js @@ -14,6 +14,10 @@ WIDGETS["batv"]={area:"tr",width:14,draw:function() { } else { g.clearRect(x,y,x+14,y+24); g.setColor(g.theme.fg).fillRect(x+2,y+2,x+12,y+22).clearRect(x+4,y+4,x+10,y+20).fillRect(x+5,y+1,x+9,y+2); - g.setColor("#0f0").fillRect(x+4,y+20-(E.getBattery()*16/100),x+10,y+20); + var battery = E.getBattery(); + if (battery < 20) {g.setColor("#f00");} + else if (battery < 40) {g.setColor(g.theme.dark ? "#ff0" : "#f80");} + else {g.setColor("#0f0");} + g.fillRect(x+4,y+20-(E.getBattery()*16/100),x+10,y+20); } }};