BangleApps/apps/weather/widget.js

41 lines
1.1 KiB
JavaScript
Raw Normal View History

(() => {
function draw() {
const w = require('weather').load()
if (!w) return;
g.reset();
2020-05-23 02:57:32 +00:00
g.setColor(0).fillRect(this.x, this.y, this.x+this.width-1, this.y+23)
if (w.txt) {
2020-05-23 02:57:32 +00:00
require('weather').drawIcon(w.txt, this.x+10, this.y+8, 7.5);
}
if (w.temp) {
let t = require('locale').temp(w.temp-273.15); // applies conversion
t = t.substr(0, t.length-2); // but we have no room for units
g.setFontAlign(0, 1); // center horizontally at bottom of widget
g.setFont('6x8', 1);
g.setColor(-1)
g.drawString(t, this.x+10, this.y+24)
}
}
function update(weather) {
require('weather').save(weather);
if (!WIDGETS["weather"].width) {
WIDGETS["weather"].width = 20
Bangle.drawWidgets()
} else if (Bangle.isLCDOn()) {
WIDGETS["weather"].draw()
}
}
const _GB = global.GB;
global.GB = (event) => {
if (event.t==="weather") update(event);
if (_GB) setTimeout(_GB, 0, event);
};
WIDGETS["weather"] = {area: "tl", width: 20, draw: draw};
if (!require('weather').load()) {
WIDGETS["weather"].width = 0
}
})();