Merge pull request #2828 from thyttan/swipeScroller

swscroll: pull in changes from showScroller_Q3
master
Gordon Williams 2023-06-19 09:13:06 +01:00 committed by GitHub
commit b9db6170ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 17 deletions

View File

@ -1,4 +1,5 @@
0.01: Inital release. 0.01: Inital release.
0.02: Rebasing on latest changes to showScroller_Q3 (https://github.com/espruino/Espruino/commit/2d3c34ef7c2b9fe2118e816aacd2e096adb99596). 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.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.

View File

@ -10,12 +10,25 @@ E.showScroller = (function(options) {
} }
returns { returns {
draw = draw all scroll: int // current scroll amount
drawItem(idx) = draw specific item 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 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({ Bangle.setUI({
mode : "custom", mode : "custom",
back : options.back, back : options.back,
@ -57,15 +70,7 @@ Bangle.setUI({
} }
} }
g.setClipRect(0,0,g.getWidth()-1,g.getHeight()-1); g.setClipRect(0,0,g.getWidth()-1,g.getHeight()-1);
}, touch : (_,e)=>{ }, touch : touchHandler
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});
}
}
}); });
var menuShowing = false; var menuShowing = false;
@ -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)); 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}); options.draw(i, {x:R.x,y:y,w:R.w,h:options.h});
g.setClipRect(0,0,g.getWidth()-1,g.getHeight()-1); 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) var rScroll = s.scroll&~1; // rendered menu scroll (we only shift by 2 because of dither)
s.draw(); // draw the full scroller s.draw(); // draw the full scroller
g.flip(); // force an update now to make this snappier g.flip(); // force an update now to make this snappier

View File

@ -1,7 +1,7 @@
{ {
"id": "swscroll", "id": "swscroll",
"name": "Swipe menus", "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.", "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", "readme": "README.md",
"icon": "app.png", "icon": "app.png",