From 97785aadbd5b74019ff1c1063dc1e8a2365e603e Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Tue, 3 Sep 2024 23:46:05 +0200 Subject: [PATCH] Add time line --- apps/dutchclock/app.js | 30 +++++++++++++++++++++++------- apps/dutchclock/metadata.json | 2 +- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/apps/dutchclock/app.js b/apps/dutchclock/app.js index df655c1f2..135cfa5ae 100644 --- a/apps/dutchclock/app.js +++ b/apps/dutchclock/app.js @@ -76,6 +76,7 @@ function tick() { function draw() { // work out how to display the current time const timeLines = getTimeLines(mins); + const bottomLines = getBottomLines(); // Reset the state of the graphics library g.clear(true); @@ -85,12 +86,13 @@ function draw() { g.setFontAlign(0,0); // align center top g.drawString(timeLines.join("\n"), X, Y, true /*clear background*/); - // draw the date, in a normal font - g.setFont("6x8"); - g.setFontAlign(0,1); // align center bottom - // pad the date - this clears the background if the date were to change length - var dateStr = " "+require("locale").date(date)+" "; - g.drawString(dateStr, SCREEN_WIDTH / 2, SCREEN_HEIGHT - 5, true /*clear background*/); + if (bottomLines.length) { + // draw the time and/or date, in a normal font + g.setFont("6x8"); + g.setFontAlign(0,1); // align center bottom + // pad the date - this clears the background if the date were to change length + g.drawString(bottomLines.join('\n'), SCREEN_WIDTH/2, SCREEN_HEIGHT - 5, true /*clear background*/); + } /* Show launcher when middle button pressed This should be done *before* Bangle.loadWidgets so that @@ -116,7 +118,21 @@ function setFont(timeLines) { } } -function getTimeLines(m) { +function getBottomLines() { + const lines = []; + + if (settings.showTimeLine) { + lines.push(require("locale").time(date)); + } + + if (settings.showDateLine) { + lines.push(`${date.getHours()}:${String(date.getMinutes()).padStart(2, '0')}`); + } + + return lines; + } + + function getTimeLines(m) { switch (settings.variant) { case VARIANT_EXACT: return getExactTimeLines(m); diff --git a/apps/dutchclock/metadata.json b/apps/dutchclock/metadata.json index 9a0bc84a2..d11dbbf41 100644 --- a/apps/dutchclock/metadata.json +++ b/apps/dutchclock/metadata.json @@ -3,7 +3,7 @@ "name": "Dutch Clock", "shortName":"Dutch Clock", "icon": "app.png", - "version":"0.06", + "version":"0.07", "description": "A clock that displays the time the way a Dutch person would respond when asked what time it is.", "type": "clock", "tags": "clock,dutch,text",