forked from FOSS/BangleApps
commit
e9d66c85e0
|
@ -12,3 +12,4 @@
|
|||
0.12: Add settings to hide date,widgets
|
||||
0.13: Add font setting
|
||||
0.14: Use ClockFace_menu.addItems
|
||||
0.15: Add Power saving option
|
|
@ -7,4 +7,5 @@ A simple digital clock showing seconds as a horizontal bar.
|
|||
|
||||
## Settings
|
||||
* `Show date`: display date at the bottom of screen
|
||||
* `Font`: choose between bitmap or vector fonts
|
||||
* `Font`: choose between bitmap or vector fonts
|
||||
* `Power saving`: (Bangle.js 2 only) don't draw the seconds bar while the watch is locked
|
|
@ -13,16 +13,20 @@ let locale = require("locale");
|
|||
locale.hasMeridian = (locale.meridian(date)!=="");
|
||||
}
|
||||
|
||||
let barW = 0, prevX = 0;
|
||||
function renderBar(l) {
|
||||
if (!this.fraction) {
|
||||
// zero-size fillRect stills draws one line of pixels, we don't want that
|
||||
return;
|
||||
}
|
||||
const width = this.fraction*l.w;
|
||||
g.fillRect(l.x, l.y, l.x+width-1, l.y+l.height-1);
|
||||
"ram";
|
||||
if (l) prevX = 0; // called from Layout: drawing area was cleared
|
||||
else l = clock.layout.bar;
|
||||
let x2 = l.x+barW;
|
||||
if (clock.powerSave && Bangle.isLocked()) x2 = 0; // hide bar
|
||||
if (x2===prevX) return; // nothing to do
|
||||
if (x2===0) x2--; // don't leave 1px line
|
||||
if (x2<Math.max(0, prevX)) g.setBgColor(l.bgCol || g.theme.bg).clearRect(x2+1, l.y, prevX, l.y2);
|
||||
else g.setColor(l.col || g.theme.fg).fillRect(prevX+1, l.y, x2, l.y2);
|
||||
prevX = x2;
|
||||
}
|
||||
|
||||
|
||||
function timeText(date) {
|
||||
if (!clock.is12Hour) {
|
||||
return locale.time(date, true);
|
||||
|
@ -47,22 +51,21 @@ function dateText(date) {
|
|||
return `${dayName} ${dayMonth}`;
|
||||
}
|
||||
|
||||
|
||||
const ClockFace = require("ClockFace"),
|
||||
clock = new ClockFace({
|
||||
precision:1,
|
||||
settingsFile:'barclock.settings.json',
|
||||
precision: 1,
|
||||
settingsFile: "barclock.settings.json",
|
||||
init: function() {
|
||||
const Layout = require("Layout");
|
||||
this.layout = new Layout({
|
||||
type: "v", c: [
|
||||
{
|
||||
type: "h", c: [
|
||||
{id: "time", label: "88:88", type: "txt", font: "6x8:5", col:g.theme.fg, bgCol: g.theme.bg}, // updated below
|
||||
{id: "ampm", label: " ", type: "txt", font: "6x8:2", col:g.theme.fg, bgCol: g.theme.bg},
|
||||
{id: "time", label: "88:88", type: "txt", font: "6x8:5", col: g.theme.fg, bgCol: g.theme.bg}, // updated below
|
||||
{id: "ampm", label: " ", type: "txt", font: "6x8:2", col: g.theme.fg, bgCol: g.theme.bg},
|
||||
],
|
||||
},
|
||||
{id: "bar", type: "custom", fraction: 0, fillx: 1, height: 6, col: g.theme.fg2, render: renderBar},
|
||||
{id: "bar", type: "custom", fillx: 1, height: 6, col: g.theme.fg2, render: renderBar},
|
||||
this.showDate ? {height: 40} : {},
|
||||
this.showDate ? {id: "date", type: "txt", font: "10%", valign: 1} : {},
|
||||
],
|
||||
|
@ -76,7 +79,8 @@ const ClockFace = require("ClockFace"),
|
|||
this.layout.ampm.label = "";
|
||||
thickness = Math.floor(Bangle.appRect.w/(5*6));
|
||||
}
|
||||
this.layout.bar.height = thickness+1;
|
||||
let bar = this.layout.bar;
|
||||
bar.height = thickness+1;
|
||||
if (this.font===1) { // vector
|
||||
const B2 = process.env.HWVERSION>1;
|
||||
if (this.is12Hour && locale.hasMeridian) {
|
||||
|
@ -89,17 +93,32 @@ const ClockFace = require("ClockFace"),
|
|||
this.layout.time.font = "6x8:"+thickness;
|
||||
}
|
||||
this.layout.update();
|
||||
bar.y2 = bar.y+bar.height-1;
|
||||
},
|
||||
update: function(date, c) {
|
||||
"ram";
|
||||
if (c.m) this.layout.time.label = timeText(date);
|
||||
if (c.h) this.layout.ampm.label = ampmText(date);
|
||||
if (c.d && this.showDate) this.layout.date.label = dateText(date);
|
||||
const SECONDS_PER_MINUTE = 60;
|
||||
if (c.s) this.layout.bar.fraction = date.getSeconds()/SECONDS_PER_MINUTE;
|
||||
this.layout.render();
|
||||
if (c.m) this.layout.render();
|
||||
if (c.s) {
|
||||
barW = Math.round(date.getSeconds()/60*this.layout.bar.w);
|
||||
renderBar();
|
||||
}
|
||||
},
|
||||
resume: function() {
|
||||
prevX = 0; // force redraw of bar
|
||||
this.layout.forgetLazyState();
|
||||
},
|
||||
});
|
||||
|
||||
// power saving: only update once a minute while locked, hide bar
|
||||
if (clock.powerSave) {
|
||||
Bangle.on("lock", lock => {
|
||||
clock.precision = lock ? 60 : 1;
|
||||
clock.tick();
|
||||
renderBar(); // hide/redraw bar right away
|
||||
});
|
||||
}
|
||||
|
||||
clock.start();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "barclock",
|
||||
"name": "Bar Clock",
|
||||
"version": "0.14",
|
||||
"version": "0.15",
|
||||
"description": "A simple digital clock showing seconds as a bar",
|
||||
"icon": "clock-bar.png",
|
||||
"screenshots": [{"url":"screenshot.png"},{"url":"screenshot_pm.png"}],
|
||||
|
|
|
@ -17,10 +17,14 @@
|
|||
onchange: v => save("font", v),
|
||||
},
|
||||
};
|
||||
require("ClockFace_menu").addItems(menu, save, {
|
||||
let items = {
|
||||
showDate: s.showDate,
|
||||
loadWidgets: s.loadWidgets,
|
||||
});
|
||||
|
||||
};
|
||||
// Power saving for Bangle.js 1 doesn't make sense (no updates while screen is off anyway)
|
||||
if (process.env.HWVERSION>1) {
|
||||
items.powerSave = s.powerSave;
|
||||
}
|
||||
require("ClockFace_menu").addItems(menu, save, items);
|
||||
E.showMenu(menu);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue