Skip to content

Commit 54f631d

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 097a056 commit 54f631d

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
jsvObjectIterator is now safe even if not called on something iterable
4040
X.on now always allocates an array - tidies up code (fix #2559)
4141
Bangle.js: E.showMenu no longer sends the internal `l` menu object as argument when running the callback function.
42+
Bangle.js2: Pass the modified touch event on through both E.showScroller and E.showMenu (to enable more complex interaction with menus).
4243

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

libs/banglejs/jswrap_bangle.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5904,6 +5904,10 @@ 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+
* (Bangle.js 2) The mapped functions can consider the touch event that interacted with the entry:
5908+
`"Entry" : function(touch) { ... }`
5909+
* This is also true of `onchange` mapped functions in entry objects:
5910+
`onchange : (value, touch) => { ... }`
59075911
* The object returned by `E.showMenu` contains:
59085912
* (Bangle.js 2) `scroller` - the object returned by `E.showScroller` -
59095913
`scroller.scroll` returns the amount the menu is currently scrolled by
@@ -6046,6 +6050,7 @@ Supply an object containing:
60466050
draw : function(idx, rect) { ... }
60476051
// a function to call when the item is selected, touch parameter is only relevant
60486052
// for Bangle.js 2 and contains the coordinates touched inside the selected item
6053+
// as well as the type of the touch - see `Bangle.touch`.
60496054
select : function(idx, touch) { ... }
60506055
// optional function to be called when 'back' is tapped
60516056
back : function() { ...}

libs/js/banglejs/E_showMenu_Q3.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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();
140+
if ("function" == typeof item) item(touch);
141141
else if ("object" == typeof item) {
142-
// if a bool, just toggle it
143142
if ("number" == typeof item.value) {
144143
showSubMenu(item, keys[idx]);
145144
} else {
145+
// if a bool, just toggle it
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)