From 5e223c24a134bec441b139c555e994ca92ff200f Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Tue, 13 Feb 2024 07:49:06 +0100 Subject: [PATCH 1/2] widadjust: Add option to hide widget --- apps/widadjust/ChangeLog | 1 + apps/widadjust/metadata.json | 2 +- apps/widadjust/settings.js | 5 +++++ apps/widadjust/widget.js | 18 ++++++++++-------- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/apps/widadjust/ChangeLog b/apps/widadjust/ChangeLog index 9b2a8d3c8..5f7738762 100644 --- a/apps/widadjust/ChangeLog +++ b/apps/widadjust/ChangeLog @@ -1,2 +1,3 @@ 0.01: New widget 0.02: Use default Bangle formatter for booleans +0.03: Add option to hide widget diff --git a/apps/widadjust/metadata.json b/apps/widadjust/metadata.json index cef91369f..db82b36e3 100644 --- a/apps/widadjust/metadata.json +++ b/apps/widadjust/metadata.json @@ -2,7 +2,7 @@ "id": "widadjust", "name": "Adjust Clock", "icon": "icon.png", - "version": "0.02", + "version": "0.03", "description": "Adjusts clock continually in the background to counter clock drift", "type": "widget", "tags": "widget", diff --git a/apps/widadjust/settings.js b/apps/widadjust/settings.js index 6743c7fc5..9a19ccf73 100644 --- a/apps/widadjust/settings.js +++ b/apps/widadjust/settings.js @@ -108,6 +108,11 @@ value: settings.debugLog, onchange: v => settings.debugLog = v, }, + + 'Hide Widget': { + value: settings.hide || false, + onchange: v => settings.hide = v, + }, }; E.showMenu(mainMenu); diff --git a/apps/widadjust/widget.js b/apps/widadjust/widget.js index 138833783..38cf0e283 100644 --- a/apps/widadjust/widget.js +++ b/apps/widadjust/widget.js @@ -78,20 +78,22 @@ } function debug(line) { - console.log(line); + //console.log(line); if (debugLogFile !== null) { debugLogFile.write(line + '\n'); } } function draw() { - g.reset().setFont('6x8').setFontAlign(0, 0); - g.clearRect(this.x, this.y, this.x + WIDTH - 1, this.y + 23); - g.drawString(Math.round(clockError), this.x + WIDTH/2, this.y + 9); + if (settings.hide !== true) { + g.reset().setFont('6x8').setFontAlign(0, 0); + g.clearRect(this.x, this.y, this.x + WIDTH - 1, this.y + 23); + g.drawString(Math.round(clockError), this.x + WIDTH/2, this.y + 9); - if (lastPpm !== null) { - g.setFont('4x6').setFontAlign(0, 1); - g.drawString(lastPpm.toFixed(1), this.x + WIDTH/2, this.y + 23); + if (lastPpm !== null) { + g.setFont('4x6').setFontAlign(0, 1); + g.drawString(lastPpm.toFixed(1), this.x + WIDTH/2, this.y + 23); + } } } @@ -208,7 +210,7 @@ let updatedClockError = clockError + (now - lastClockErrorUpdateTime) * ppm / 1000000; return now - updatedClockError; }, - width: WIDTH, + width: settings.hide === true ? 0 : WIDTH, }; if (settings.saveState) { From b21f495cbfb258bae4618bb73069b824c97c05a1 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Tue, 13 Feb 2024 07:56:51 +0100 Subject: [PATCH 2/2] widadjust: reverse hide check --- apps/widadjust/widget.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/apps/widadjust/widget.js b/apps/widadjust/widget.js index 38cf0e283..bc418862d 100644 --- a/apps/widadjust/widget.js +++ b/apps/widadjust/widget.js @@ -85,15 +85,16 @@ } function draw() { - if (settings.hide !== true) { - g.reset().setFont('6x8').setFontAlign(0, 0); - g.clearRect(this.x, this.y, this.x + WIDTH - 1, this.y + 23); - g.drawString(Math.round(clockError), this.x + WIDTH/2, this.y + 9); + if (settings.hide === true) { + return; + } + g.reset().setFont('6x8').setFontAlign(0, 0); + g.clearRect(this.x, this.y, this.x + WIDTH - 1, this.y + 23); + g.drawString(Math.round(clockError), this.x + WIDTH/2, this.y + 9); - if (lastPpm !== null) { - g.setFont('4x6').setFontAlign(0, 1); - g.drawString(lastPpm.toFixed(1), this.x + WIDTH/2, this.y + 23); - } + if (lastPpm !== null) { + g.setFont('4x6').setFontAlign(0, 1); + g.drawString(lastPpm.toFixed(1), this.x + WIDTH/2, this.y + 23); } }