Skip to content

Commit d7d0530

Browse files
author
thyttan
committed
messagegui: hw btn on scroller goes back
1 parent 22a63a8 commit d7d0530

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

apps/messagegui/app.js

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,21 @@ function showMessagesScroller(msg, persist, alreadyProcessed) {
338338
stop : Math.max(idxSpan.stop, alreadyProcessed.idxSpan.stop||0)}
339339
};
340340

341+
function identifyDisplayedMsg(scrollIdx) {
342+
let firstTitleLinePerMsg = [titleLines[0]];
343+
for (let i=1; i<titleLines.length; i++) {
344+
if (titleLines[i]-titleLines[i-1] === 1) {continue;}
345+
firstTitleLinePerMsg.push(titleLines[i]);
346+
}
347+
for (let i=titleLines.length-1; i>=0 ; i--) {
348+
if (scrollIdx>=firstTitleLinePerMsg[i]) {
349+
return MESSAGES[i + alreadyProcessed.idxSpan.start];
350+
}
351+
}
352+
}
353+
341354
let prevScrollIdx; // Used for stopping repeated triggering of next message by the scroller.
355+
let prevPrevScrollIdx; // Used to chose how to identify displayed message when selecting with button.
342356

343357
E.showScroller({
344358
scroll : initScroll*g.getFontHeight(),
@@ -367,32 +381,29 @@ function showMessagesScroller(msg, persist, alreadyProcessed) {
367381
true, alreadyProcessed);
368382
}, 40);
369383
}
384+
if (prevPrevScrollIdx!==prevScrollIdx) {prevPrevScrollIdx = prevScrollIdx;}
370385
prevScrollIdx = scrollIdx;
371386
},
372387
select : function(scrollIdx, touch) {
373-
let msgSelect;
374-
let firstTitleLinePerMsg = [titleLines[0]];
375-
for (let i=1; i<titleLines.length; i++) {
376-
if (titleLines[i]-titleLines[i-1] === 1) {continue;}
377-
firstTitleLinePerMsg.push(titleLines[i]);
378-
}
379-
for (let i=titleLines.length-1; i>=0 ; i--) {
380-
if (scrollIdx>=firstTitleLinePerMsg[i]) {
381-
msgSelect = MESSAGES[i + alreadyProcessed.idxSpan.start];
382-
break;
383-
}
384-
}
388+
const MSG_SELECT = identifyDisplayedMsg(scrollIdx);
385389
if (touch.type == 0) {
386390
WU.show();
387-
showMessage(msgSelect.id, true)
391+
if (BTN_WATCH) {clearWatch(BTN_WATCH);}
392+
showMessage(MSG_SELECT.id, true);
388393
}
389394
if (touch.type == 2) {
390395
WU.show();
391-
showMessageSettings(msgSelect)
396+
if (BTN_WATCH) {clearWatch(BTN_WATCH);}
397+
showMessageSettings(MSG_SELECT);
392398
}
393-
},
394-
//back : () => showMessage(messages[idx].id, true)
399+
}
395400
});
401+
const BTN_WATCH = setWatch(()=>{
402+
WU.show();
403+
const SCROLL_IDX_CENTER_SCREEN = prevScrollIdx>prevPrevScrollIdx ?
404+
prevScrollIdx-5 : prevScrollIdx+5; // FIXME: `±5` should depend on screen height and font height.
405+
showMessage(identifyDisplayedMsg(SCROLL_IDX_CENTER_SCREEN).id, true);
406+
}, BTN, {edge:'rising'});
396407
}
397408

398409
function showMessageSettings(msg) {

0 commit comments

Comments
 (0)