Skip to content

Commit 0f7096b

Browse files
author
thyttan
committed
messagegui: some refactoring
1 parent 3b4facc commit 0f7096b

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

apps/messagegui/app.js

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ function showMessageScroller2(msg, persist, alreadyProcessed) {
265265
//print("msgIdx",msgIdx);
266266
//print(msg);
267267

268-
let cacheObj = {};
268+
let updatedProcessed = {};
269269
let startIdx = 0;
270270
let stopIdx = 0;
271271
let initiatedFrom = alreadyProcessed===undefined ?
@@ -281,15 +281,15 @@ function showMessageScroller2(msg, persist, alreadyProcessed) {
281281
if (initiatedFrom === "other function") {
282282
startIdx = Math.max(msgIdx-1, 0);
283283
stopIdx = Math.min(msgIdx+2, MESSAGES.length);
284-
Object.assign(cacheObj, {startIdx:startIdx, stopIdx:stopIdx})
284+
Object.assign(updatedProcessed, {startIdx:startIdx, stopIdx:stopIdx})
285285
} else if (initiatedFrom === "scrolling up") {
286286
startIdx = Math.max(msgIdx, 0);
287287
stopIdx = alreadyProcessed.startIdx;
288-
Object.assign(cacheObj, {startIdx:startIdx, stopIdx:alreadyProcessed.stopIdx})
288+
Object.assign(updatedProcessed, {startIdx:startIdx, stopIdx:alreadyProcessed.stopIdx})
289289
} else if (initiatedFrom === "scrolling down") {
290290
startIdx = alreadyProcessed.stopIdx;
291291
stopIdx = Math.min(msgIdx+1, MESSAGES.length);
292-
Object.assign(cacheObj, {startIdx:alreadyProcessed.startIdx, stopIdx:stopIdx})
292+
Object.assign(updatedProcessed, {startIdx:alreadyProcessed.startIdx, stopIdx:stopIdx})
293293
}
294294
//print(startIdx, stopIdx);
295295

@@ -354,7 +354,7 @@ function showMessageScroller2(msg, persist, alreadyProcessed) {
354354
}
355355

356356
Object.assign(
357-
cacheObj,
357+
updatedProcessed,
358358
{
359359
lines : allLines2,
360360
titleLines : titleLines,
@@ -376,36 +376,23 @@ function showMessageScroller2(msg, persist, alreadyProcessed) {
376376
setColor(titleLines.find((e)=>e==scrollIdx)!==undefined ? g.theme.fg2 : g.theme.fg).
377377
clearRect(r);
378378
g.setFont(bodyFont).setFontAlign(0,-1).drawString(allLines2[scrollIdx], r.x+r.w/2, r.y);
379-
if (scrollIdx>=allLines2.length-1 && scrollIdx!=prevScrollIdx &&
380-
Math.max(msgIdx,(alreadyProcessed&&alreadyProcessed.stopIdx)||0) <
381-
MESSAGES.length-1) {
379+
if (scrollIdx>=allLines2.length-1 && scrollIdx!=prevScrollIdx && updatedProcessed.stopIdx < MESSAGES.length-1) {
382380
setTimeout(() => {
383381
E.showScroller();
384-
showMessageScroller2(MESSAGES[Math.max(stopIdx,
385-
(alreadyProcessed&&alreadyProcessed.stopIdx)||0)], true, cacheObj);
386-
}, 1);
382+
showMessageScroller2(MESSAGES[updatedProcessed.stopIdx], true, updatedProcessed);
383+
}, 40);
387384
}
388-
if (scrollIdx==0 && scrollIdx!=prevScrollIdx &&
389-
Math.min(
390-
msgIdx,
391-
(alreadyProcessed&&alreadyProcessed.startIdx)===undefined ?
392-
MESSAGES.length : alreadyProcessed.startIdx)
393-
> 0) {
385+
if (scrollIdx==0 && scrollIdx!=prevScrollIdx && updatedProcessed.startIdx>0) {
394386
setTimeout(() => {
395387
E.showScroller();
396-
showMessageScroller2(MESSAGES[Math.min(startIdx-1,
397-
((alreadyProcessed&&alreadyProcessed.startIdx)===undefined
398-
?MESSAGES.length
399-
:alreadyProcessed.startIdx-1)
400-
)]
401-
, true, cacheObj);
402-
}, 1);
388+
showMessageScroller2(MESSAGES[updatedProcessed.startIdx-1], true, updatedProcessed);
389+
}, 40);
403390
}
404391
prevScrollIdx=scrollIdx;
405392
}, select : function(scrollIdx, touch) {
406393
let touchedMsg;
407394
for (let i=0; i<titleLines.length; i++) {
408-
if (scrollIdx>=titleLines[i]) {touchedMsg = MESSAGES[i + cacheObj.startIdx];}
395+
if (scrollIdx>=titleLines[i]) {touchedMsg = MESSAGES[i + updatedProcessed.startIdx];}
409396
};
410397
if (touch.type == 0) {
411398
WU.show();

0 commit comments

Comments
 (0)