mirror of
https://github.com/espruino/Espruino.git
synced 2025-12-08 19:06:15 +00:00
5 lines
2.3 KiB
JavaScript
5 lines
2.3 KiB
JavaScript
(function(m){Bangle.btnWatches&&(Bangle.btnWatches.forEach(clearWatch),Bangle.btnWatches=void 0);g.clear(1);g.flip();Bangle.drawWidgets();if(m){var p=g.getWidth()-9;g.getHeight();var e=Object.keys(m),a=m[""];a&&e.splice(e.indexOf(""),1);a instanceof Object||(a={});a.fontHeight=16;a.x=0;a.x2=p-2;a.y=24;a.y2=220;void 0===a.selected&&(a.selected=0);a.fontHeight||(a.fontHeight=6);var q=0|a.x,n=a.x2||g.getWidth()-1,k=0|a.y,u=a.y2||g.getHeight()-1;a.title&&(k+=a.fontHeight+2);var t=require("locale"),
|
|
d={draw:function(){g.reset();g.setColor(-1);g.setFont("6x8",2).setFontAlign(0,-1,0);a.title&&(g.drawString(a.title,(q+n)/2,k-a.fontHeight-2),g.drawLine(q,k-2,n,k-2));for(var c=0|Math.min((u-k)/a.fontHeight,e.length),b=E.clip(a.selected-(c>>1),0,e.length-c),f=k;c--;){var h=e[b],r=m[h];g.setColor(b!=a.selected||d.selectEdit?7:759);g.fillRect(q,f,n,f+a.fontHeight-1);g.setColor(-1);g.setFontAlign(-1,-1);g.drawString(t.translate(h),q,f);if("object"==typeof r){h=n;var l=r.value;r.format&&(l=r.format(l));
|
|
l=t.translate(""+l);d.selectEdit&&b==a.selected&&(h-=25,g.setColor(759),g.fillRect(h-(g.stringWidth(l)+4),f,n,f+a.fontHeight-1),g.setColor(-1),g.drawImage("\f\u0005\u0081\x00 \u0007\x00\u00f9\u00f0\u000e\x00@",h,f+(a.fontHeight-10)/2,{scale:2}));g.setFontAlign(1,-1);g.drawString(l,h-2,f)}g.setColor(-1);f+=a.fontHeight;b++}g.setFontAlign(-1,-1);c=b<e.length;g.drawImage("\b\b\u0001\u00108|\u00fe\u0010\u0010\u0010\u0010",p,40);g.drawImage("\b\b\u0001\u0010\u0010\u0010\u0010\u00fe|8\u0010",p,194);g.drawImage("\b\b\u0001\x00\b\f\u000e\u00ff\u000e\f\b",
|
|
p,116);g.setColor(c?-1:0);g.fillPoly([104,220,136,220,120,228]);g.flip()},select:function(c){c=m[e[a.selected]];if("function"==typeof c)c(d);else if("object"==typeof c){if("number"==typeof c.value)d.selectEdit=d.selectEdit?void 0:c;else if("boolean"==typeof c.value&&(c.value=!c.value),c.onchange)c.onchange(c.value);d.draw()}},move:function(c){if(d.selectEdit){var b=d.selectEdit;b.value-=(c||1)*(b.step||1);void 0!==b.min&&b.value<b.min&&(b.value=b.min);void 0!==b.max&&b.value>b.max&&(b.value=b.max);
|
|
if(b.onchange)b.onchange(b.value)}else a.selected=(c+a.selected)%e.length,0>a.selected&&(a.selected+=e.length);d.draw()}};d.draw();Bangle.btnWatches=[setWatch(function(){d.move(-1)},BTN1,{repeat:1}),setWatch(function(){d.move(1)},BTN3,{repeat:1}),setWatch(function(){d.select()},BTN2,{repeat:1})];return d}}) |