Skip to content

Conversation

RKBoss6
Copy link
Contributor

@RKBoss6 RKBoss6 commented Aug 29, 2025

This resolves #3915, adding a snooze menu if you long press the snooze button. This will only work if you upload this code to the bangle in the IDE, as a boot.js file, or install the latest cutting edge firmware:

E.showPrompt=(function(message,options) {
  if (!options) options={};
  if (!options.buttons)
    options.buttons = {"Yes":true,"No":false};
  var btns = Object.keys(options.buttons);
  if (btns.length>6) throw new Error(">6 buttons");
  var btnPos;
  function draw(highlightedButton) {
    g.reset().setFontAlign(0,0);
    var R = Bangle.appRect, Y = R.y, W = R.w;
    var title = g.findFont(options.title||"", {w:W-2,wrap:1,max:24});
    if (title.text) {
      g.setColor(g.theme.fgH).setBgColor(g.theme.bgH).
        clearRect(0,Y,W-1,Y+4+title.h).
        drawString(title.text,W/2,Y+4+title.h/2);
      Y += title.h+4;
    } else Y+=4;
    var BX = 0|"0123233"[btns.length],
        BY = Math.ceil(btns.length / BX),
        BW = (W-1)/BX, BH = options.buttonHeight || ((BY>1 || options.img)?40:50);
    var H = R.y2-(Y + BY*BH);
    if (options.img) {
      var im = g.imageMetrics(options.img);
      g.drawImage(options.img,(W-im.width)/2, Y + 6);
      H -= im.height;
      Y += im.height;
    }
    var msg = g.findFont(message, {w:W-2,h:H,wrap:1,trim:1,min:16});
    g.setColor(g.theme.fg).setBgColor(g.theme.bg).
      drawString(msg.text,W/2,Y+H/2);
    btnPos = [];
    btns.forEach((btn,idx)=>{
      var ix=idx%BX,iy=0|(idx/BX),x = ix*BW + 2, y = R.y2-(BY-iy)*BH + 1,
          bw = BW-4, bh = BH-2, poly = [x+4,y,
                  x+bw-4,y,
                  x+bw,y+4,
                  x+bw,y+bh-4,
                  x+bw-4,y+bh,
                  x+4,y+bh,
                  x,y+bh-4,
                  x,y+4,
                  x+4,y];
      btnPos.push({x1:x-2, x2:x+BW-2,
                   y1:y, y2:y+BH});
      var btnText = g.findFont(btn, {w:bw-4,h:BH-4,wrap:1});
      g.setColor(idx===highlightedButton ? g.theme.bgH : g.theme.bg2).fillPoly(poly).
        setColor(idx===highlightedButton ? g.theme.fgH : g.theme.fg2).drawPoly(poly).drawString(btnText.text,x+bw/2,y+2+BH/2);
      if (idx&1) y+=BH;
    });
    Bangle.setLCDPower(1); // ensure screen is on
  }
  g.reset().clearRect(Bangle.appRect); // clear screen
  if (!message) {
    Bangle.setUI(); // remove watches
    return Promise.resolve();
  }
  draw();
  return new Promise(resolve=>{
    var ui = {mode:"custom", remove: options.remove, redraw: draw, back:options.back, touch:(_,e)=>{
      btnPos.forEach((b,i)=>{
        if (e.x >= b.x1 && e.x <= b.x2 &&
            e.y >= b.y1 && e.y <= b.y2 && !e.hit) {
          e.hit = true; // ensure we don't call twice if the buttons overlap
          draw(i); // highlighted button
          g.flip(); // write to screen
          E.showPrompt(); // remove
          if (e.type===2 /*long press*/ && options.buttonsLong && btns[i] in options.buttonsLong)
            resolve(options.buttonsLong[btns[i]]);
           else
            resolve(options.buttons[btns[i]]);
        }
      });
    }};
    if (btns.length==1 && !options.back) ui.btn = () => {
      draw(0); // highlighted button
      g.flip(); // write to screen
      E.showPrompt(); // remove
      resolve(options.buttons[btns[0]]);
    };
    Bangle.setUI(ui);
  });
})

That modifies the showPrompt to reflect the changes made in the firmware. From there, upload the latest sched app at https://rkboss6.github.io/BangleApps/?id=sched

@RKBoss6 RKBoss6 marked this pull request as draft August 29, 2025 01:49
@RKBoss6
Copy link
Contributor Author

RKBoss6 commented Aug 29, 2025

We'll merge this once @thyttan's changes to E.showPrompt are merged.

Copy link
Collaborator

@bobrippling bobrippling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! A few little suggestions, I'll give it a test too :)

@RKBoss6 RKBoss6 marked this pull request as ready for review August 29, 2025 17:50
@bobrippling
Copy link
Collaborator

LGTM, tagging @gfwilliams with this being a core app

@bobrippling bobrippling requested a review from gfwilliams August 29, 2025 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature discussion: [Alarm/sched] Improve snoozing
2 participants