Merge pull request #2828 from thyttan/swipeScroller
swscroll: pull in changes from showScroller_Q3master
commit
b9db6170ce
|
|
@ -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.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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,17 +70,9 @@ 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;
|
||||||
var R = Bangle.appRect;
|
var R = Bangle.appRect;
|
||||||
var Y = R.y;
|
var Y = R.y;
|
||||||
|
|
@ -82,8 +87,8 @@ function idxToY(i) {
|
||||||
function YtoIdx(y) {
|
function YtoIdx(y) {
|
||||||
return Math.floor((y + rScroll - R.y)/options.h);
|
return Math.floor((y + rScroll - R.y)/options.h);
|
||||||
}
|
}
|
||||||
|
|
||||||
var s = {
|
var s = {
|
||||||
scroll : E.clip(0|options.scroll,menuScrollMin,menuScrollMax),
|
scroll : E.clip(0|options.scroll,menuScrollMin,menuScrollMax),
|
||||||
draw : () => {
|
draw : () => {
|
||||||
g.reset().clearRect(R.x,R.y,R.x2,R.y2);
|
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));
|
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
|
||||||
|
|
|
||||||
|
|
@ -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",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue