Skip to content

Commit

Permalink
Merge pull request espruino#2291 from halemmerich/showscroller
Browse files Browse the repository at this point in the history
E.showScroller_Q3 - Give coordinates in item to select callback
  • Loading branch information
gfwilliams authored Nov 16, 2022
2 parents f4c9c4f + a6c5360 commit ed0b727
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
3 changes: 2 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@
Bangle.js2: Use 8x3bpp block fill with masking (now at least 6x faster than 2v15)
Fix JIT when overwriting a pre-existing function, JIT now allows `var/let/const`, fix lock leak in function call, fix FOR postinc issue
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.js2: 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*
Bangle.js: Add Bangle.load() and Bangle.showClock() methods
Graphics: Ensure g.reset() after a custom font was set de-allocates the custom font (fix #2290)
Bangle.js: setUI now calls g.reset(), and also protects against recursion in uiRemove
Bangle.js2: Touched item coordinates in E.showScroller's select callback

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
7 changes: 4 additions & 3 deletions libs/banglejs/jswrap_bangle.c
Original file line number Diff line number Diff line change
Expand Up @@ -5409,7 +5409,7 @@ The second `options` argument can contain:
"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, remove?: () => 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, touch?: {x: number, y: number}) => void, back?: () => void, remove?: () => void }): { draw: () => void, drawItem: (itemNo: number) => void };",
"showScroller(): void;"
]
}
Expand All @@ -5424,8 +5424,9 @@ Supply an object containing:
c : 10, // number of menu items
// a function to draw a menu item
draw : function(idx, rect) { ... }
// a function to call when the item is selected
select : function(idx) { ... }
// a function to call when the item is selected, touch parameter is only relevant
// for Bangle.js 2 and contains the coordinates touched inside the selected item
select : function(idx, touch) { ... }
// optional function to be called when 'back' is tapped
back : function() { ...}
// Bangle.js: optional function to be called when the scroller should be removed
Expand Down
9 changes: 6 additions & 3 deletions libs/js/banglejs/E_showScroller_Q3.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
scrollMin = minimum scroll amount (can be negative)
draw = function(idx, rect)
remove = function()
select = function(idx)
select = function(idx, touch)
}
returns {
Expand Down Expand Up @@ -91,8 +91,11 @@ Bangle.setUI({
}, touch : (_,e)=>{
if (e.y<R.y-4) return;
var i = YtoIdx(e.y);
if ((menuScrollMin<0 || i>=0) && i<options.c)
options.select(i);
if ((menuScrollMin<0 || i>=0) && i<options.c){
let yAbs = (e.y + rScroll - R.y);
let yInElement = yAbs - i*options.h;
options.select(i, {x:e.x, y:yInElement});
}
}
});
return s;
Expand Down
6 changes: 3 additions & 3 deletions libs/js/banglejs/E_showScroller_Q3.min.js

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

0 comments on commit ed0b727

Please sign in to comment.