From 1ba083b706adabc4f3233cb82fbf1f8fa18add36 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com> Date: Mon, 1 Jul 2024 22:50:21 +0200 Subject: [PATCH 1/4] Bangle_setUI_Q3: set custom handlers on any mode TODO: Not thoroughly tested yet. First discussed here around here: https://github.com/espruino/BangleApps/issues/3435#issuecomment-2160293792 --- libs/js/banglejs/Bangle_setUI_Q3.js | 40 ++++++++++++++--------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/libs/js/banglejs/Bangle_setUI_Q3.js b/libs/js/banglejs/Bangle_setUI_Q3.js index 3a30c43a96..07bdac3fb5 100644 --- a/libs/js/banglejs/Bangle_setUI_Q3.js +++ b/libs/js/banglejs/Bangle_setUI_Q3.js @@ -85,28 +85,28 @@ setWatch(Bangle.showLauncher, BTN1, {repeat:1,edge:"falling"}) ]; } else if (mode=="custom") { - if (options.clock) Bangle.CLOCK=1; - if (options.touch) - Bangle.touchHandler = options.touch; - if (options.drag) { - Bangle.dragHandler = options.drag; - Bangle.on("drag", Bangle.dragHandler); - } - if (options.swipe) { - Bangle.swipeHandler = options.swipe; - Bangle.on("swipe", Bangle.swipeHandler); - } - if (options.btn) { - Bangle.btnWatches = [ - setWatch(function() { options.btn(1); }, BTN1, {repeat:1,edge:"falling"}) - ]; - } else if (options.clock) { - Bangle.btnWatches = [ - setWatch(Bangle.showLauncher, BTN1, {repeat:1,edge:"falling"}) - ]; - } } else throw new Error("Unknown UI mode "+E.toJS(mode)); + if (options.clock) Bangle.CLOCK=1; + if (options.touch) + Bangle.touchHandler = options.touch; + if (options.drag) { + Bangle.dragHandler = options.drag; + Bangle.on("drag", Bangle.dragHandler); + } + if (options.swipe) { + Bangle.swipeHandler = options.swipe; + Bangle.on("swipe", Bangle.swipeHandler); + } + if (options.btn) { + Bangle.btnWatches = [ + setWatch(function() { options.btn(1); }, BTN1, {repeat:1,edge:"falling"}) + ]; + } else if (options.clock) { + Bangle.btnWatches = [ + setWatch(Bangle.showLauncher, BTN1, {repeat:1,edge:"falling"}) + ]; + } if (options.remove) // handler for removing the UI (intervals/etc) Bangle.uiRemove = options.remove; if (options.redraw) // handler for redrawing the UI From 6567b7717f2bc4a9b19d6339131ea60fe60d5293 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com> Date: Tue, 2 Jul 2024 00:01:50 +0200 Subject: [PATCH 2/4] Bangle_setUI_Q3: only add custom btn handler This is maybe a quick fix. There could maybe be a bigger refactor to handle btn watches in the same way as other handlers are added, where they aren't added until we know which on we want to set (By writing/overwriting e.g. `Bangle.touchHandler` and only actually set it with `Bangle.on` at the end of the script). --- libs/js/banglejs/Bangle_setUI_Q3.js | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/js/banglejs/Bangle_setUI_Q3.js b/libs/js/banglejs/Bangle_setUI_Q3.js index 07bdac3fb5..3cb8cd205a 100644 --- a/libs/js/banglejs/Bangle_setUI_Q3.js +++ b/libs/js/banglejs/Bangle_setUI_Q3.js @@ -99,6 +99,7 @@ Bangle.on("swipe", Bangle.swipeHandler); } if (options.btn) { + if (Bangle.btnWatches) Bangle.btnWatches.forEach(clearWatch); Bangle.btnWatches = [ setWatch(function() { options.btn(1); }, BTN1, {repeat:1,edge:"falling"}) ]; From 8a3210c196dcb2bc2e9bed0016c4bf6909317861 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com> Date: Tue, 2 Jul 2024 00:07:39 +0200 Subject: [PATCH 3/4] Bangle_setUI_Q3: Make custom btn edge configurable `btn` can be set like before, so backwards compatible I think. But it can now also be an object on form {fn: ()={}, edge: "rising/falling/both"}. @gfwilliams has suggested another solution using callbacks in https://github.com/espruino/BangleApps/pull/3452#discussion_r1642419463 The solution I opted for here for now follows the same coding style of how the `type`/`mode` parameter of setUI can be either a string or an object. --- libs/js/banglejs/Bangle_setUI_Q3.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/js/banglejs/Bangle_setUI_Q3.js b/libs/js/banglejs/Bangle_setUI_Q3.js index 3cb8cd205a..e85af10e4a 100644 --- a/libs/js/banglejs/Bangle_setUI_Q3.js +++ b/libs/js/banglejs/Bangle_setUI_Q3.js @@ -100,8 +100,13 @@ } if (options.btn) { if (Bangle.btnWatches) Bangle.btnWatches.forEach(clearWatch); + var e = "falling"; + if ("object"==typeof options.btn) { + e = options.btn.edge; + options.btn = options.btn.fn; + } Bangle.btnWatches = [ - setWatch(function() { options.btn(1); }, BTN1, {repeat:1,edge:"falling"}) + setWatch(function() { options.btn(1); }, BTN1, {repeat:1,edge:e}) ]; } else if (options.clock) { Bangle.btnWatches = [ From b978df5475370d1bb6944e5fc2940fb716e951b8 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com> Date: Tue, 2 Jul 2024 00:11:46 +0200 Subject: [PATCH 4/4] Bangle_setUI_Q3: Change default btn edge to rising To make the ui feel snappier. First discussed around here: https://github.com/espruino/BangleApps/issues/3435#issuecomment-2157804935 --- libs/js/banglejs/Bangle_setUI_Q3.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libs/js/banglejs/Bangle_setUI_Q3.js b/libs/js/banglejs/Bangle_setUI_Q3.js index e85af10e4a..f30f22b09c 100644 --- a/libs/js/banglejs/Bangle_setUI_Q3.js +++ b/libs/js/banglejs/Bangle_setUI_Q3.js @@ -52,7 +52,7 @@ Bangle.on('drag',Bangle.dragHandler); Bangle.touchHandler = d => {b();cb();}; Bangle.btnWatches = [ - setWatch(function() { b();cb(); }, BTN1, {repeat:1, edge:"falling"}), + setWatch(function() { b();cb(); }, BTN1, {repeat:1, edge:"rising"}), ]; } else if (mode=="leftright") { var dx = 0; @@ -68,12 +68,12 @@ Bangle.on('drag',Bangle.dragHandler); Bangle.touchHandler = d => {b();cb();}; Bangle.btnWatches = [ - setWatch(function() { b();cb(); }, BTN1, {repeat:1, edge:"falling"}), + setWatch(function() { b();cb(); }, BTN1, {repeat:1, edge:"rising"}), ]; } else if (mode=="clock") { Bangle.CLOCK=1; Bangle.btnWatches = [ - setWatch(Bangle.showLauncher, BTN1, {repeat:1,edge:"falling"}) + setWatch(Bangle.showLauncher, BTN1, {repeat:1,edge:"rising"}) ]; } else if (mode=="clockupdown") { Bangle.CLOCK=1; @@ -82,7 +82,7 @@ b();cb((e.y > 88) ? 1 : -1); }; Bangle.btnWatches = [ - setWatch(Bangle.showLauncher, BTN1, {repeat:1,edge:"falling"}) + setWatch(Bangle.showLauncher, BTN1, {repeat:1,edge:"rising"}) ]; } else if (mode=="custom") { } else @@ -100,7 +100,7 @@ } if (options.btn) { if (Bangle.btnWatches) Bangle.btnWatches.forEach(clearWatch); - var e = "falling"; + var e = "rising"; if ("object"==typeof options.btn) { e = options.btn.edge; options.btn = options.btn.fn; @@ -110,7 +110,7 @@ ]; } else if (options.clock) { Bangle.btnWatches = [ - setWatch(Bangle.showLauncher, BTN1, {repeat:1,edge:"falling"}) + setWatch(Bangle.showLauncher, BTN1, {repeat:1,edge:"rising"}) ]; } if (options.remove) // handler for removing the UI (intervals/etc) @@ -139,7 +139,7 @@ btnWatch = setWatch(function() { btnWatch = undefined; options.back(); - }, BTN1, {edge:"falling"}); + }, BTN1, {edge:"rising"}); WIDGETS = Object.assign({back:{ area:"tl", width:24, draw:e=>g.reset().setColor("#f00").drawImage(atob("GBiBAAAYAAH/gAf/4A//8B//+D///D///H/P/n+H/n8P/n4f/vwAP/wAP34f/n8P/n+H/n/P/j///D///B//+A//8Af/4AH/gAAYAA=="),e.x,e.y),