mirror of https://github.com/espruino/BangleApps
swscroll: pull in changes from showScroller_Q3
parent
57f01d2951
commit
d912afbb97
|
@ -1,4 +1,5 @@
|
|||
0.01: Inital release.
|
||||
0.02: Rebasing on latest changes to showScroller_Q3 (https://github.com/espruino/Espruino/commit/2d3c34ef7c2b9fe2118e816aacd2e096adb99596).
|
||||
0.03: Rebasing on latest changes to showScroller_Q3 (https://github.com/espruino/Espruino/commit/b6f8105b6348bb6f7cd03ac11efc1f3585c6ad79). Ensure that changing a menu item when half-scrolled off screen doesn't overwrite widgets.
|
||||
0.04: Rebasing on latest changes to showScroller_Q3 (https://github.com/espruino/Espruino/commit/a0e2d9231df709849f81abf572a742b0fceab85b). Fixes missing `isActive` function that caused an error.
|
||||
|
||||
|
|
|
@ -10,12 +10,25 @@ E.showScroller = (function(options) {
|
|||
}
|
||||
|
||||
returns {
|
||||
draw = draw all
|
||||
drawItem(idx) = draw specific item
|
||||
scroll: int // current scroll amount
|
||||
draw: function() // draw all
|
||||
drawItem : function(idx) // draw specific item
|
||||
isActive : function() // is this scroller still active?
|
||||
}
|
||||
|
||||
*/
|
||||
if (!options) return Bangle.setUI(); // remove existing handlers
|
||||
|
||||
var touchHandler = (_,e)=>{
|
||||
if (e.y<R.y-4) return;
|
||||
var i = YtoIdx(e.y);
|
||||
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});
|
||||
}
|
||||
};
|
||||
|
||||
Bangle.setUI({
|
||||
mode : "custom",
|
||||
back : options.back,
|
||||
|
@ -57,17 +70,9 @@ Bangle.setUI({
|
|||
}
|
||||
}
|
||||
g.setClipRect(0,0,g.getWidth()-1,g.getHeight()-1);
|
||||
}, touch : (_,e)=>{
|
||||
if (e.y<R.y-4) return;
|
||||
var i = YtoIdx(e.y);
|
||||
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});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}, touch : touchHandler
|
||||
});
|
||||
|
||||
var menuShowing = false;
|
||||
var R = Bangle.appRect;
|
||||
var Y = R.y;
|
||||
|
@ -82,8 +87,8 @@ function idxToY(i) {
|
|||
function YtoIdx(y) {
|
||||
return Math.floor((y + rScroll - R.y)/options.h);
|
||||
}
|
||||
|
||||
var s = {
|
||||
|
||||
var s = {
|
||||
scroll : E.clip(0|options.scroll,menuScrollMin,menuScrollMax),
|
||||
draw : () => {
|
||||
g.reset().clearRect(R.x,R.y,R.x2,R.y2);
|
||||
|
@ -98,7 +103,8 @@ var s = {
|
|||
g.reset().setClipRect(R.x,Math.max(y,R.y),R.x2,Math.min(y+options.h,R.y2));
|
||||
options.draw(i, {x:R.x,y:y,w:R.w,h:options.h});
|
||||
g.setClipRect(0,0,g.getWidth()-1,g.getHeight()-1);
|
||||
}};
|
||||
}, isActive : () => Bangle.touchHandler == touchHandler
|
||||
};
|
||||
var rScroll = s.scroll&~1; // rendered menu scroll (we only shift by 2 because of dither)
|
||||
s.draw(); // draw the full scroller
|
||||
g.flip(); // force an update now to make this snappier
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "swscroll",
|
||||
"name": "Swipe menus",
|
||||
"version": "0.03",
|
||||
"version": "0.04",
|
||||
"description": "Replace built in E.showScroller to act on swipe instead of drag. Navigate menus in discrete steps instead of a continuous motion.",
|
||||
"readme": "README.md",
|
||||
"icon": "app.png",
|
||||
|
|
Loading…
Reference in New Issue