From 684c54e884788b3ad897959cc6689e176d82af7e Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Mon, 5 Dec 2022 22:26:35 +0100 Subject: [PATCH] rebase on latest changes --- apps/swscroll/ChangeLog | 1 + apps/swscroll/boot.js | 94 ++++++++++++++++++++----------------- apps/swscroll/metadata.json | 2 +- 3 files changed, 52 insertions(+), 45 deletions(-) diff --git a/apps/swscroll/ChangeLog b/apps/swscroll/ChangeLog index c650baf72..c5fc9dcb4 100644 --- a/apps/swscroll/ChangeLog +++ b/apps/swscroll/ChangeLog @@ -1 +1,2 @@ 0.01: Inital release. +0.02: Rebasing on latest changes to showScroller_Q3 (https://github.com/espruino/Espruino/commit/2d3c34ef7c2b9fe2118e816aacd2e096adb99596). diff --git a/apps/swscroll/boot.js b/apps/swscroll/boot.js index fc5650cad..2b1b00de3 100644 --- a/apps/swscroll/boot.js +++ b/apps/swscroll/boot.js @@ -1,13 +1,14 @@ -E.showScroller = (function(options) { +E.showScroller = (function(options) { /* options = { h = height c = # of items scroll = initial scroll position scrollMin = minimum scroll amount (can be negative) draw = function(idx, rect) - select = function(idx) + remove = function() + select = function(idx, touch) } - + returns { draw = draw all drawItem(idx) = draw specific item @@ -15,46 +16,13 @@ E.showScroller = (function(options) { */ if (!options) return Bangle.setUI(); // remove existing handlers -var menuShowing = false; -var R = Bangle.appRect; -var Y = Bangle.appRect.y; -var n = Math.ceil(R.h/options.h); -var menuScrollMin = 0|options.scrollMin; -var menuScrollMax = options.h*options.c - R.h; -if (menuScrollMax { - 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,y,R.x2,y+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); -}}; -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 Bangle.setUI({ mode : "custom", back : options.back, - swipe : (hor,ver)=>{ + remove : options.remove, + swipe : (_,UD)=>{ pixels = 120; - var dy = ver*pixels; + var dy = UD*pixels; if (s.scroll - dy > menuScrollMax) dy = s.scroll - menuScrollMax-8; // Makes it so the last 'page' has the same position as previous pages. This should be done dynamically (change the static 8 to be a variable) so the offset is correct even when no widget field or title field is present. if (s.scroll - dy < menuScrollMin) @@ -66,7 +34,7 @@ Bangle.setUI({ 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); - var d = ver*pixels; + 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)); @@ -92,9 +60,47 @@ Bangle.setUI({ }, touch : (_,e)=>{ if (e.y=0) && i=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,y,R.x2,y+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); +}}; +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 return s; -}); +}) diff --git a/apps/swscroll/metadata.json b/apps/swscroll/metadata.json index cb345054e..4edbfa2ba 100644 --- a/apps/swscroll/metadata.json +++ b/apps/swscroll/metadata.json @@ -1,7 +1,7 @@ { "id": "swscroll", "name": "Swipe menus", - "version": "0.01", + "version": "0.02", "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",