mirror of
https://github.com/espruino/Espruino.git
synced 2025-12-08 19:06:15 +00:00
2 lines
839 B
JavaScript
2 lines
839 B
JavaScript
exports.list=function(b,c){var a=c[""];a instanceof Object||(a={});void 0===a.selected&&(a.selected=0);a.fontHeight||(a.fontHeight=6);var e=0|a.x,h=a.x2||b.getWidth()-1,d=0|a.y,m=a.y2||b.getHeight()-1;a.title&&(d+=a.fontHeight+2);var f=Object.keys(c).slice(1),l={draw:function(){b.clear();b.setColor(-1);a.title&&(b.drawString(a.title,e+(h-e-b.stringWidth(a.title))/2,d-a.fontHeight-2),b.drawLine(e,d-2,h,d-2));for(var k=0|Math.min((m-d)/a.fontHeight,f.length),c=E.clip(a.selected-(k>>1),0,
|
|
f.length-k),g=d;k--;)c==a.selected&&(b.fillRect(e,g,h,g+a.fontHeight-1),b.setColor(0)),b.drawString(f[c++],e,g),b.setColor(-1),g+=a.fontHeight;a.preflip&&a.preflip();b.flip&&b.flip()},select:function(){var b=c[f[a.selected]];"function"==typeof b&&b()},move:function(b){a.selected=0|Math.clip(a.selected+b,0,f.length-1);l.draw()}};l.draw();return l} |