Skip to content

Commit a45e578

Browse files
author
thyttan
committed
messagegui: at a pretty good state
1 parent ae950a3 commit a45e578

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

apps/messagegui/app.js

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,6 @@ function showMessageScroller2(msg, persist, alreadyProcessed) {
252252
const WU = require("widget_utils");
253253
WU.hide();
254254

255-
//if (alreadyProcessed) print("alreadyPeocessed start and stop idx: ",alreadyProcessed.startIdx, alreadyProcessed.stopIdx);
256-
257255
if (replying) { return; }
258256
if (persist) {
259257
cancelReloadTimeout();
@@ -262,8 +260,6 @@ function showMessageScroller2(msg, persist, alreadyProcessed) {
262260
}
263261

264262
let msgIdx = MESSAGES.findIndex((m) => m.id == msg.id)
265-
//print("msgIdx",msgIdx);
266-
//print(msg);
267263

268264
let updatedProcessed = {};
269265
let startIdx = 0;
@@ -291,7 +287,6 @@ function showMessageScroller2(msg, persist, alreadyProcessed) {
291287
stopIdx = Math.min(msgIdx+1, MESSAGES.length);
292288
Object.assign(updatedProcessed, {startIdx:alreadyProcessed.startIdx, stopIdx:stopIdx})
293289
}
294-
//print(startIdx, stopIdx);
295290

296291
active = "scroller";
297292
var bodyFont = fontBig;
@@ -318,16 +313,15 @@ function showMessageScroller2(msg, persist, alreadyProcessed) {
318313
}
319314
}
320315
var titleCnt = lines.length;
321-
if (titleCnt) lines.push(""); // add blank line after title
322-
lines = lines.concat(g.wrapString(msgLocal.body, g.getWidth()-10), [ "---------" ]);
316+
if (titleCnt) {lines.push("");} // add blank line after title
317+
lines = lines.concat(g.wrapString(msgLocal.body, g.getWidth()-10), ["-".repeat(j+1)]);
323318
messagesWrapped.push(lines);
324319
};
325320
let allLines2 = [];
326321
for (let i=0;i<messagesWrapped.length;i++) {
327322
allLines2 = allLines2.concat(messagesWrapped[i]);
328323
}
329324

330-
//print("titlelines", titleLines)
331325
var initScroll = messagesWrapped[0].length;
332326
if (initiatedFrom === "other function"){
333327
if (msgIdx==0) initScroll = 0;
@@ -338,8 +332,6 @@ function showMessageScroller2(msg, persist, alreadyProcessed) {
338332
titleLines = alreadyProcessed.titleLines.concat(titleLines.map((x) => x + alreadyProcessed.lines.length));
339333
}
340334

341-
//print("titlelines", titleLines)
342-
343335
if (initiatedFrom === "other function"){
344336
// no-op
345337
} else if (initiatedFrom === "scrolling up") {
@@ -362,7 +354,7 @@ function showMessageScroller2(msg, persist, alreadyProcessed) {
362354
}
363355
)
364356

365-
let prevScrollIdx; // Used to stop multiple triggers of next message by the scroller.
357+
let prevScrollIdx; // Used for stopping multiple triggers of next message by the scroller.
366358

367359
E.showScroller({
368360
scroll : initScroll*g.getFontHeight(),
@@ -371,12 +363,11 @@ function showMessageScroller2(msg, persist, alreadyProcessed) {
371363
// a function to draw a menu item
372364
draw : function(scrollIdx, r) {
373365
"ram"
374-
//print(scrollIdx, allLines2.length); // FIXME: Remove this print.
375366
g.setBgColor(titleLines.find((e)=>e==scrollIdx)!==undefined ? g.theme.bg2 : g.theme.bg).
376367
setColor(titleLines.find((e)=>e==scrollIdx)!==undefined ? g.theme.fg2 : g.theme.fg).
377368
clearRect(r);
378369
g.setFont(bodyFont).setFontAlign(0,-1).drawString(allLines2[scrollIdx], r.x+r.w/2, r.y);
379-
if (scrollIdx>=allLines2.length-1 && scrollIdx!=prevScrollIdx && updatedProcessed.stopIdx < MESSAGES.length-1) {
370+
if (scrollIdx>=allLines2.length-1 && scrollIdx!=prevScrollIdx && updatedProcessed.stopIdx < MESSAGES.length) {
380371
setTimeout(() => {
381372
E.showScroller();
382373
showMessageScroller2(MESSAGES[updatedProcessed.stopIdx], true, updatedProcessed);
@@ -388,21 +379,23 @@ function showMessageScroller2(msg, persist, alreadyProcessed) {
388379
showMessageScroller2(MESSAGES[updatedProcessed.startIdx-1], true, updatedProcessed);
389380
}, 40);
390381
}
391-
prevScrollIdx=scrollIdx;
382+
prevScrollIdx = scrollIdx;
392383
}, select : function(scrollIdx, touch) {
393-
let touchedMsg;
394-
for (let i=0; i<titleLines.length; i++) {
395-
if (scrollIdx>=titleLines[i]) {touchedMsg = MESSAGES[i + updatedProcessed.startIdx];}
396-
};
384+
let msgSelectIdx;
385+
for (let i = titleLines.length-1; i>=0 ; i--) {
386+
if (scrollIdx>=titleLines[i]) {
387+
msgSelectIdx = i + updatedProcessed.startIdx;
388+
break;
389+
}
390+
}
397391
if (touch.type == 0) {
398392
WU.show();
399-
showMessage(touchedMsg.id, true)
393+
showMessage(MESSAGES[msgSelectIdx].id, true)
400394
}
401395
if (touch.type == 2) {
402396
WU.show();
403-
showMessageSettings(touchedMsg)
397+
showMessageSettings(MESSAGES[msgSelectIdx])
404398
}
405-
//showMessage(msg.id, true);
406399
},
407400
//back : () => showMessage(messages[idx].id, true)
408401
});

0 commit comments

Comments
 (0)