diff --git a/apps/swscroll/ChangeLog b/apps/swscroll/ChangeLog index 1adab01bb..9283a85da 100644 --- a/apps/swscroll/ChangeLog +++ b/apps/swscroll/ChangeLog @@ -2,4 +2,4 @@ 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. - +0.05: Fix for the rebase in ver 0.04. Check boxes didn't behave but now they do. diff --git a/apps/swscroll/boot.js b/apps/swscroll/boot.js index 3c4b55817..1c5a84140 100644 --- a/apps/swscroll/boot.js +++ b/apps/swscroll/boot.js @@ -1,4 +1,4 @@ -E.showScroller = (function(options) { +E.showScroller = (function(options) { /* options = { h = height c = # of items @@ -19,20 +19,20 @@ E.showScroller = (function(options) { */ if (!options) return Bangle.setUI(); // remove existing handlers -var touchHandler = (_,e)=>{ - if (e.y=0) && i { + g.reset().clearRect(R).setClipRect(R.x,R.y,R.x2,R.y2); + var a = YtoIdx(R.y); + var b = Math.min(YtoIdx(R.y2),options.c-1); + for (var i=a;i<=b;i++) + options.draw(i, {x:R.x,y:idxToY(i),w:R.w,h:options.h}); + g.setClipRect(0,0,g.getWidth()-1,g.getHeight()-1); }; Bangle.setUI({ mode : "custom", back : options.back, remove : options.remove, + redraw : draw, swipe : (_,UD)=>{ pixels = 120; var dy = UD*pixels; @@ -45,13 +45,13 @@ Bangle.setUI({ rScroll = s.scroll &~1; dy = oldScroll-rScroll; if (!dy || options.c<=3) return; //options.c<=3 should maybe be dynamic, so 3 would be replaced by a variable dependent on R=Bangle.appRect. It's here so we don't try to scroll if all entries fit in the app rectangle. - g.reset().setClipRect(R.x,R.y,R.x2,R.y2); - g.scroll(0,dy); + g.reset().setClipRect(R.x,R.y,R.x2,R.y2).scroll(0,dy); var d = UD*pixels; if (d < 0) { - g.setClipRect(R.x,R.y2-(1-d),R.x2,R.y2); - let i = YtoIdx(R.y2-(1-d)); - let y = idxToY(i); + let y = Math.max(R.y2-(1-d), R.y); + g.setClipRect(R.x,y,R.x2,R.y2); + let i = YtoIdx(y); + y = idxToY(i); //print(i, options.c, options.c-i); //debugging info while (y < R.y2 - (options.h*((options.c-i)<=0)) ) { //- (options.h*((options.c-i)<=0)) makes sure we don't go beyond the menu entries in the menu object "options". This has to do with "dy = s.scroll - menuScrollMax-8" above. options.draw(i, {x:R.x,y:y,w:R.w,h:options.h}); @@ -59,10 +59,10 @@ Bangle.setUI({ y += options.h; } } else { // d>0 - g.setClipRect(R.x,R.y,R.x2,R.y+d); - let i = YtoIdx(R.y+d); - let y = idxToY(i); - //print(i, options.c, options.c-i); //debugging info + let y = Math.min(R.y+d, R.y2); + g.setClipRect(R.x,R.y,R.x2,y); + let i = YtoIdx(y); + y = idxToY(i); while (y > R.y-options.h) { options.draw(i, {x:R.x,y:y,w:R.w,h:options.h}); y -= options.h; @@ -70,7 +70,15 @@ Bangle.setUI({ } } g.setClipRect(0,0,g.getWidth()-1,g.getHeight()-1); - }, touch : touchHandler + }, touch : (_,e)=>{ + if (e.y=0) && i { - g.reset().clearRect(R.x,R.y,R.x2,R.y2); - g.setClipRect(R.x,R.y,R.x2,R.y2); - var a = YtoIdx(R.y); - var b = Math.min(YtoIdx(R.y2),options.c-1); - for (var i=a;i<=b;i++) - options.draw(i, {x:R.x,y:idxToY(i),w:R.w,h:options.h}); - g.setClipRect(0,0,g.getWidth()-1,g.getHeight()-1); -}, drawItem : i => { - var y = idxToY(i); - 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 - }; + draw : draw, drawItem : i => { + var y = idxToY(i); + 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.uiRedraw == draw +}; 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 diff --git a/apps/swscroll/metadata.json b/apps/swscroll/metadata.json index 3258b9b21..3c0717d14 100644 --- a/apps/swscroll/metadata.json +++ b/apps/swscroll/metadata.json @@ -1,7 +1,7 @@ { "id": "swscroll", "name": "Swipe menus", - "version": "0.04", + "version": "0.05", "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",