Espruino/libs/js/banglejs/E_showScroller_Q3.min.js
Gordon Williams 529fb0779e Bangle.js: setUI now has a 'redraw' argument to allow apps to provide a way to redraw themselves
Also fixes for scroller.isActive (and redraw checks) that break if there is a back icon
2023-06-20 11:00:23 +01:00

3 lines
1.3 KiB
JavaScript

(function(d){function m(b){return b*d.h+a.y-f}function k(b){return Math.floor((b+f-a.y)/d.h)}if(!d)return Bangle.setUI();var n=()=>{g.reset().clearRect(a).setClipRect(a.x,a.y,a.x2,a.y2);for(var b=k(a.y),c=Math.min(k(a.y2),d.c-1);b<=c;b++)d.draw(b,{x:a.x,y:m(b),w:a.w,h:d.h});g.setClipRect(0,0,g.getWidth()-1,g.getHeight()-1)};Bangle.setUI({mode:"custom",back:d.back,remove:d.remove,redraw:n,drag:b=>{var c=b.dy;e.scroll-c>l&&(c=e.scroll-l);e.scroll-c<h&&(c=e.scroll-h);e.scroll-=
c;c=f;f=e.scroll&-2;if(c-=f){g.reset().setClipRect(a.x,a.y,a.x2,a.y2).scroll(0,c);b=b.dy;if(0>b)for(b=Math.max(a.y2-(1-b),a.y),g.setClipRect(a.x,b,a.x2,a.y2),c=k(b),b=m(c);b<a.y2;)d.draw(c,{x:a.x,y:b,w:a.w,h:d.h}),c++,b+=d.h;else for(b=Math.min(a.y+b,a.y2),g.setClipRect(a.x,a.y,a.x2,b),c=k(b),b=m(c);b>a.y-d.h;)d.draw(c,{x:a.x,y:b,w:a.w,h:d.h}),b-=d.h,c--;g.setClipRect(0,0,g.getWidth()-1,g.getHeight()-1)}},touch:(b,c)=>{c.y<a.y-4||(b=k(c.y),(0>h||0<=b)&&b<d.c&&d.select(b,{x:c.x,y:c.y+f-a.y-b*d.h}))}});
var a=Bangle.appRect,h=0|d.scrollMin,l=d.h*d.c-a.h;l<h&&(l=h);var e={scroll:E.clip(0|d.scroll,h,l),draw:n,drawItem:b=>{var c=m(b);g.reset().setClipRect(a.x,Math.max(c,a.y),a.x2,Math.min(c+d.h,a.y2));d.draw(b,{x:a.x,y:c,w:a.w,h:d.h});g.setClipRect(0,0,g.getWidth()-1,g.getHeight()-1)},isActive:()=>Bangle.uiRedraw==n},f=e.scroll&-2;e.draw();g.flip();return e})