Using setInterval to update scroller items

Posted on
  • I'm tinkering around with the scroller (on a Bangle 2) and I was wondering if there was a way to update scroller items using, say, setInterval. As a quick example:

    var list = [];
    list[0] = 10;
    list[1] = 20;
    list[2] = 30;
    list[3] = 40;
    list[4] = 50;
    list[5] = 60;
    list[6] = 70;
    
    E.showScroller({
      h : 40, c : list.length,
      draw : (idx, r) => {
        setInterval(function() {
          g.clearRect(r.x,r.y,r.x+r.w-1,r.y+r.h-1)­;
          g.setFont("6x8:2").drawString(list[idx],­r.x+10,r.y+4);
          list[idx]--;
        }, 1000);
      },
      select : (idx) => console.log("You selected ", idx)
      }
    );
    

    If all items fit on the screen, it works fine, but when you start scrolling, the menu starts glitching. Is there a good way to have the items show up properly?

  • This should work with the latest firmware:

    
        var list = [];
        list[0] = 10;
        list[1] = 20;
        list[2] = 30;
        list[3] = 40;
        list[4] = 50;
        list[5] = 60;
        list[6] = 70;
        var s = E.showScroller({
          h : 40, c : list.length,
          draw : (idx, r) => {
            g.clearRect(r.x,r.y,r.x+r.w-1,r.y+r.h-1)­;
            g.setFont("6x8:2").drawString(list[idx],­r.x+10,r.y+4);
          },
          select : (idx) => console.log("You selected ", idx)
          }
        );
      setInterval(function(){
          list = list.map(i => i-1);
          s.draw();
      }, 1000);
    
  • Very interesting, thank you!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Using setInterval to update scroller items

Posted by Avatar for frigis1 @frigis1

Actions