swscroll: fix check boxes not behaving
... by more properly rebasing on latest E_showScroller_Q3.js from Espruino.master
parent
7dfabf9d7e
commit
8f5d097120
|
|
@ -2,4 +2,4 @@
|
||||||
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.
|
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.
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
E.showScroller = (function(options) {
|
E.showScroller = (function(options) {
|
||||||
/* options = {
|
/* options = {
|
||||||
h = height
|
h = height
|
||||||
c = # of items
|
c = # of items
|
||||||
|
|
@ -19,20 +19,20 @@ E.showScroller = (function(options) {
|
||||||
*/
|
*/
|
||||||
if (!options) return Bangle.setUI(); // remove existing handlers
|
if (!options) return Bangle.setUI(); // remove existing handlers
|
||||||
|
|
||||||
var touchHandler = (_,e)=>{
|
var draw = () => {
|
||||||
if (e.y<R.y-4) return;
|
g.reset().clearRect(R).setClipRect(R.x,R.y,R.x2,R.y2);
|
||||||
var i = YtoIdx(e.y);
|
var a = YtoIdx(R.y);
|
||||||
if ((menuScrollMin<0 || i>=0) && i<options.c){
|
var b = Math.min(YtoIdx(R.y2),options.c-1);
|
||||||
let yAbs = (e.y + rScroll - R.y);
|
for (var i=a;i<=b;i++)
|
||||||
let yInElement = yAbs - i*options.h;
|
options.draw(i, {x:R.x,y:idxToY(i),w:R.w,h:options.h});
|
||||||
options.select(i, {x:e.x, y:yInElement});
|
g.setClipRect(0,0,g.getWidth()-1,g.getHeight()-1);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Bangle.setUI({
|
Bangle.setUI({
|
||||||
mode : "custom",
|
mode : "custom",
|
||||||
back : options.back,
|
back : options.back,
|
||||||
remove : options.remove,
|
remove : options.remove,
|
||||||
|
redraw : draw,
|
||||||
swipe : (_,UD)=>{
|
swipe : (_,UD)=>{
|
||||||
pixels = 120;
|
pixels = 120;
|
||||||
var dy = UD*pixels;
|
var dy = UD*pixels;
|
||||||
|
|
@ -45,13 +45,13 @@ Bangle.setUI({
|
||||||
rScroll = s.scroll &~1;
|
rScroll = s.scroll &~1;
|
||||||
dy = oldScroll-rScroll;
|
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.
|
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.reset().setClipRect(R.x,R.y,R.x2,R.y2).scroll(0,dy);
|
||||||
g.scroll(0,dy);
|
|
||||||
var d = UD*pixels;
|
var d = UD*pixels;
|
||||||
if (d < 0) {
|
if (d < 0) {
|
||||||
g.setClipRect(R.x,R.y2-(1-d),R.x2,R.y2);
|
let y = Math.max(R.y2-(1-d), R.y);
|
||||||
let i = YtoIdx(R.y2-(1-d));
|
g.setClipRect(R.x,y,R.x2,R.y2);
|
||||||
let y = idxToY(i);
|
let i = YtoIdx(y);
|
||||||
|
y = idxToY(i);
|
||||||
//print(i, options.c, options.c-i); //debugging info
|
//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.
|
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});
|
options.draw(i, {x:R.x,y:y,w:R.w,h:options.h});
|
||||||
|
|
@ -59,10 +59,10 @@ Bangle.setUI({
|
||||||
y += options.h;
|
y += options.h;
|
||||||
}
|
}
|
||||||
} else { // d>0
|
} else { // d>0
|
||||||
g.setClipRect(R.x,R.y,R.x2,R.y+d);
|
let y = Math.min(R.y+d, R.y2);
|
||||||
let i = YtoIdx(R.y+d);
|
g.setClipRect(R.x,R.y,R.x2,y);
|
||||||
let y = idxToY(i);
|
let i = YtoIdx(y);
|
||||||
//print(i, options.c, options.c-i); //debugging info
|
y = idxToY(i);
|
||||||
while (y > R.y-options.h) {
|
while (y > R.y-options.h) {
|
||||||
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});
|
||||||
y -= options.h;
|
y -= options.h;
|
||||||
|
|
@ -70,7 +70,15 @@ Bangle.setUI({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g.setClipRect(0,0,g.getWidth()-1,g.getHeight()-1);
|
g.setClipRect(0,0,g.getWidth()-1,g.getHeight()-1);
|
||||||
}, touch : touchHandler
|
}, touch : (_,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});
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var menuShowing = false;
|
var menuShowing = false;
|
||||||
|
|
@ -87,24 +95,16 @@ 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 : draw, drawItem : i => {
|
||||||
g.reset().clearRect(R.x,R.y,R.x2,R.y2);
|
var y = idxToY(i);
|
||||||
g.setClipRect(R.x,R.y,R.x2,R.y2);
|
g.reset().setClipRect(R.x,Math.max(y,R.y),R.x2,Math.min(y+options.h,R.y2));
|
||||||
var a = YtoIdx(R.y);
|
options.draw(i, {x:R.x,y:y,w:R.w,h:options.h});
|
||||||
var b = Math.min(YtoIdx(R.y2),options.c-1);
|
g.setClipRect(0,0,g.getWidth()-1,g.getHeight()-1);
|
||||||
for (var i=a;i<=b;i++)
|
}, isActive : () => Bangle.uiRedraw == draw
|
||||||
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
|
|
||||||
};
|
|
||||||
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.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.",
|
"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