mirror of https://github.com/espruino/BangleApps
Merge pull request #3428 from halemmerich/newLCDOverlay
Adapt widget_utils and messagesoverlay to new LCD overlay code for remove callbackspull/3446/head
commit
afea9dff9c
|
@ -14,3 +14,4 @@
|
|||
0.09: Fix scrolling to last line for long text
|
||||
0.10: Track Listeners added with prependListener
|
||||
Handle changed internal callback variable name for watches introduced in 2v21.104
|
||||
0.11: Update for new setLCDOverlay remove handler
|
|
@ -55,7 +55,7 @@ const show = function(){
|
|||
if (ovr.getBPP() == 1) {
|
||||
img.palette = new Uint16Array([g.theme.fg,g.theme.bg]);
|
||||
}
|
||||
Bangle.setLCDOverlay(img, ovrx, ovry);
|
||||
Bangle.setLCDOverlay(img, ovrx, ovry, {id:"messagesoverlay", remove:cleanup});
|
||||
};
|
||||
|
||||
const manageEvent = function(event) {
|
||||
|
@ -618,7 +618,7 @@ const cleanup = function(){
|
|||
}
|
||||
restoreHandlers();
|
||||
|
||||
Bangle.setLCDOverlay();
|
||||
Bangle.setLCDOverlay(undefined, {id: "messagesoverlay"});
|
||||
ovr = undefined;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "messagesoverlay",
|
||||
"name": "Messages Overlay",
|
||||
"version": "0.10",
|
||||
"version": "0.11",
|
||||
"description": "An overlay based implementation of a messages UI (display notifications from iOS and Gadgetbridge/Android)",
|
||||
"icon": "app.png",
|
||||
"type": "bootloader",
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
exports.offset = 0;
|
||||
exports.hide = function() {
|
||||
exports.cleanup();
|
||||
if (!global.WIDGETS) return;
|
||||
|
@ -26,22 +27,12 @@ exports.show = function() {
|
|||
}
|
||||
};
|
||||
|
||||
/// Remove any intervals/handlers/etc that we might have added. Does NOT re-show widgets that were hidden
|
||||
exports.cleanup = function() {
|
||||
/// Remove anything not needed if the overlay was removed
|
||||
exports.cleanupOverlay = function() {
|
||||
exports.offset = -24;
|
||||
Bangle.setLCDOverlay(undefined, {id: "widget_utils"});
|
||||
delete exports.autohide;
|
||||
delete Bangle.appRect;
|
||||
if (exports.origSetLCDOverlay){
|
||||
Bangle.setLCDOverlay = exports.origSetLCDOverlay;
|
||||
}
|
||||
delete exports.origSetLCDOverlay;
|
||||
if (exports.cleanUpOverlay){
|
||||
Bangle.setLCDOverlay();
|
||||
}
|
||||
delete exports.cleanUpOverlay;
|
||||
if (exports.swipeHandler) {
|
||||
Bangle.removeListener("swipe", exports.swipeHandler);
|
||||
delete exports.swipeHandler;
|
||||
}
|
||||
if (exports.animInterval) {
|
||||
clearInterval(exports.animInterval);
|
||||
delete exports.animInterval;
|
||||
|
@ -50,6 +41,16 @@ exports.cleanup = function() {
|
|||
clearTimeout(exports.hideTimeout);
|
||||
delete exports.hideTimeout;
|
||||
}
|
||||
};
|
||||
|
||||
/// Remove any intervals/handlers/etc that we might have added. Does NOT re-show widgets that were hidden
|
||||
exports.cleanup = function() {
|
||||
exports.cleanupOverlay();
|
||||
delete exports.offset;
|
||||
if (exports.swipeHandler) {
|
||||
Bangle.removeListener("swipe", exports.swipeHandler);
|
||||
delete exports.swipeHandler;
|
||||
}
|
||||
if (exports.origDraw) {
|
||||
Bangle.drawWidgets = exports.origDraw;
|
||||
delete exports.origDraw;
|
||||
|
@ -74,14 +75,6 @@ exports.swipeOn = function(autohide) {
|
|||
/* TODO: maybe when widgets are offscreen we don't even
|
||||
store them in an offscreen buffer? */
|
||||
|
||||
if (!exports.origSetLCDOverlay) {
|
||||
exports.origSetLCDOverlay = Bangle.setLCDOverlay;
|
||||
Bangle.setLCDOverlay = function(){
|
||||
require("widget_utils").origSetLCDOverlay.apply(Bangle, arguments);
|
||||
require("widget_utils").cleanUpOverlay = false;
|
||||
};
|
||||
}
|
||||
|
||||
// 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
|
||||
|
@ -93,16 +86,23 @@ exports.swipeOn = function(autohide) {
|
|||
};
|
||||
og.reset().clearRect(0,0,og.getWidth(),23).fillRect(0,24,og.getWidth(),25);
|
||||
let _g = g;
|
||||
let offset = -24; // where on the screen are we? -24=hidden, 0=full visible
|
||||
exports.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);
|
||||
exports.cleanUpOverlay = true;
|
||||
} else {
|
||||
Bangle.setLCDOverlay();
|
||||
const o = exports.offset;
|
||||
if (o>-24) {
|
||||
Bangle.appRect.y = o+24;
|
||||
Bangle.appRect.h = 1 + Bangle.appRect.y2 - Bangle.appRect.y;
|
||||
if (o>-24) {
|
||||
Bangle.setLCDOverlay(og, 0, o, {
|
||||
id:"widget_utils",
|
||||
remove:()=>{
|
||||
require("widget_utils").cleanupOverlay();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Bangle.setLCDOverlay(undefined, {id: "widget_utils"});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,7 @@ exports.swipeOn = function(autohide) {
|
|||
g=og;
|
||||
this._draw(this);
|
||||
g=_g;
|
||||
if (offset>-24) queueDraw();
|
||||
if (exports.offset>-24) queueDraw();
|
||||
};
|
||||
w._area = w.area;
|
||||
if (w.area.startsWith("b"))
|
||||
|
@ -129,14 +129,14 @@ exports.swipeOn = function(autohide) {
|
|||
function anim(dir, callback) {
|
||||
if (exports.animInterval) clearInterval(exports.animInterval);
|
||||
exports.animInterval = setInterval(function() {
|
||||
offset += dir;
|
||||
exports.offset += dir;
|
||||
let stop = false;
|
||||
if (dir>0 && offset>=0) { // fully down
|
||||
if (dir>0 && exports.offset>=0) { // fully down
|
||||
stop = true;
|
||||
offset = 0;
|
||||
} else if (dir<0 && offset<-23) { // fully up
|
||||
exports.offset = 0;
|
||||
} else if (dir<0 && exports.offset<-23) { // fully up
|
||||
stop = true;
|
||||
offset = -24;
|
||||
exports.offset = -24;
|
||||
}
|
||||
if (stop) {
|
||||
clearInterval(exports.animInterval);
|
||||
|
@ -158,8 +158,8 @@ exports.swipeOn = function(autohide) {
|
|||
anim(-4);
|
||||
}, exports.autohide);
|
||||
};
|
||||
if (ud>0 && offset<0) anim(4, cb);
|
||||
if (ud<0 && offset>-24) anim(-4);
|
||||
if (ud>0 && exports.offset<0) anim(4, cb);
|
||||
if (ud<0 && exports.offset>-24) anim(-4);
|
||||
};
|
||||
Bangle.on("swipe", exports.swipeHandler);
|
||||
Bangle.drawWidgets();
|
||||
|
|
Loading…
Reference in New Issue