[widalarmeta] move "Only on clock" check to top of draw

master
Logan B 2025-07-30 20:39:56 -05:00
parent d31c6ca12a
commit 7fc876237d
No known key found for this signature in database
1 changed files with 43 additions and 40 deletions

View File

@ -39,6 +39,13 @@
} // getNextAlarm
function draw(_w, fromInterval) {
// If only show on clock and not on clock
if (config.whenToShow === 1 && !Bangle.CLOCK) {
this.nextAlarm = undefined; // make sure to reload later
return;
}
if (this.nextAlarm === undefined) {
let alarm = getNextAlarm();
if (alarm === undefined) {
@ -56,49 +63,45 @@
let calcWidth = 0;
let drawSeconds = false;
// If always showing, or the clock is visible
if (config.whenToShow === 1 && !Bangle.CLOCK)
return;
// Determine text and width
if (next > 0 && next <= config.maxhours*60*60*1000) {
const hours = Math.floor((next-1) / 3600000).toString();
const minutes = Math.floor(((next-1) % 3600000) / 60000).toString();
const seconds = Math.floor(((next-1) % 60000) / 1000).toString();
drawSeconds = (config.showSeconds & 0b01 && !Bangle.isLocked()) || (config.showSeconds & 0b10 && next <= 1000*60);
// Determine text and width
if (next > 0 && next <= config.maxhours*60*60*1000) {
const hours = Math.floor((next-1) / 3600000).toString();
const minutes = Math.floor(((next-1) % 3600000) / 60000).toString();
const seconds = Math.floor(((next-1) % 60000) / 1000).toString();
drawSeconds = (config.showSeconds & 0b01 && !Bangle.isLocked()) || (config.showSeconds & 0b10 && next <= 1000*60);
g.reset(); // reset the graphics context to defaults (color/font/etc)
g.setFontAlign(-1,0); // center font in y direction
g.clearRect(this.x, this.y, this.x+this.width-1, this.y+23);
g.reset(); // reset the graphics context to defaults (color/font/etc)
g.setFontAlign(-1,0); // center font in y direction
g.clearRect(this.x, this.y, this.x+this.width-1, this.y+23);
var text = "";
if (config.padHours) {
text += hours.padStart(2, '0');
} else {
text += hours;
}
text += ":" + minutes.padStart(2, '0');
if (drawSeconds) {
text += ":" + seconds.padStart(2, '0');
}
if (config.font == 0) {
g.setFont("5x9Numeric7Seg:1x2");
} else if (config.font == 1) {
g.setFont("Teletext5x9Ascii:1x2");
} else {
// Default to this if no other font is set.
g.setFont("6x8:1x2");
}
g.drawString(text, this.x+1, this.y+12);
var text = "";
if (config.padHours) {
text += hours.padStart(2, '0');
} else {
text += hours;
}
text += ":" + minutes.padStart(2, '0');
if (drawSeconds) {
text += ":" + seconds.padStart(2, '0');
}
if (config.font == 0) {
g.setFont("5x9Numeric7Seg:1x2");
} else if (config.font == 1) {
g.setFont("Teletext5x9Ascii:1x2");
} else {
// Default to this if no other font is set.
g.setFont("6x8:1x2");
}
g.drawString(text, this.x+1, this.y+12);
calcWidth = g.stringWidth(text) + 2; // One pixel on each side
this.bellVisible = false;
} else if (config.drawBell && this.numActiveAlarms > 0) {
calcWidth = 24;
// next alarm too far in future, draw only widalarm bell
if (this.bellVisible !== true || fromInterval !== true) {
g.reset().drawImage(atob("GBgBAAAAAAAAABgADhhwDDwwGP8YGf+YMf+MM//MM//MA//AA//AA//AA//AA//AA//AB//gD//wD//wAAAAADwAABgAAAAAAAAA"),this.x,this.y);
this.bellVisible = true;
}
calcWidth = g.stringWidth(text) + 2; // One pixel on each side
this.bellVisible = false;
} else if (config.drawBell && this.numActiveAlarms > 0) {
calcWidth = 24;
// next alarm too far in future, draw only widalarm bell
if (this.bellVisible !== true || fromInterval !== true) {
g.reset().drawImage(atob("GBgBAAAAAAAAABgADhhwDDwwGP8YGf+YMf+MM//MM//MA//AA//AA//AA//AA//AA//AB//gD//wD//wAAAAADwAABgAAAAAAAAA"),this.x,this.y);
this.bellVisible = true;
}
}