widget utils swipeOn now updates appRect to match where the widgets are - see https://github.com/espruino/BangleApps/pull/2306

pull/2308/head
Gordon Williams 2022-11-23 10:46:52 +00:00
parent cf3e574b8f
commit 6868ca321e
1 changed files with 12 additions and 11 deletions

View File

@ -16,7 +16,7 @@ exports.hide = function() {
/// Show any hidden widgets
exports.show = function() {
exports.cleanup();
if (!global.WIDGETS) return;
if (!global.WIDGETS) return;
for (var w of global.WIDGETS) {
if (!w._draw) return; // not hidden
w.draw = w._draw;
@ -49,15 +49,15 @@ exports.cleanup = function() {
}
/** Put widgets offscreen, and allow them to be swiped
back onscreen with a downwards swipe. Use .show to undo.
back onscreen with a downwards swipe. Use .show to undo.
Bangle.js 2 only at the moment. */
exports.swipeOn = function() {
exports.cleanup();
if (!global.WIDGETS) return;
/* TODO: maybe when widgets are offscreen we don't even
store them in an offscreen buffer? */
// force app rect to be fullscreen
Bangle.appRect = { x: 0, y: 0, w: g.getWidth(), h: g.getHeight(), x2: g.getWidth()-1, y2: g.getHeight()-1 };
// setup offscreen graphics for widgets
@ -65,17 +65,19 @@ exports.swipeOn = function() {
og.theme = g.theme;
og._reset = og.reset;
og.reset = function() {
return this._reset().setColor(g.theme.fg).setBgColor(g.theme.bg);
return this._reset().setColor(g.theme.fg).setBgColor(g.theme.bg);
};
og.reset().clearRect(0,0,og.getWidth(),og.getHeight());
let _g = g;
let offset = -24; // where on the screen are we? -24=hidden, 0=full visible
function queueDraw() {
Bangle.appRect.y = offset+24;
Bangle.appRect.h = 1 + Bangle.appRect.y2 - Bangle.appRect.y;
if (offset>-24) Bangle.setLCDOverlay(og, 0, offset);
else Bangle.setLCDOverlay();
}
for (var w of global.WIDGETS) {
if (w._draw) return; // already hidden
w._draw = w.draw;
@ -89,14 +91,14 @@ exports.swipeOn = function() {
if (w.area.startsWith("b"))
w.area = "t"+w.area.substr(1);
}
exports.origDraw = Bangle.drawWidgets;
Bangle.drawWidgets = ()=>{
g=og;
exports.origDraw();
g=_g;
};
function anim(dir, callback) {
if (exports.animInterval) clearInterval(exports.interval);
exports.animInterval = setInterval(function() {
@ -130,7 +132,6 @@ exports.swipeOn = function() {
});
if (ud<0 && offset>-24) anim(-4);
};
};
Bangle.on("swipe", exports.swipeHandler);
};