Skip to content

Commit bef271c

Browse files
committed
E_showMenu_/E_showScroller_Q3: forward touch event
The goal was to make it possible for menus to distinguish between short and long touches when the entry maps to a function. With this alarms in the `alarm` app could be made togglable by longpressing corresponding menu entries.
1 parent 5911409 commit bef271c

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
STM32F4: Update stm32f4xx_ll_usb to fix over-buffered USB CDC tx after being woken from deep sleep
2929
Waveform: Add 'npin' option to allow +/- output on two pins
3030
Waveform: Add ability to play directly from Storage
31+
Bangle.js2: Pass the modified touch event on through both
32+
E.showScroller and E.showMenu (to enable more
33+
complex interaction with menus).
3134

3235
2v24 : Bangle.js2: Add 'Bangle.touchRd()', 'Bangle.touchWr()'
3336
Bangle.js2: After Bangle.showTestScreen, put Bangle.js into a hard off state (not soft off)

libs/banglejs/jswrap_bangle.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5904,6 +5904,8 @@ On Bangle.js there are a few additions over the standard `graphical_menu`:
59045904
menu is removed
59055905
* (Bangle.js 2) `scroll : int` - an integer specifying how much the initial
59065906
menu should be scrolled by
5907+
* `onchange : function(value, touch) {}` - on Bangle.js 2 this function can
5908+
consider ~how~ the entry was touched. See `E.showScroller` for more info.
59075909
* The object returned by `E.showMenu` contains:
59085910
* (Bangle.js 2) `scroller` - the object returned by `E.showScroller` -
59095911
`scroller.scroll` returns the amount the menu is currently scrolled by
@@ -6046,6 +6048,7 @@ Supply an object containing:
60466048
draw : function(idx, rect) { ... }
60476049
// a function to call when the item is selected, touch parameter is only relevant
60486050
// for Bangle.js 2 and contains the coordinates touched inside the selected item
6051+
// as well as the type of the touch (short or long, see `Bangle.touch`).
60496052
select : function(idx, touch) { ... }
60506053
// optional function to be called when 'back' is tapped
60516054
back : function() { ...}

libs/js/banglejs/E_showMenu_Q3.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@
3838
g.setColor(g.theme.fg2).setFont("12x20").setFontAlign(-1,0).drawString((item.format) ? item.format(v,1) : v, r.x+12, r.y+H/2);
3939
g.drawImage(/* 20x20 */atob(v==item.value?"FBSBAAH4AH/gHgeDgBww8MY/xmf+bH/jz/88//PP/zz/88f+Nn/mY/xjDww4AcHgeAf+AB+A":"FBSBAAH4AH/gHgeDgBwwAMYABmAAbAADwAA8AAPAADwAA8AANgAGYABjAAw4AcHgeAf+AB+A"), r.x+r.w-32, r.y+H/2-10);
4040
},
41-
select : function(idx) {
41+
select : function(idx, touch) {
4242
if (idx<0) return; // TITLE
4343
Bangle.buzz(20);
4444
item.value = item.min + idx*step;
45-
if (item.onchange) item.onchange(item.value);
45+
if (item.onchange) item.onchange(item.value, touch);
4646
scr.scroll = l.scroller.scroll; // set scroll to prev position
4747
show(); // redraw original menu
4848
}
@@ -133,19 +133,19 @@
133133
l = g.setFont("6x15").wrapString(title,r.w-pad);
134134
g.setFontAlign(-1,0).drawString(l.join("\n"), r.x+12, r.y+H/2);
135135
},
136-
select : function(idx) {
136+
select : function(idx, touch) {
137137
if (idx<0) return back&&back(); // title
138138
var item = menu[keys[idx]];
139139
Bangle.buzz(20);
140-
if ("function" == typeof item) item(l);
140+
if ("function" == typeof item) item(l, touch);
141141
else if ("object" == typeof item) {
142142
// if a bool, just toggle it
143143
if ("number" == typeof item.value) {
144144
showSubMenu(item, keys[idx]);
145145
} else {
146146
if ("boolean"==typeof item.value)
147147
item.value=!item.value;
148-
if (item.onchange) item.onchange(item.value);
148+
if (item.onchange) item.onchange(item.value, touch);
149149
if (l.scroller.isActive()) l.scroller.drawItem(idx);
150150
}
151151
}

libs/js/banglejs/E_showScroller_Q3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Bangle.setUI({
8282
}
8383
if ((menuScrollMin<0 || i>=0) && i<options.c){
8484
//console.log("Press ",e.y,i,yInElement);
85-
options.select(i, {x:e.x, y:yInElement});
85+
options.select(i, {x:e.x, y:yInElement, type:e.type});
8686
}
8787
}
8888
});

0 commit comments

Comments
 (0)