Skip to content

Commit

Permalink
Merge pull request #2286 from halemmerich/remove
Browse files Browse the repository at this point in the history
Implement passing through remove methods for E.show*
  • Loading branch information
gfwilliams committed Nov 11, 2022
2 parents 017a58c + dd6c290 commit 0bb0492
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 40 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Expand Up @@ -31,6 +31,7 @@
JIT compiler now included in MDBT42Q/Pixl.js/Puck.js/Bangle.js 1
Bangle.js 2: Bangle.setUI remove unused 'touch' mode, ensure 'back' button doesn't overlap if button is already used (fix #2287)
Bangle.js: Do not clear widget area if only zero width wigets are using it
Bangle.js: Allow setting remove methods for E.show*

2v15 : Fix issue where `E.toJS("\0"+"0") == '"\00"'` which is just `"\0"`
Fix issue accessing `arguments` after/inside 'let/const' keyword (fix #2224)
Expand Down
18 changes: 13 additions & 5 deletions libs/banglejs/jswrap_bangle.c
Expand Up @@ -5241,6 +5241,8 @@ On Bangle.js there are a few additions over the standard `graphical_menu`:
* The options object can contain:
* `back : function() { }` - add a 'back' button, with the function called when
it is pressed
* `remove : function() { }` - add a handler function to be called when the
menu is removed
* (Bangle.js 2) `scroll : int` - an integer specifying how much the initial
menu should be scrolled by
* The object returned by `E.showMenu` contains:
Expand Down Expand Up @@ -5311,7 +5313,7 @@ E.showMessage("Lots of text will wrap automatically",{
"return" : ["JsVar","A promise that is resolved when 'Ok' is pressed"],
"ifdef" : "BANGLEJS",
"typescript" : [
"showPrompt<T = boolean>(message: string, options?: { title?: string, buttons?: { [key: string]: T } }): Promise<T>;",
"showPrompt<T = boolean>(message: string, options?: { title?: string, buttons?: { [key: string]: T }, remove?: () => void }): Promise<T>;",
"showPrompt(): void;"
]
}
Expand Down Expand Up @@ -5352,6 +5354,7 @@ The second `options` argument can contain:
title: "Hello", // optional Title
buttons : {"Ok":true,"Cancel":false}, // optional list of button text & return value
img: "image_string" // optional image string to draw
remove: function() { } // Bangle.js: optional function to be called when the prompt is removed
}
```
*/
Expand All @@ -5362,12 +5365,12 @@ The second `options` argument can contain:
"name" : "showScroller",
"generate_js" : "libs/js/banglejs/E_showScroller.min.js",
"params" : [
["options","JsVar","An object containing `{ h, c, draw, select }` (see below) "]
["options","JsVar","An object containing `{ h, c, draw, select, back, remove }` (see below) "]
],
"return" : ["JsVar", "A menu object with `draw()` and `drawItem(itemNo)` functions" ],
"ifdef" : "BANGLEJS",
"typescript" : [
"showScroller(options?: { h: number, c: number, draw: (idx: number, rect: { x: number, y: number, w: number, h: number }) => void, select: (idx: number) => void, back?: () => void }): { draw: () => void, drawItem: (itemNo: number) => void };",
"showScroller(options?: { h: number, c: number, draw: (idx: number, rect: { x: number, y: number, w: number, h: number }) => void, select: (idx: number) => void, back?: () => void, remove?: () => void }): { draw: () => void, drawItem: (itemNo: number) => void };",
"showScroller(): void;"
]
}
Expand All @@ -5386,6 +5389,8 @@ Supply an object containing:
select : function(idx) { ... }
// optional function to be called when 'back' is tapped
back : function() { ...}
// Bangle.js: optional function to be called when the scroller should be removed
remove : function() {}
}
```
Expand Down Expand Up @@ -5437,11 +5442,14 @@ To remove the scroller, just call `E.showScroller()`
"generate_js" : "libs/js/banglejs/E_showAlert.min.js",
"params" : [
["message","JsVar","A message to display. Can include newlines"],
["options","JsVar","(optional) a title for the message"]
["options","JsVar","(optional) a title for the message or an object containing options"]
],
"return" : ["JsVar","A promise that is resolved when 'Ok' is pressed"],
"ifdef" : "BANGLEJS",
"typescript" : "showAlert(message?: string, options?: string): Promise<void>;"
"typescript" : [
"showAlert(message?: string, options?: string): Promise<void>;",
"showAlert(message?: string, options?: { title?: string, remove?: () => void }): Promise<void>;"
]
}
Displays a full screen prompt on the screen, with a single 'Ok' button.
Expand Down
11 changes: 8 additions & 3 deletions libs/js/banglejs/E_showAlert.js
@@ -1,3 +1,8 @@
(function(msg,title) {
return E.showPrompt(msg,{title:title,buttons:{Ok:1},img:require("heatshrink").decompress(atob("lEo4UBov+///BIMggFVAAQHBAoYIEBQ1QBIcFBIdABIcBBAVUHYsVDgweEDggeELQ4JKGAcP+AyDGAcO2AyDBJI6DBIkBBLpKDBIgAEBOKBEABSyGMYwJTGIkBWabRJd6dVIw0BBIIyDGAYJBGQYwEDwwcCDwwcCAAQ5FBQwFDA="))});
})
(function(msg,options) {
if ("string" == typeof options)
options = { title : options };
options = options||{};
options.buttons = {Ok:1};
options.img = require("heatshrink").decompress(atob("lEo4UBov+///BIMggFVAAQHBAoYIEBQ1QBIcFBIdABIcBBAVUHYsVDgweEDggeELQ4JKGAcP+AyDGAcO2AyDBJI6DBIkBBLpKDBIgAEBOKBEABSyGMYwJTGIkBWabRJd6dVIw0BBIIyDGAYJBGQYwEDwwcCDwwcCAAQ5FBQwFDA="));
return E.showPrompt(msg,options);
})
2 changes: 1 addition & 1 deletion libs/js/banglejs/E_showAlert.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions libs/js/banglejs/E_showMenu_F18.js
Expand Up @@ -189,9 +189,9 @@
}
};
l.draw();
Bangle.setUI({mode: "updown", back: items["< Back"]?l.back:undefined}, dir => {
Bangle.setUI({mode: "updown", back: items["< Back"]?l.back:undefined, remove: options.remove}, dir => {
if (dir) l.move(dir);
else l.select();
});
return l;
})
})
14 changes: 7 additions & 7 deletions libs/js/banglejs/E_showMenu_F18.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions libs/js/banglejs/E_showMenu_Q3.js
Expand Up @@ -27,6 +27,7 @@
E.showScroller({
h : H, c : (item.max+step-item.min)/step,
back: show, // redraw original menu
remove: options.remove,
scrollMin : -24, scroll : -24, // title is 24px, rendered at -1
draw : (idx, r) => {
if (idx<0) // TITLE
Expand Down Expand Up @@ -63,7 +64,8 @@
draw();
Bangle.setUI({
mode: "updown",
back: show
back: show,
remove: options.remove
}, dir => {
if (dir) {
v -= (dir||1)*(item.step||1);
Expand All @@ -82,11 +84,12 @@
var l = {
draw : ()=>l.scroller.draw(),
scroller : undefined
};
};
var scr = {
h : H, c : keys.length/*title*/,
scrollMin : -24, scroll : options.scroll??-24, // title is 24px, rendered at -1
back : back,
remove : options.remove,
draw : (idx, r) => {
if (idx<0) // TITLE
return g.setColor(g.theme.fg).setFont("12x20").setFontAlign(-1,0).drawString(
Expand Down Expand Up @@ -135,4 +138,4 @@
}
show();
return l;
})
})

0 comments on commit 0bb0492

Please sign in to comment.