Skip to content

Commit 269b3e3

Browse files
committed
Bangle_setUI_Q3: tweaks (read below)
- Add custom handlers on top of the standard modes as well. Previously this was only possible for mode == "custom". - The goal here is to make it possible to move all input handling inside `setUI` where today some apps add on extra handlers outside of `setUI` calls. - Change the default behaviour of the hardware button to act immediately on press down. Previously it has been acting on button release. - This makes the interaction slightly snappier. - In addition to the existing `btn` key a new `btnRelease` key can now be specified. `btnRelease` will let you listen to the rising edge of the hardware button.
1 parent ae11e0e commit 269b3e3

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

libs/js/banglejs/Bangle_setUI_Q3.js

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
try{Bangle.buzz(30);}catch(e){}
4040
}
4141
if (mode=="updown") {
42+
if (options.drag) throw new Error("Custom drag handler not supported in mode updown!")
4243
var dy = 0;
4344
Bangle.dragHandler = e=>{
4445
dy += e.dy;
@@ -52,9 +53,10 @@
5253
Bangle.on('drag',Bangle.dragHandler);
5354
Bangle.touchHandler = d => {b();cb();};
5455
Bangle.btnWatches = [
55-
setWatch(function() { b();cb(); }, BTN1, {repeat:1, edge:"falling"}),
56+
setWatch(function() { b();cb(); }, BTN1, {repeat:1, edge:"rising"}),
5657
];
5758
} else if (mode=="leftright") {
59+
if (options.drag) throw new Error("Custom drag handler not supported in mode leftright!")
5860
var dx = 0;
5961
Bangle.dragHandler = e=>{
6062
dx += e.dx;
@@ -68,12 +70,12 @@
6870
Bangle.on('drag',Bangle.dragHandler);
6971
Bangle.touchHandler = d => {b();cb();};
7072
Bangle.btnWatches = [
71-
setWatch(function() { b();cb(); }, BTN1, {repeat:1, edge:"falling"}),
73+
setWatch(function() { b();cb(); }, BTN1, {repeat:1, edge:"rising"}),
7274
];
7375
} else if (mode=="clock") {
7476
Bangle.CLOCK=1;
7577
Bangle.btnWatches = [
76-
setWatch(Bangle.showLauncher, BTN1, {repeat:1,edge:"falling"})
78+
setWatch(Bangle.showLauncher, BTN1, {repeat:1,edge:"rising"})
7779
];
7880
} else if (mode=="clockupdown") {
7981
Bangle.CLOCK=1;
@@ -82,31 +84,30 @@
8284
b();cb((e.y > 88) ? 1 : -1);
8385
};
8486
Bangle.btnWatches = [
85-
setWatch(Bangle.showLauncher, BTN1, {repeat:1,edge:"falling"})
87+
setWatch(Bangle.showLauncher, BTN1, {repeat:1,edge:"rising"})
8688
];
8789
} else if (mode=="custom") {
88-
if (options.clock) Bangle.CLOCK=1;
89-
if (options.touch)
90-
Bangle.touchHandler = options.touch;
91-
if (options.drag) {
92-
Bangle.dragHandler = options.drag;
93-
Bangle.on("drag", Bangle.dragHandler);
94-
}
95-
if (options.swipe) {
96-
Bangle.swipeHandler = options.swipe;
97-
Bangle.on("swipe", Bangle.swipeHandler);
98-
}
99-
if (options.btn) {
100-
Bangle.btnWatches = [
101-
setWatch(function() { options.btn(1); }, BTN1, {repeat:1,edge:"falling"})
102-
];
103-
} else if (options.clock) {
90+
if (options.clock) {
10491
Bangle.btnWatches = [
105-
setWatch(Bangle.showLauncher, BTN1, {repeat:1,edge:"falling"})
92+
setWatch(Bangle.showLauncher, BTN1, {repeat:1,edge:"rising"})
10693
];
10794
}
10895
} else
10996
throw new Error("Unknown UI mode "+E.toJS(mode));
97+
if (options.clock) Bangle.CLOCK=1;
98+
if (options.touch)
99+
Bangle.touchHandler = options.touch;
100+
if (options.drag) {
101+
Bangle.dragHandler = options.drag;
102+
Bangle.on("drag", Bangle.dragHandler);
103+
}
104+
if (options.swipe) {
105+
Bangle.swipeHandler = options.swipe;
106+
Bangle.on("swipe", Bangle.swipeHandler);
107+
}
108+
if ((options.btn || options.btnRelease) && !Bangle.btnWatches) Bangle.btnWatches = [];
109+
if (options.btn) Bangle.btnWatches.push(setWatch(options.btn.bind(options), BTN1, {repeat:1,edge:"rising"}))
110+
if (options.btnRelease) Bangle.btnWatches.push(setWatch(options.btnRelease.bind(options), BTN1, {repeat:1,edge:"falling"}))
110111
if (options.remove) // handler for removing the UI (intervals/etc)
111112
Bangle.uiRemove = options.remove;
112113
if (options.redraw) // handler for redrawing the UI
@@ -133,7 +134,7 @@
133134
btnWatch = setWatch(function() {
134135
btnWatch = undefined;
135136
options.back();
136-
}, BTN1, {edge:"falling"});
137+
}, BTN1, {edge:"rising"});
137138
WIDGETS = Object.assign({back:{
138139
area:"tl", width:24,
139140
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),

libs/js/banglejs/Bangle_setUI_Q3.min.js

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)