mirror of https://github.com/espruino/BangleApps
Minor layout speed improvements (~5%)
parent
0300d3c08c
commit
9c4cc9d585
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2022 Bangle.js contributors. See the file LICENSE for copying permission. */
|
/* Copyright (c) 2024 Bangle.js contributors. See the file LICENSE for copying permission. */
|
||||||
|
|
||||||
// See Layout.md for documentation
|
// See Layout.md for documentation
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
function Layout(layout, options) {
|
function Layout(layout, options) {
|
||||||
this._l = this.l = layout;
|
this._l = this.l = layout;
|
||||||
// Do we have >1 physical buttons?
|
// Do we have >1 physical buttons?
|
||||||
|
@ -127,7 +126,7 @@ Layout.prototype.setUI = function() {
|
||||||
Bangle.touchHandler = (_,e)=>touchHandler(this._l,e);
|
Bangle.touchHandler = (_,e)=>touchHandler(this._l,e);
|
||||||
Bangle.on('touch',Bangle.touchHandler);
|
Bangle.on('touch',Bangle.touchHandler);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
function prepareLazyRender(l, rectsToClear, drawList, rects, parentBg) {
|
function prepareLazyRender(l, rectsToClear, drawList, rects, parentBg) {
|
||||||
var bgCol = l.bgCol == null ? parentBg : g.toColor(l.bgCol);
|
var bgCol = l.bgCol == null ? parentBg : g.toColor(l.bgCol);
|
||||||
|
@ -190,7 +189,7 @@ Layout.prototype.render = function (l) {
|
||||||
btnborder = l.btnBorderCol!==undefined?l.btnBorderCol:gfx.theme.fg2,
|
btnborder = l.btnBorderCol!==undefined?l.btnBorderCol:gfx.theme.fg2,
|
||||||
btnface = l.btnFaceCol!==undefined?l.btnFaceCol:gfx.theme.bg2;
|
btnface = l.btnFaceCol!==undefined?l.btnFaceCol:gfx.theme.bg2;
|
||||||
if(l.selected){
|
if(l.selected){
|
||||||
btnface = gfx.theme.bgH, btnborder = gfx.theme.fgH;
|
btnface = gfx.theme.bgH; btnborder = gfx.theme.fgH;
|
||||||
}
|
}
|
||||||
gfx.setColor(btnface).fillPoly(poly).setColor(btnborder).drawPoly(poly);
|
gfx.setColor(btnface).fillPoly(poly).setColor(btnborder).drawPoly(poly);
|
||||||
if (l.col!==undefined) gfx.setColor(l.col);
|
if (l.col!==undefined) gfx.setColor(l.col);
|
||||||
|
@ -208,10 +207,10 @@ Layout.prototype.render = function (l) {
|
||||||
l.y + l.h/2,
|
l.y + l.h/2,
|
||||||
{scale: l.scale||undefined, rotate: Math.PI*0.5*(l.r||0)}
|
{scale: l.scale||undefined, rotate: Math.PI*0.5*(l.r||0)}
|
||||||
);
|
);
|
||||||
}, "custom":function(l){"ram"; l.render(l);
|
}, "custom":function(l){ "ram"; l.render(l);
|
||||||
}, "h":function(l) { "ram"; l.c.forEach(render);
|
}, "h":function(l) { "ram"; l.c.forEach(render);
|
||||||
}, "v":function(l) { "ram"; l.c.forEach(render); }
|
}, "v":function(l) { "ram"; l.c.forEach(render);
|
||||||
};
|
}};
|
||||||
|
|
||||||
if (this.lazy) {
|
if (this.lazy) {
|
||||||
// we have to use 'var' here not 'let', otherwise the minifier
|
// we have to use 'var' here not 'let', otherwise the minifier
|
||||||
|
@ -232,22 +231,22 @@ Layout.prototype.render = function (l) {
|
||||||
|
|
||||||
Layout.prototype.forgetLazyState = function () {
|
Layout.prototype.forgetLazyState = function () {
|
||||||
this.rects = {};
|
this.rects = {};
|
||||||
}
|
};
|
||||||
|
|
||||||
Layout.prototype.layout = function (l) {
|
Layout.prototype.layout = function (l) {
|
||||||
// l = current layout element
|
// l = current layout element
|
||||||
var cb = {
|
var cb = {
|
||||||
"h" : function(l) {"ram";
|
"h" : function(l) {"ram";
|
||||||
var acc_w = l.x + (0|l.pad);
|
var acc_w = l.x + (0|l.pad),
|
||||||
var accfillx = 0;
|
accfillx = 0,
|
||||||
var fillx = l.c && l.c.reduce((a,l)=>a+(0|l.fillx),0);
|
fillx = l.c && l.c.reduce((a,l)=>a+(0|l.fillx),0);
|
||||||
if (!fillx) { acc_w += (l.w-l._w)>>1; fillx=1; }
|
if (!fillx) { acc_w += (l.w-l._w)>>1; fillx=1; }
|
||||||
var x = acc_w;
|
var x = acc_w;
|
||||||
l.c.forEach(c => {
|
l.c.forEach(c => {
|
||||||
c.x = 0|x;
|
c.x = 0|x;
|
||||||
acc_w += c._w;
|
acc_w += c._w;
|
||||||
accfillx += 0|c.fillx;
|
accfillx += 0|c.fillx;
|
||||||
x = acc_w + Math.floor(accfillx*(l.w-l._w)/fillx);
|
x = acc_w + 0|(accfillx*(l.w-l._w)/fillx);
|
||||||
c.w = 0|(x - c.x);
|
c.w = 0|(x - c.x);
|
||||||
c.h = 0|(c.filly ? l.h - (l.pad<<1) : c._h);
|
c.h = 0|(c.filly ? l.h - (l.pad<<1) : c._h);
|
||||||
c.y = 0|(l.y + (0|l.pad) + ((1+(0|c.valign))*(l.h-(l.pad<<1)-c.h)>>1));
|
c.y = 0|(l.y + (0|l.pad) + ((1+(0|c.valign))*(l.h-(l.pad<<1)-c.h)>>1));
|
||||||
|
@ -255,16 +254,16 @@ Layout.prototype.layout = function (l) {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
"v" : function(l) {"ram";
|
"v" : function(l) {"ram";
|
||||||
var acc_h = l.y + (0|l.pad);
|
var acc_h = l.y + (0|l.pad),
|
||||||
var accfilly = 0;
|
accfilly = 0,
|
||||||
var filly = l.c && l.c.reduce((a,l)=>a+(0|l.filly),0);
|
filly = l.c && l.c.reduce((a,l)=>a+(0|l.filly),0);
|
||||||
if (!filly) { acc_h += (l.h-l._h)>>1; filly=1; }
|
if (!filly) { acc_h += (l.h-l._h)>>1; filly=1; }
|
||||||
var y = acc_h;
|
var y = acc_h;
|
||||||
l.c.forEach(c => {
|
l.c.forEach(c => {
|
||||||
c.y = 0|y;
|
c.y = 0|y;
|
||||||
acc_h += c._h;
|
acc_h += c._h;
|
||||||
accfilly += 0|c.filly;
|
accfilly += 0|c.filly;
|
||||||
y = acc_h + Math.floor(accfilly*(l.h-l._h)/filly);
|
y = acc_h + 0|(accfilly*(l.h-l._h)/filly);
|
||||||
c.h = 0|(y - c.y);
|
c.h = 0|(y - c.y);
|
||||||
c.w = 0|(c.fillx ? l.w - (l.pad<<1) : c._w);
|
c.w = 0|(c.fillx ? l.w - (l.pad<<1) : c._w);
|
||||||
c.x = 0|(l.x + (0|l.pad) + ((1+(0|c.halign))*(l.w-(l.pad<<1)-c.w)>>1));
|
c.x = 0|(l.x + (0|l.pad) + ((1+(0|c.halign))*(l.w-(l.pad<<1)-c.w)>>1));
|
||||||
|
@ -274,6 +273,7 @@ Layout.prototype.layout = function (l) {
|
||||||
};
|
};
|
||||||
if (cb[l.type]) cb[l.type](l);
|
if (cb[l.type]) cb[l.type](l);
|
||||||
};
|
};
|
||||||
|
|
||||||
Layout.prototype.debug = function(l,c) {
|
Layout.prototype.debug = function(l,c) {
|
||||||
if (!l) l = this._l;
|
if (!l) l = this._l;
|
||||||
c=c||1;
|
c=c||1;
|
||||||
|
@ -283,31 +283,32 @@ Layout.prototype.debug = function(l,c) {
|
||||||
c++;
|
c++;
|
||||||
if (l.c) l.c.forEach(n => this.debug(n,c));
|
if (l.c) l.c.forEach(n => this.debug(n,c));
|
||||||
};
|
};
|
||||||
|
|
||||||
Layout.prototype.update = function() {
|
Layout.prototype.update = function() {
|
||||||
delete this.updateNeeded;
|
delete this.updateNeeded;
|
||||||
var gfx=g; // define locally, because this is faster
|
var gfx=g, max=Math.max, rnd=Math.round; // define locally, because this is faster
|
||||||
// update sizes
|
// update sizes
|
||||||
function updateMin(l) {"ram";
|
function updateMin(l) {"ram";
|
||||||
cb[l.type](l);
|
cb[l.type](l);
|
||||||
if (l.r&1) { // rotation
|
if (l.r&1) { // rotation
|
||||||
var t = l._w;l._w=l._h;l._h=t;
|
var t = l._w;l._w=l._h;l._h=t;
|
||||||
}
|
}
|
||||||
l._w = Math.max(l._w + (l.pad<<1), 0|l.width);
|
l._w = max(l._w + (l.pad<<1), 0|l.width);
|
||||||
l._h = Math.max(l._h + (l.pad<<1), 0|l.height);
|
l._h = max(l._h + (l.pad<<1), 0|l.height);
|
||||||
}
|
}
|
||||||
var cb = {
|
var cb = {
|
||||||
"txt" : function(l) {"ram";
|
"txt" : function(l) {"ram";
|
||||||
if (l.font.endsWith("%"))
|
if (l.font.endsWith("%"))
|
||||||
l.font = "Vector"+Math.round(gfx.getHeight()*l.font.slice(0,-1)/100);
|
l.font = "Vector"+rnd(gfx.getHeight()*l.font.slice(0,-1)/100);
|
||||||
if (l.wrap) {
|
if (l.wrap) {
|
||||||
l._h = l._w = 0;
|
l._h = l._w = 0;
|
||||||
} else {
|
} else {
|
||||||
var m = g.setFont(l.font).stringMetrics(l.label);
|
var m = gfx.setFont(l.font).stringMetrics(l.label);
|
||||||
l._w = m.width; l._h = m.height;
|
l._w = m.width; l._h = m.height;
|
||||||
}
|
}
|
||||||
}, "btn": function(l) {"ram";
|
}, "btn": function(l) {"ram";
|
||||||
if (l.font && l.font.endsWith("%"))
|
if (l.font && l.font.endsWith("%"))
|
||||||
l.font = "Vector"+Math.round(gfx.getHeight()*l.font.slice(0,-1)/100);
|
l.font = "Vector"+rnd(gfx.getHeight()*l.font.slice(0,-1)/100);
|
||||||
var m = l.src?gfx.imageMetrics("function"==typeof l.src?l.src():l.src):gfx.setFont(l.font||"6x8:2").stringMetrics(l.label);
|
var m = l.src?gfx.imageMetrics("function"==typeof l.src?l.src():l.src):gfx.setFont(l.font||"6x8:2").stringMetrics(l.label);
|
||||||
l._h = 16 + m.height;
|
l._h = 16 + m.height;
|
||||||
l._w = 20 + m.width;
|
l._w = 20 + m.width;
|
||||||
|
@ -325,19 +326,18 @@ Layout.prototype.update = function() {
|
||||||
l._h = 0;
|
l._h = 0;
|
||||||
}, "h": function(l) {"ram";
|
}, "h": function(l) {"ram";
|
||||||
l.c.forEach(updateMin);
|
l.c.forEach(updateMin);
|
||||||
l._h = l.c.reduce((a,b)=>Math.max(a,b._h),0);
|
l._h = l.c.reduce((a,b)=>max(a,b._h),0);
|
||||||
l._w = l.c.reduce((a,b)=>a+b._w,0);
|
l._w = l.c.reduce((a,b)=>a+b._w,0);
|
||||||
if (l.fillx == null && l.c.some(c=>c.fillx)) l.fillx = 1;
|
if (l.fillx == null && l.c.some(c=>c.fillx)) l.fillx = 1;
|
||||||
if (l.filly == null && l.c.some(c=>c.filly)) l.filly = 1;
|
if (l.filly == null && l.c.some(c=>c.filly)) l.filly = 1;
|
||||||
}, "v": function(l) {"ram";
|
}, "v": function(l) {"ram";
|
||||||
l.c.forEach(updateMin);
|
l.c.forEach(updateMin);
|
||||||
l._h = l.c.reduce((a,b)=>a+b._h,0);
|
l._h = l.c.reduce((a,b)=>a+b._h,0);
|
||||||
l._w = l.c.reduce((a,b)=>Math.max(a,b._w),0);
|
l._w = l.c.reduce((a,b)=>max(a,b._w),0);
|
||||||
if (l.fillx == null && l.c.some(c=>c.fillx)) l.fillx = 1;
|
if (l.fillx == null && l.c.some(c=>c.fillx)) l.fillx = 1;
|
||||||
if (l.filly == null && l.c.some(c=>c.filly)) l.filly = 1;
|
if (l.filly == null && l.c.some(c=>c.filly)) l.filly = 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var l = this._l;
|
var l = this._l;
|
||||||
updateMin(l);
|
updateMin(l);
|
||||||
delete cb;
|
delete cb;
|
||||||
|
@ -363,4 +363,4 @@ Layout.prototype.clear = function(l) {
|
||||||
g.clearRect(l.x,l.y,l.x+l.w-1,l.y+l.h-1);
|
g.clearRect(l.x,l.y,l.x+l.w-1,l.y+l.h-1);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports = Layout;
|
exports = Layout;
|
|
@ -1,14 +1,14 @@
|
||||||
function p(d,h){function b(e){"ram";e.id&&(a[e.id]=e);e.type||(e.type="");e.c&&e.c.forEach(b)}this._l=this.l=d;this.options=h||{};this.lazy=this.options.lazy||!1;this.physBtns=1;let f;if(2!=process.env.HWVERSION){this.physBtns=3;f=[];function e(l){"ram";"btn"==l.type&&f.push(l);l.c&&l.c.forEach(e)}e(d);f.length&&(this.physBtns=0,this.buttons=f,this.selectedButton=-1)}if(this.options.btns)if(d=this.options.btns,this.physBtns>=d.length){this.b=d;let e=Math.floor(Bangle.appRect.h/
|
function p(d,k){function c(f){"ram";f.id&&(l[f.id]=f);f.type||(f.type="");f.c&&f.c.forEach(c)}this._l=this.l=d;this.options=k||{};this.lazy=this.options.lazy||!1;this.physBtns=1;let h;if(2!=process.env.HWVERSION){this.physBtns=3;h=[];function f(a){"ram";"btn"==a.type&&h.push(a);a.c&&a.c.forEach(f)}f(d);h.length&&(this.physBtns=0,this.buttons=h,this.selectedButton=-1)}if(this.options.btns)if(d=this.options.btns,this.physBtns>=d.length){this.b=d;let f=Math.floor(Bangle.appRect.h/
|
||||||
this.physBtns);for(2<this.physBtns&&1==d.length&&d.unshift({label:""});this.physBtns>d.length;)d.push({label:""});this._l.width=g.getWidth()-8;this._l={type:"h",filly:1,c:[this._l,{type:"v",pad:1,filly:1,c:d.map(l=>(l.type="txt",l.font="6x8",l.height=e,l.r=1,l))}]}}else this._l.width=g.getWidth()-32,this._l={type:"h",c:[this._l,{type:"v",c:d.map(e=>(e.type="btn",e.filly=1,e.width=32,e.r=1,e))}]},f&&f.push.apply(f,this._l.c[1].c);this.setUI();var a=this;b(this._l);this.updateNeeded=!0}function t(d,
|
this.physBtns);for(2<this.physBtns&&1==d.length&&d.unshift({label:""});this.physBtns>d.length;)d.push({label:""});this._l.width=g.getWidth()-8;this._l={type:"h",filly:1,c:[this._l,{type:"v",pad:1,filly:1,c:d.map(a=>(a.type="txt",a.font="6x8",a.height=f,a.r=1,a))}]}}else this._l.width=g.getWidth()-32,this._l={type:"h",c:[this._l,{type:"v",c:d.map(f=>(f.type="btn",f.filly=1,f.width=32,f.r=1,f))}]},h&&h.push.apply(h,this._l.c[1].c);this.setUI();var l=this;c(this._l);this.updateNeeded=!0}function t(d,
|
||||||
h,b,f,a){var e=null==d.bgCol?a:g.toColor(d.bgCol);if(e!=a||"txt"==d.type||"btn"==d.type||"img"==d.type||"custom"==d.type){var l=d.c;delete d.c;var k="H"+E.CRC32(E.toJS(d));l&&(d.c=l);delete h[k]||((f[k]=[d.x,d.y,d.x+d.w-1,d.y+d.h-1]).bg=null==a?g.theme.bg:a,b&&(b.push(d),b=null))}if(d.c)for(var c of d.c)t(c,h,b,f,e)}p.prototype.setUI=function(){Bangle.setUI();let d;this.buttons&&(Bangle.setUI({mode:"updown",back:this.options.back,remove:this.options.remove},h=>{var b=this.selectedButton,f=this.buttons.length;
|
k,c,h,l){var f=null==d.bgCol?l:g.toColor(d.bgCol);if(f!=l||"txt"==d.type||"btn"==d.type||"img"==d.type||"custom"==d.type){var a=d.c;delete d.c;var e="H"+E.CRC32(E.toJS(d));a&&(d.c=a);delete k[e]||((h[e]=[d.x,d.y,d.x+d.w-1,d.y+d.h-1]).bg=null==l?g.theme.bg:l,c&&(c.push(d),c=null))}if(d.c)for(var b of d.c)t(b,k,c,h,f)}p.prototype.setUI=function(){Bangle.setUI();let d;this.buttons&&(Bangle.setUI({mode:"updown",back:this.options.back,remove:this.options.remove},k=>{var c=this.selectedButton,h=this.buttons.length;
|
||||||
if(void 0===h&&this.buttons[b])return this.buttons[b].cb();this.buttons[b]&&(delete this.buttons[b].selected,this.render(this.buttons[b]));b=(b+f+h)%f;this.buttons[b]&&(this.buttons[b].selected=1,this.render(this.buttons[b]));this.selectedButton=b}),d=!0);!this.options.back&&!this.options.remove||d||Bangle.setUI({mode:"custom",back:this.options.back,remove:this.options.remove});if(this.b){function h(b,f){.75<f.time-f.lastTime&&this.b[b].cbl?this.b[b].cbl(f):this.b[b].cb&&this.b[b].cb(f)}Bangle.btnWatches&&
|
if(void 0===k&&this.buttons[c])return this.buttons[c].cb();this.buttons[c]&&(delete this.buttons[c].selected,this.render(this.buttons[c]));c=(c+h+k)%h;this.buttons[c]&&(this.buttons[c].selected=1,this.render(this.buttons[c]));this.selectedButton=c}),d=!0);!this.options.back&&!this.options.remove||d||Bangle.setUI({mode:"custom",back:this.options.back,remove:this.options.remove});if(this.b){function k(c,h){.75<h.time-h.lastTime&&this.b[c].cbl?this.b[c].cbl(h):this.b[c].cb&&this.b[c].cb(h)}Bangle.btnWatches&&
|
||||||
Bangle.btnWatches.forEach(clearWatch);Bangle.btnWatches=[];this.b[0]&&Bangle.btnWatches.push(setWatch(h.bind(this,0),BTN1,{repeat:!0,edge:-1}));this.b[1]&&Bangle.btnWatches.push(setWatch(h.bind(this,1),BTN2,{repeat:!0,edge:-1}));this.b[2]&&Bangle.btnWatches.push(setWatch(h.bind(this,2),BTN3,{repeat:!0,edge:-1}))}if(2==process.env.HWVERSION){function h(b,f){b.cb&&f.x>=b.x&&f.y>=b.y&&f.x<=b.x+b.w&&f.y<=b.y+b.h&&(2==f.type&&b.cbl?b.cbl(f):b.cb&&b.cb(f));b.c&&b.c.forEach(a=>h(a,f))}Bangle.touchHandler=
|
Bangle.btnWatches.forEach(clearWatch);Bangle.btnWatches=[];this.b[0]&&Bangle.btnWatches.push(setWatch(k.bind(this,0),BTN1,{repeat:!0,edge:-1}));this.b[1]&&Bangle.btnWatches.push(setWatch(k.bind(this,1),BTN2,{repeat:!0,edge:-1}));this.b[2]&&Bangle.btnWatches.push(setWatch(k.bind(this,2),BTN3,{repeat:!0,edge:-1}))}if(2==process.env.HWVERSION){function k(c,h){c.cb&&h.x>=c.x&&h.y>=c.y&&h.x<=c.x+c.w&&h.y<=c.y+c.h&&(2==h.type&&c.cbl?c.cbl(h):c.cb&&c.cb(h));c.c&&c.c.forEach(l=>k(l,h))}Bangle.touchHandler=
|
||||||
(b,f)=>h(this._l,f);Bangle.on("touch",Bangle.touchHandler)}};p.prototype.render=function(d){function h(c){"ram";b.reset();void 0!==c.col&&b.setColor(c.col);void 0!==c.bgCol&&b.setBgColor(c.bgCol).clearRect(c.x,c.y,c.x+c.w-1,c.y+c.h-1);f[c.type](c)}d||(d=this._l);this.updateNeeded&&this.update();var b=g,f={"":function(){},txt:function(c){"ram";if(c.wrap){var m=b.setFont(c.font).setFontAlign(0,-1).wrapString(c.label,c.w),n=c.y+(c.h-b.getFontHeight()*m.length>>1);b.drawString(m.join("\n"),c.x+(c.w>>
|
(c,h)=>k(this._l,h);Bangle.on("touch",Bangle.touchHandler)}};p.prototype.render=function(d){function k(b){"ram";c.reset();void 0!==b.col&&c.setColor(b.col);void 0!==b.bgCol&&c.setBgColor(b.bgCol).clearRect(b.x,b.y,b.x+b.w-1,b.y+b.h-1);h[b.type](b)}d||(d=this._l);this.updateNeeded&&this.update();var c=g,h={"":function(){},txt:function(b){"ram";if(b.wrap){var m=c.setFont(b.font).setFontAlign(0,-1).wrapString(b.label,b.w),n=b.y+(b.h-c.getFontHeight()*m.length>>1);c.drawString(m.join("\n"),b.x+(b.w>>
|
||||||
1),n)}else b.setFont(c.font).setFontAlign(0,0,c.r).drawString(c.label,c.x+(c.w>>1),c.y+(c.h>>1))},btn:function(c){"ram";var m=c.x+(0|c.pad),n=c.y+(0|c.pad),q=c.w-(c.pad<<1),r=c.h-(c.pad<<1);m=[m,n+4,m+4,n,m+q-5,n,m+q-1,n+4,m+q-1,n+r-5,m+q-5,n+r-1,m+4,n+r-1,m,n+r-5,m,n+4];n=void 0!==c.btnBorderCol?c.btnBorderCol:b.theme.fg2;q=void 0!==c.btnFaceCol?c.btnFaceCol:b.theme.bg2;c.selected&&(q=b.theme.bgH,n=b.theme.fgH);b.setColor(q).fillPoly(m).setColor(n).drawPoly(m);void 0!==c.col&&b.setColor(c.col);c.src?
|
1),n)}else c.setFont(b.font).setFontAlign(0,0,b.r).drawString(b.label,b.x+(b.w>>1),b.y+(b.h>>1))},btn:function(b){"ram";var m=b.x+(0|b.pad),n=b.y+(0|b.pad),q=b.w-(b.pad<<1),r=b.h-(b.pad<<1);m=[m,n+4,m+4,n,m+q-5,n,m+q-1,n+4,m+q-1,n+r-5,m+q-5,n+r-1,m+4,n+r-1,m,n+r-5,m,n+4];n=void 0!==b.btnBorderCol?b.btnBorderCol:c.theme.fg2;q=void 0!==b.btnFaceCol?b.btnFaceCol:c.theme.bg2;b.selected&&(q=c.theme.bgH,n=c.theme.fgH);c.setColor(q).fillPoly(m).setColor(n).drawPoly(m);void 0!==b.col&&c.setColor(b.col);b.src?
|
||||||
b.setBgColor(q).drawImage("function"==typeof c.src?c.src():c.src,c.x+c.w/2,c.y+c.h/2,{scale:c.scale||void 0,rotate:.5*Math.PI*(c.r||0)}):b.setFont(c.font||"6x8:2").setFontAlign(0,0,c.r).drawString(c.label,c.x+c.w/2,c.y+c.h/2)},img:function(c){"ram";b.drawImage("function"==typeof c.src?c.src():c.src,c.x+c.w/2,c.y+c.h/2,{scale:c.scale||void 0,rotate:.5*Math.PI*(c.r||0)})},custom:function(c){"ram";c.render(c)},h:function(c){"ram";c.c.forEach(h)},v:function(c){"ram";c.c.forEach(h)}};if(this.lazy){this.rects||
|
c.setBgColor(q).drawImage("function"==typeof b.src?b.src():b.src,b.x+b.w/2,b.y+b.h/2,{scale:b.scale||void 0,rotate:.5*Math.PI*(b.r||0)}):c.setFont(b.font||"6x8:2").setFontAlign(0,0,b.r).drawString(b.label,b.x+b.w/2,b.y+b.h/2)},img:function(b){"ram";c.drawImage("function"==typeof b.src?b.src():b.src,b.x+b.w/2,b.y+b.h/2,{scale:b.scale||void 0,rotate:.5*Math.PI*(b.r||0)})},custom:function(b){"ram";b.render(b)},h:function(b){"ram";b.c.forEach(k)},v:function(b){"ram";b.c.forEach(k)}};if(this.lazy){this.rects||
|
||||||
(this.rects={});var a=this.rects.clone(),e=[];t(d,a,e,this.rects,null);for(var l in a)delete this.rects[l];d=Object.keys(a).map(c=>a[c]).reverse();for(var k of d)b.setBgColor(k.bg).clearRect.apply(g,k);e.forEach(h)}else h(d)};p.prototype.forgetLazyState=function(){this.rects={}};p.prototype.layout=function(d){var h={h:function(b){"ram";var f=b.x+(0|b.pad),a=0,e=b.c&&b.c.reduce((k,c)=>k+(0|c.fillx),0);e||(f+=b.w-b._w>>1,e=1);var l=f;b.c.forEach(k=>{k.x=0|l;f+=k._w;a+=0|k.fillx;l=f+Math.floor(a*(b.w-
|
(this.rects={});var l=this.rects.clone(),f=[];t(d,l,f,this.rects,null);for(var a in l)delete this.rects[a];d=Object.keys(l).map(b=>l[b]).reverse();for(var e of d)c.setBgColor(e.bg).clearRect.apply(g,e);f.forEach(k)}else k(d)};p.prototype.forgetLazyState=function(){this.rects={}};p.prototype.layout=function(d){var k={h:function(c){"ram";var h=c.x+(0|c.pad),l=0,f=c.c&&c.c.reduce((e,b)=>e+(0|b.fillx),0);f||(h+=c.w-c._w>>1,f=1);var a=h;c.c.forEach(e=>{e.x=0|a;h+=e._w;l+=0|e.fillx;a=h+0|l*(c.w-c._w)/f;
|
||||||
b._w)/e);k.w=0|l-k.x;k.h=0|(k.filly?b.h-(b.pad<<1):k._h);k.y=0|b.y+(0|b.pad)+((1+(0|k.valign))*(b.h-(b.pad<<1)-k.h)>>1);if(k.c)h[k.type](k)})},v:function(b){"ram";var f=b.y+(0|b.pad),a=0,e=b.c&&b.c.reduce((k,c)=>k+(0|c.filly),0);e||(f+=b.h-b._h>>1,e=1);var l=f;b.c.forEach(k=>{k.y=0|l;f+=k._h;a+=0|k.filly;l=f+Math.floor(a*(b.h-b._h)/e);k.h=0|l-k.y;k.w=0|(k.fillx?b.w-(b.pad<<1):k._w);k.x=0|b.x+(0|b.pad)+((1+(0|k.halign))*(b.w-(b.pad<<1)-k.w)>>1);if(k.c)h[k.type](k)})}};if(h[d.type])h[d.type](d)};p.prototype.debug=
|
e.w=0|a-e.x;e.h=0|(e.filly?c.h-(c.pad<<1):e._h);e.y=0|c.y+(0|c.pad)+((1+(0|e.valign))*(c.h-(c.pad<<1)-e.h)>>1);if(e.c)k[e.type](e)})},v:function(c){"ram";var h=c.y+(0|c.pad),l=0,f=c.c&&c.c.reduce((e,b)=>e+(0|b.filly),0);f||(h+=c.h-c._h>>1,f=1);var a=h;c.c.forEach(e=>{e.y=0|a;h+=e._h;l+=0|e.filly;a=h+0|l*(c.h-c._h)/f;e.h=0|a-e.y;e.w=0|(e.fillx?c.w-(c.pad<<1):e._w);e.x=0|c.x+(0|c.pad)+((1+(0|e.halign))*(c.w-(c.pad<<1)-e.w)>>1);if(e.c)k[e.type](e)})}};if(k[d.type])k[d.type](d)};p.prototype.debug=function(d,
|
||||||
function(d,h){d||(d=this._l);h=h||1;g.setColor(h&1,h&2,h&4).drawRect(d.x+h-1,d.y+h-1,d.x+d.w-h,d.y+d.h-h);d.pad&&g.drawRect(d.x+d.pad-1,d.y+d.pad-1,d.x+d.w-d.pad,d.y+d.h-d.pad);h++;d.c&&d.c.forEach(b=>this.debug(b,h))};p.prototype.update=function(){function d(a){"ram";b[a.type](a);if(a.r&1){var e=a._w;a._w=a._h;a._h=e}a._w=Math.max(a._w+(a.pad<<1),0|a.width);a._h=Math.max(a._h+(a.pad<<1),0|a.height)}delete this.updateNeeded;var h=g,b={txt:function(a){"ram";a.font.endsWith("%")&&(a.font="Vector"+Math.round(h.getHeight()*
|
k){d||(d=this._l);k=k||1;g.setColor(k&1,k&2,k&4).drawRect(d.x+k-1,d.y+k-1,d.x+d.w-k,d.y+d.h-k);d.pad&&g.drawRect(d.x+d.pad-1,d.y+d.pad-1,d.x+d.w-d.pad,d.y+d.h-d.pad);k++;d.c&&d.c.forEach(c=>this.debug(c,k))};p.prototype.update=function(){function d(a){"ram";l[a.type](a);if(a.r&1){var e=a._w;a._w=a._h;a._h=e}a._w=c(a._w+(a.pad<<1),0|a.width);a._h=c(a._h+(a.pad<<1),0|a.height)}delete this.updateNeeded;var k=g,c=Math.max,h=Math.round,l={txt:function(a){"ram";a.font.endsWith("%")&&(a.font="Vector"+h(k.getHeight()*
|
||||||
a.font.slice(0,-1)/100));if(a.wrap)a._h=a._w=0;else{var e=g.setFont(a.font).stringMetrics(a.label);a._w=e.width;a._h=e.height}},btn:function(a){"ram";a.font&&a.font.endsWith("%")&&(a.font="Vector"+Math.round(h.getHeight()*a.font.slice(0,-1)/100));var e=a.src?h.imageMetrics("function"==typeof a.src?a.src():a.src):h.setFont(a.font||"6x8:2").stringMetrics(a.label);a._h=16+e.height;a._w=20+e.width},img:function(a){"ram";var e=h.imageMetrics("function"==typeof a.src?a.src():a.src),l=a.scale||1;a._w=e.width*
|
a.font.slice(0,-1)/100));if(a.wrap)a._h=a._w=0;else{var e=k.setFont(a.font).stringMetrics(a.label);a._w=e.width;a._h=e.height}},btn:function(a){"ram";a.font&&a.font.endsWith("%")&&(a.font="Vector"+h(k.getHeight()*a.font.slice(0,-1)/100));var e=a.src?k.imageMetrics("function"==typeof a.src?a.src():a.src):k.setFont(a.font||"6x8:2").stringMetrics(a.label);a._h=16+e.height;a._w=20+e.width},img:function(a){"ram";var e=k.imageMetrics("function"==typeof a.src?a.src():a.src),b=a.scale||1;a._w=e.width*b;a._h=
|
||||||
l;a._h=e.height*l},"":function(a){"ram";a._w=0;a._h=0},custom:function(a){"ram";a._w=0;a._h=0},h:function(a){"ram";a.c.forEach(d);a._h=a.c.reduce((e,l)=>Math.max(e,l._h),0);a._w=a.c.reduce((e,l)=>e+l._w,0);null==a.fillx&&a.c.some(e=>e.fillx)&&(a.fillx=1);null==a.filly&&a.c.some(e=>e.filly)&&(a.filly=1)},v:function(a){"ram";a.c.forEach(d);a._h=a.c.reduce((e,l)=>e+l._h,0);a._w=a.c.reduce((e,l)=>Math.max(e,l._w),0);null==a.fillx&&a.c.some(e=>e.fillx)&&(a.fillx=1);null==a.filly&&a.c.some(e=>e.filly)&&
|
e.height*b},"":function(a){"ram";a._w=0;a._h=0},custom:function(a){"ram";a._w=0;a._h=0},h:function(a){"ram";a.c.forEach(d);a._h=a.c.reduce((e,b)=>c(e,b._h),0);a._w=a.c.reduce((e,b)=>e+b._w,0);null==a.fillx&&a.c.some(e=>e.fillx)&&(a.fillx=1);null==a.filly&&a.c.some(e=>e.filly)&&(a.filly=1)},v:function(a){"ram";a.c.forEach(d);a._h=a.c.reduce((e,b)=>e+b._h,0);a._w=a.c.reduce((e,b)=>c(e,b._w),0);null==a.fillx&&a.c.some(e=>e.fillx)&&(a.fillx=1);null==a.filly&&a.c.some(e=>e.filly)&&(a.filly=1)}},f=this._l;
|
||||||
(a.filly=1)}},f=this._l;d(f);delete b;f.fillx||f.filly?(f.w=Bangle.appRect.w,f.h=Bangle.appRect.h,f.x=Bangle.appRect.x,f.y=Bangle.appRect.y):(f.w=f._w,f.h=f._h,f.x=Bangle.appRect.w-f.w>>1,f.y=Bangle.appRect.y+(Bangle.appRect.h-f.h>>1));this.layout(f)};p.prototype.clear=function(d){d||(d=this._l);g.reset();void 0!==d.bgCol&&g.setBgColor(d.bgCol);g.clearRect(d.x,d.y,d.x+d.w-1,d.y+d.h-1)};exports=p
|
d(f);delete l;f.fillx||f.filly?(f.w=Bangle.appRect.w,f.h=Bangle.appRect.h,f.x=Bangle.appRect.x,f.y=Bangle.appRect.y):(f.w=f._w,f.h=f._h,f.x=Bangle.appRect.w-f.w>>1,f.y=Bangle.appRect.y+(Bangle.appRect.h-f.h>>1));this.layout(f)};p.prototype.clear=function(d){d||(d=this._l);g.reset();void 0!==d.bgCol&&g.setBgColor(d.bgCol);g.clearRect(d.x,d.y,d.x+d.w-1,d.y+d.h-1)};exports=p
|
Loading…
Reference in New Issue