Don't use getModified in lazy layout rendering

master
Ben Whittaker 2021-09-15 05:58:04 -04:00
parent 95d353a749
commit 6bd606b645
2 changed files with 20 additions and 22 deletions

View File

@ -214,7 +214,7 @@ function render(l) {
if (!l) l = this.l; if (!l) l = this.l;
g.reset(); g.reset();
if (l.col) g.setColor(l.col); if (l.col) g.setColor(l.col);
if (l.bgCol!==undefined) g.setBgColor(l.bgCol).clearRect(l.x,l.y,l.x+l.w,l.y+l.h); if (l.bgCol!==undefined) g.setBgColor(l.bgCol).clearRect(l.x,l.y,l.x+l.w-1,l.y+l.h-1);
switch (l.type) { switch (l.type) {
case "txt": case "txt":
g.setFont(l.font,l.fsz).setFontAlign(0,0,l.r).drawString(l.label, l.x+(l.w>>1), l.y+(l.h>>1), true/*solid bg*/); g.setFont(l.font,l.fsz).setFontAlign(0,0,l.r).drawString(l.label, l.x+(l.w>>1), l.y+(l.h>>1), true/*solid bg*/);
@ -243,12 +243,15 @@ function render(l) {
if (l.c) l.c.forEach(render); if (l.c) l.c.forEach(render);
} }
function prepareLazyRender(l, rectsToClear, drawList) { function prepareLazyRender(l, rectsToClear, drawList, rects) {
if (l.type == "txt" || l.type == "btn" || l.type == "img" || l.type == "custom") { if (l.type == "txt" || l.type == "btn" || l.type == "img" || l.type == "custom") {
let hash = E.CRC32(E.toJS(l)); let hash = E.CRC32(E.toJS(l));
if (!delete rectsToClear[hash]) drawList.push({hash: hash, l: l}); if (!delete rectsToClear[hash]) {
drawList.push(l);
rects[hash] = [l.x,l.y,l.x+l.w-1,l.y+l.h-1];
} }
else if (l.c) l.c.forEach(l => prepareLazyRender(l, rectsToClear, drawList)); }
else if (l.c) l.c.forEach(l => prepareLazyRender(l, rectsToClear, drawList, rects));
} }
Layout.prototype.render = function (l) { Layout.prototype.render = function (l) {
@ -260,14 +263,10 @@ Layout.prototype.render = function (l) {
if (!this.rects) this.rects = {}; if (!this.rects) this.rects = {};
let rectsToClear = Object.assign({}, this.rects); let rectsToClear = Object.assign({}, this.rects);
let drawList = []; let drawList = [];
prepareLazyRender(l, rectsToClear, drawList); prepareLazyRender(l, rectsToClear, drawList, this.rects);
for (let hash in rectsToClear) delete this.rects[hash]; for (let hash in rectsToClear) delete this.rects[hash];
for (let rect of rectsToClear) if (rect) g.clearRect(rect.x1, rect.y1, rect.x2, rect.y2); for (let rect of rectsToClear) g.clearRect.apply(g, rect);
g.getModified(true); drawList.forEach(render);
for (let d of drawList) {
render(d.l);
this.rects[d.hash] = g.getModified(true);
}
} }
else { else {
render(l); render(l);

21
modules/Layout.min.js vendored
View File

@ -214,7 +214,7 @@ function render(l) {
if (!l) l = this.l; if (!l) l = this.l;
g.reset(); g.reset();
if (l.col) g.setColor(l.col); if (l.col) g.setColor(l.col);
if (l.bgCol!==undefined) g.setBgColor(l.bgCol).clearRect(l.x,l.y,l.x+l.w,l.y+l.h); if (l.bgCol!==undefined) g.setBgColor(l.bgCol).clearRect(l.x,l.y,l.x+l.w-1,l.y+l.h-1);
switch (l.type) { switch (l.type) {
case "txt": case "txt":
g.setFont(l.font,l.fsz).setFontAlign(0,0,l.r).drawString(l.label, l.x+(l.w>>1), l.y+(l.h>>1), true/*solid bg*/); g.setFont(l.font,l.fsz).setFontAlign(0,0,l.r).drawString(l.label, l.x+(l.w>>1), l.y+(l.h>>1), true/*solid bg*/);
@ -243,12 +243,15 @@ function render(l) {
if (l.c) l.c.forEach(render); if (l.c) l.c.forEach(render);
} }
function prepareLazyRender(l, rectsToClear, drawList) { function prepareLazyRender(l, rectsToClear, drawList, rects) {
if (l.type == "txt" || l.type == "btn" || l.type == "img" || l.type == "custom") { if (l.type == "txt" || l.type == "btn" || l.type == "img" || l.type == "custom") {
let hash = E.CRC32(E.toJS(l)); let hash = E.CRC32(E.toJS(l));
if (!delete rectsToClear[hash]) drawList.push({hash: hash, l: l}); if (!delete rectsToClear[hash]) {
drawList.push(l);
rects[hash] = [l.x,l.y,l.x+l.w-1,l.y+l.h-1];
} }
else if (l.c) l.c.forEach(l => prepareLazyRender(l, rectsToClear, drawList)); }
else if (l.c) l.c.forEach(l => prepareLazyRender(l, rectsToClear, drawList, rects));
} }
Layout.prototype.render = function (l) { Layout.prototype.render = function (l) {
@ -260,14 +263,10 @@ Layout.prototype.render = function (l) {
if (!this.rects) this.rects = {}; if (!this.rects) this.rects = {};
let rectsToClear = Object.assign({}, this.rects); let rectsToClear = Object.assign({}, this.rects);
let drawList = []; let drawList = [];
prepareLazyRender(l, rectsToClear, drawList); prepareLazyRender(l, rectsToClear, drawList, this.rects);
for (let hash in rectsToClear) delete this.rects[hash]; for (let hash in rectsToClear) delete this.rects[hash];
for (let rect of rectsToClear) if (rect) g.clearRect(rect.x1, rect.y1, rect.x2, rect.y2); for (let rect of rectsToClear) g.clearRect.apply(g, rect);
g.getModified(true); drawList.forEach(render);
for (let d of drawList) {
render(d.l);
this.rects[d.hash] = g.getModified(true);
}
} }
else { else {
render(l); render(l);