mirror of https://github.com/espruino/BangleApps
Minor speed/memory layout tweaks - issue with floating point width/height still outstanding
parent
48bb819be7
commit
912b7e8dbf
|
@ -87,6 +87,13 @@ function Layout(layout, buttons, options) {
|
||||||
|
|
||||||
if (buttons) {
|
if (buttons) {
|
||||||
if (this.physBtns >= buttons.length) {
|
if (this.physBtns >= buttons.length) {
|
||||||
|
// Handler for button watch events
|
||||||
|
function pressHandler(btn,e) {
|
||||||
|
if (e.time-e.lastTime > 0.75 && this.b[btn].cbl)
|
||||||
|
this.b[btn].cbl(e);
|
||||||
|
else
|
||||||
|
if (this.b[btn].cb) this.b[btn].cb(e);
|
||||||
|
}
|
||||||
// enough physical buttons
|
// enough physical buttons
|
||||||
let btnHeight = Math.floor((g.getHeight()-this.yOffset) / this.physBtns);
|
let btnHeight = Math.floor((g.getHeight()-this.yOffset) / this.physBtns);
|
||||||
if (Bangle.btnWatch) Bangle.btnWatch.forEach(clearWatch);
|
if (Bangle.btnWatch) Bangle.btnWatch.forEach(clearWatch);
|
||||||
|
@ -113,6 +120,12 @@ function Layout(layout, buttons, options) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (process.env.HWVERSION==2) {
|
if (process.env.HWVERSION==2) {
|
||||||
|
// Handler for touch events
|
||||||
|
function touchHandler(l,e) {
|
||||||
|
if (l.type=="btn" && l.cb && e.x>=l.x && e.y>=l.y && e.x<=l.x+l.w && e.y<=l.y+l.h)
|
||||||
|
l.cb(e);
|
||||||
|
if (l.c) l.c.forEach(n => touchHandler(n,e));
|
||||||
|
}
|
||||||
Bangle.touchHandler = function(_,e){touchHandler(layout,e)};
|
Bangle.touchHandler = function(_,e){touchHandler(layout,e)};
|
||||||
Bangle.on('touch',Bangle.touchHandler);
|
Bangle.on('touch',Bangle.touchHandler);
|
||||||
}
|
}
|
||||||
|
@ -139,21 +152,6 @@ Layout.prototype.remove = function (l) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handler for button watch events
|
|
||||||
function pressHandler(btn,e) {
|
|
||||||
if (e.time-e.lastTime > 0.75 && this.b[btn].cbl)
|
|
||||||
this.b[btn].cbl(e);
|
|
||||||
else
|
|
||||||
if (this.b[btn].cb) this.b[btn].cb(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handler for touch events
|
|
||||||
function touchHandler(l,e) {
|
|
||||||
if (l.type=="btn" && l.cb && e.x>=l.x && e.y>=l.y && e.x<=l.x+l.w && e.y<=l.y+l.h)
|
|
||||||
l.cb(e);
|
|
||||||
if (l.c) l.c.forEach(n => touchHandler(n,e));
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
||||||
if (bgCol != parentBg || l.type == "txt" || l.type == "btn" || l.type == "img" || l.type == "custom") {
|
if (bgCol != parentBg || l.type == "txt" || l.type == "btn" || l.type == "img" || l.type == "custom") {
|
||||||
|
@ -241,9 +239,9 @@ Layout.prototype.layout = function (l) {
|
||||||
case "h": {
|
case "h": {
|
||||||
var x = l.x + (0|l.pad);
|
var x = l.x + (0|l.pad);
|
||||||
var fillx = l.c && l.c.reduce((a,l)=>a+(0|l.fillx),0);
|
var fillx = l.c && l.c.reduce((a,l)=>a+(0|l.fillx),0);
|
||||||
if (!fillx) { x += (l.w-l._w)/2; }
|
if (!fillx) { x += (l.w-l._w)/2; fillx = 1; }
|
||||||
l.c.forEach(c => {
|
l.c.forEach(c => {
|
||||||
c.w = c._w + ((0|c.fillx)*(l.w-l._w)/(fillx||1));
|
c.w = c._w + ((0|c.fillx)*(l.w-l._w)/fillx);
|
||||||
c.h = c.filly ? l.h - (l.pad<<1) : c._h;
|
c.h = c.filly ? l.h - (l.pad<<1) : c._h;
|
||||||
c.x = x;
|
c.x = x;
|
||||||
c.y = l.y + (0|l.pad) + (1+(0|c.valign))*(l.h-(l.pad<<1)-c.h)/2;
|
c.y = l.y + (0|l.pad) + (1+(0|c.valign))*(l.h-(l.pad<<1)-c.h)/2;
|
||||||
|
@ -253,12 +251,12 @@ Layout.prototype.layout = function (l) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "v": {
|
case "v": {
|
||||||
var y = l.y + (0|l.pad);;
|
var y = l.y + (0|l.pad);
|
||||||
var filly = l.c && l.c.reduce((a,l)=>a+(0|l.filly),0);
|
var filly = l.c && l.c.reduce((a,l)=>a+(0|l.filly),0);
|
||||||
if (!filly) { y += (l.h-l._h)/2 }
|
if (!filly) { y += (l.h-l._h)/2; filly = 1; }
|
||||||
l.c.forEach(c => {
|
l.c.forEach(c => {
|
||||||
c.w = c.fillx ? l.w - (l.pad<<1) : c._w;
|
c.w = c.fillx ? l.w - (l.pad<<1) : c._w;
|
||||||
c.h = c._h + ((0|c.filly)*(l.h-l._h)/(filly||1));
|
c.h = c._h + ((0|c.filly)*(l.h-l._h)/filly);
|
||||||
c.y = y;
|
c.y = y;
|
||||||
c.x = l.x + (0|l.pad) + (1+(0|c.halign))*(l.w-(l.pad<<1)-c.w)/2;
|
c.x = l.x + (0|l.pad) + (1+(0|c.halign))*(l.w-(l.pad<<1)-c.w)/2;
|
||||||
y += c.h;
|
y += c.h;
|
||||||
|
@ -349,8 +347,8 @@ Layout.prototype.update = function() {
|
||||||
} else {
|
} else {
|
||||||
l.w = l._w;
|
l.w = l._w;
|
||||||
l.h = l._h;
|
l.h = l._h;
|
||||||
l.x = (w-l.w)/2;
|
l.x = Math.round((w-l.w)/2);
|
||||||
l.y = y+(h-l.h)/2;
|
l.y = y+Math.round((h-l.h)/2);
|
||||||
}
|
}
|
||||||
// layout children
|
// layout children
|
||||||
this.layout(l);
|
this.layout(l);
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Loading…
Reference in New Issue