• The Bangle.js 2 drawWidgets() code is here: https://github.com/espruino/Espruino/blo­b/master/libs/js/banglejs/Bangle_drawWid­gets_Q3.js

    So your app could override that with something like this:

    Bangle.drawWidgets = function() {
      // Same as default Bangle.drawWidgets
      var w=g.getWidth(), h=g.getHeight();
      var pos = {
    	  tl:{x:0, y:0, r:0, c:0}, // if r==1, we're right->left
    	  tr:{x:w-1, y:0, r:1, c:0},
    	  bl:{x:0, y:h-24, r:0, c:0},
    	  br:{x:w-1, y:h-24, r:1, c:0}
      };
      if (global.WIDGETS) {
        for (var wd of WIDGETS) {
      	  var p = pos[wd.area];
      	  if (!p) continue;
      	  wd.x = p.x - p.r*wd.width;
      	  wd.y = p.y;
      	  p.x += wd.width*(1-2*p.r);
      	  p.c++;
        }
        g.reset();
        // Changes start here:
        if (pos.tl.c || pos.tr.c) {
          g.setClipRect(0,0,w-1,23);
         // TODO: redraw top widget area background
         g.reset();
       }
       if (pos.bl.c || pos.br.c) {
         g.setClipRect(0,h-24,w-1,h-1);
         // TODO: redraw bottom widget area background
         g.reset();
       }
        try {
            for (wd of WIDGETS) {
                // clear individual widget background:
                g.clearRect(wd.x,wd.y, wd.x+wd.width-1,23);
                wd.draw(wd); 
           }
       } catch(e) {print(e);}
      }
    }
    

    You want to override Bangle.drawWidgets() instead of just drawing them yourself, because widgets tend to call Bangle.drawWidgets() to show/hide themself.
    And you need to redraw the background for the same reason: widgets can be shown/hidden, which moves other widgets around. (I guess you could keep track of widget positions to check if you really need to redraw)

  • Perfect, thank you very much for your response (particularly the "TODO" comments in there)!

    This gives me the information I need to

    • draw my own background prior to any widgets and
    • then to draw all widgets on top of that

    Thanks a lot!

    Edit:

    • I followed your suggestion and implemented a modified version of "Bangle.drawWidgets" - it works like a charm!
    • what surprises me, though, is the call of g.setClipRectRect in line 27 - is this part of the original code or did you edit it?

    Edit 2:

    • I found it: you edited the original code! Thus, you may perhaps want to correct that line

    Thanks again for your effort!

About

Avatar for rigrig @rigrig started