Skip to content

Commit

Permalink
widget_utils - Remove the overlay on cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
halemmerich committed Apr 30, 2024
1 parent d2b1487 commit bb28d8c
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions modules/widget_utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// hide any visible widgets
exports.hide = function() {
exports.cleanup();
if (!global.WIDGETS) return;
Expand Down Expand Up @@ -29,8 +28,15 @@ exports.show = function() {

/// Remove any intervals/handlers/etc that we might have added. Does NOT re-show widgets that were hidden
exports.cleanup = function() {
print(exports.cleanUpOverlay);
delete exports.autohide;
delete Bangle.appRect;
if (exports.cleanUpOverlay){
Bangle.setLCDOverlay = exports.origSetLCDOverlay;
Bangle.setLCDOverlay();
delete exports.cleanUpOverlay;
}
delete exports.origSetLCDOverlay;
if (exports.swipeHandler) {
Bangle.removeListener("swipe", exports.swipeHandler);
delete exports.swipeHandler;
Expand Down Expand Up @@ -67,6 +73,12 @@ exports.swipeOn = function(autohide) {
/* TODO: maybe when widgets are offscreen we don't even
store them in an offscreen buffer? */

exports.origSetLCDOverlay = Bangle.setLCDOverlay;
Bangle.setLCDOverlay = function(){
exports.origSetLCDOverlay.apply(Bangle, arguments);
exports.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
Expand All @@ -83,8 +95,10 @@ exports.swipeOn = function(autohide) {
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();
if (offset>-24) {
Bangle.setLCDOverlay(og, 0, offset);
exports.cleanUpOverlay = true;
}
}

for (var w of global.WIDGETS) if (!w._draw) { // already hidden
Expand Down Expand Up @@ -144,4 +158,4 @@ exports.swipeOn = function(autohide) {
};
Bangle.on("swipe", exports.swipeHandler);
Bangle.drawWidgets();
};
};

0 comments on commit bb28d8c

Please sign in to comment.