From d4d6d48471eba1e4a633ec0a91576f29e4e3c538 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Tue, 5 Apr 2022 16:48:56 +0100 Subject: [PATCH] better example app --- apps/_example_app/app.js | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/apps/_example_app/app.js b/apps/_example_app/app.js index af367779a..06c254a36 100644 --- a/apps/_example_app/app.js +++ b/apps/_example_app/app.js @@ -1,12 +1,34 @@ // place your const, vars, functions or classes here -// special function to handle display switch on -Bangle.on('lcdPower', (on) => { - if (on) { - // call your app function here - // If you clear the screen, do Bangle.drawWidgets(); +// clear the screen +g.clear(); + +var n = 0; + +// redraw the screen +function draw() { + g.reset().clearRect(Bangle.appRect); + g.setFont("6x8").setFontAlign(0,0).drawString("Up / Down",g.getWidth()/2,g.getHeight()/2 - 20); + g.setFont("Vector",60).setFontAlign(0,0).drawString(n,g.getWidth()/2,g.getHeight()/2 + 30); +} + +// Respond to user input +Bangle.setUI({mode: "updown"}, function(dir) { + if (dir<0) { + n--; + draw(); + } else if (dir>0) { + n++; + draw(); + } else { + n = 0; + draw(); } }); -g.clear(); -// call your app function here +// First draw... +draw(); + +// Load widgets +Bangle.loadWidgets(); +Bangle.drawWidgets();