Skip to content

Commit d9dbaf6

Browse files
author
thyttan
committed
messagegui: add scroller containing all msgs
1 parent d24aefc commit d9dbaf6

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

apps/messagegui/app.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,53 @@ function showMessageScroller(msg) {
274274
});
275275
}
276276

277+
function showMessagesScroller(messages, offsetToMessageNumber) {
278+
print(messages);
279+
cancelReloadTimeout();
280+
active = "scroller";
281+
var bodyFont = fontBig;
282+
g.setFont(bodyFont);
283+
var allLines = [];
284+
var titleLines = [];
285+
var j = messages.length-1;
286+
var initScroll = 0;
287+
messages.forEach(msg => {
288+
if (j == offsetToMessageNumber) initScroll = allLines.length;
289+
var lines = [];
290+
if (msg.title) {
291+
lines = g.wrapString(msg.title, g.getWidth()-10);
292+
for (let i=0; i<lines.length; i++) {
293+
titleLines = titleLines.concat(allLines.length + i)
294+
}
295+
}
296+
var titleCnt = lines.length;
297+
if (titleCnt) lines.push(""); // add blank line after title
298+
lines = lines.concat(g.wrapString(msg.body, g.getWidth()-10), [ "------" ]);
299+
print(lines);
300+
allLines = allLines.concat(lines);
301+
print(allLines);
302+
j--;
303+
});
304+
E.showScroller({
305+
scroll : initScroll*g.getFontHeight(),
306+
h : g.getFontHeight(), // height of each menu item in pixels
307+
c : allLines.length, // number of menu items
308+
// a function to draw a menu item
309+
draw : function(idx, r) {
310+
print(idx); // FIXME: Remove this print.
311+
// FIXME: in 2v13 onwards, clearRect(r) will work fine. There's a bug in 2v12
312+
g.setBgColor(titleLines.find((e)=>e==idx)!==undefined ? g.theme.bg2 : g.theme.bg).
313+
setColor(titleLines.find((e)=>e==idx)!==undefined ? g.theme.fg2 : g.theme.fg).
314+
clearRect(r.x,r.y,r.x+r.w, r.y+r.h);
315+
g.setFont(bodyFont).setFontAlign(0,-1).drawString(allLines[idx], r.x+r.w/2, r.y);
316+
}, select : function(idx) {
317+
if (idx>=allLines.length-2)
318+
showMessage(msg.id, true);
319+
},
320+
back : () => showMessage(msg.id, true)
321+
});
322+
}
323+
277324
function showMessageSettings(msg) {
278325
active = "settings";
279326
var menu = {"":{
@@ -616,3 +663,7 @@ Bangle.on('lock',locked => {
616663
if (!locked)
617664
require("messages").stopBuzz();
618665
});
666+
667+
setTimeout(() => {
668+
showMessagesScroller(MESSAGES);
669+
}, 11);

0 commit comments

Comments
 (0)