@@ -295,10 +295,10 @@ function showMessagesScroller(msg, persist) {
295
295
var bodyFont = fontBig ;
296
296
g . setFont ( bodyFont ) ;
297
297
const FONT_HEIGHT = g . getFontHeight ( ) ;
298
- const LINES_PER_SCREEN = APP_RECT . h / FONT_HEIGHT ;
299
298
let initScroll ;
300
299
var titleLines = [ ] ;
301
300
let allLines = [ ] ;
301
+ let firstTitleLinePerMsg = [ ] ;
302
302
for ( let i = 0 ; i < MESSAGES . length ; i ++ ) {
303
303
if ( MSG_IDX === i ) { initScroll = allLines . length * FONT_HEIGHT }
304
304
let msgIter = MESSAGES [ i ] ;
@@ -309,6 +309,7 @@ function showMessagesScroller(msg, persist) {
309
309
lines = g . wrapString ( TITLE_STRING , APP_RECT . w - 10 ) ;
310
310
for ( let i = 0 ; i < lines . length ; i ++ ) {
311
311
titleLines . push ( i + allLines . length ) ;
312
+ if ( i == 0 ) firstTitleLinePerMsg . push ( i + allLines . length ) ;
312
313
}
313
314
lines = lines . concat ( g . wrapString ( msgIter . body , APP_RECT . w - 10 ) ,
314
315
[ "-" . repeat ( 12 ) ] ) ;
@@ -320,22 +321,6 @@ function showMessagesScroller(msg, persist) {
320
321
returnToClockIfEmpty ( ) ;
321
322
}
322
323
323
- function identifyDisplayedMsg ( scrollIdx ) {
324
- let firstTitleLinePerMsg = [ titleLines [ 0 ] ] ;
325
- for ( let i = 1 ; i < titleLines . length ; i ++ ) {
326
- if ( titleLines [ i ] - titleLines [ i - 1 ] === 1 ) { continue ; }
327
- firstTitleLinePerMsg . push ( titleLines [ i ] ) ;
328
- }
329
- for ( let i = titleLines . length - 1 ; i >= 0 ; i -- ) {
330
- if ( scrollIdx >= firstTitleLinePerMsg [ i ] ) {
331
- return MESSAGES [ i ] ;
332
- }
333
- }
334
- }
335
-
336
- // Used to choose how to identify displayed message when selecting with hw button.
337
- let prevScrollIdxs = [ undefined , undefined ] ; // [prevIdx, prevPrevIdx]
338
-
339
324
E . showScroller ( {
340
325
scroll : initScroll ,
341
326
h : FONT_HEIGHT , // height of each menu item in pixels
@@ -346,39 +331,35 @@ function showMessagesScroller(msg, persist) {
346
331
setColor ( titleLines . find ( e => e == scrollIdx ) !== undefined ? g . theme . fg2 : g . theme . fg ) .
347
332
clearRect ( r ) ;
348
333
g . setFont ( bodyFont ) . setFontAlign ( 0 , - 1 ) . drawString ( allLines [ scrollIdx ] , r . x + r . w / 2 , r . y ) ;
349
- if ( prevScrollIdxs [ 1 ] !== prevScrollIdxs [ 0 ] ) {
350
- prevScrollIdxs [ 1 ] = prevScrollIdxs [ 0 ] ;
351
- if ( ! persist ) { resetReloadTimeout ( ) ; }
352
- }
353
- prevScrollIdxs [ 0 ] = scrollIdx ;
334
+ if ( ! persist ) { resetReloadTimeout ( ) ; }
354
335
} ,
355
336
select : function ( scrollIdx , touch ) {
356
337
WU . show ( ) ;
357
- const MSG_SELECT = identifyDisplayedMsg ( scrollIdx ) ;
358
338
clearBtnHandler ( ) ;
359
- if ( ! touch ) { showMessageRouter ( MSG_SELECT , true , "overview" ) ; return ; }
360
- if ( touch . type == 0 ) { showMessageRouter ( MSG_SELECT , true , "overview" ) ; }
361
- if ( touch . type == 2 ) { showMessageSettings ( MSG_SELECT ) ; }
339
+ for ( let i = firstTitleLinePerMsg . length - 1 ; i >= 0 ; i -- ) {
340
+ if ( scrollIdx >= firstTitleLinePerMsg [ i ] ) {
341
+ if ( ! touch || touch . type === 0 ) { showMessageRouter ( MESSAGES [ i ] , true ,
342
+ "overview" ) ; return ; }
343
+ if ( touch . type == 2 ) { showMessageSettings ( MESSAGES [ i ] ) ; }
344
+ break ;
345
+ }
346
+ }
362
347
}
363
348
} ) ;
364
349
365
- function clearBtnHandler ( ) {
366
- if ( Bangle . btnHandler ) { clearWatch ( Bangle . btnHandler ) ; Bangle . btnHandler = undefined ; }
367
- }
368
- clearBtnHandler ( ) ;
369
-
370
350
// If Bangle.js 2 add an external select hw button handler.
371
- Bangle . btnHandler = ( ( 2 === process . env . HWVERSION ) && ( setWatch ( ( ) => {
351
+ let btnHandler = ( ( 2 === process . env . HWVERSION ) && ( setWatch ( ( ) => {
372
352
Bangle . emit ( "drag" , { dy :0 } ) ; // Compatibility with `kineticscroll`, stopping the scroller so it doesn't continue scrolling when the `showMessageOverview` screen is loaded.
373
353
// Zero ms timeout as to not move on before the scroller has registered the emitted drag event.
374
354
setTimeout ( ( ) => {
375
355
if ( "messagegui.new.js" === global . __FILE__ ) { return load ( ) ; }
376
- const SCROLL_IDX_CENTER_SCREEN = prevScrollIdxs [ 0 ] > prevScrollIdxs [ 1 ] ?
377
- prevScrollIdxs [ 0 ] - LINES_PER_SCREEN / 2 :prevScrollIdxs [ 0 ] + LINES_PER_SCREEN / 2 ;
378
- WU . show ( ) ;
379
- showMessageOverview ( identifyDisplayedMsg ( SCROLL_IDX_CENTER_SCREEN ) . id , true ) ;
356
+ Bangle . emit ( "touch" , 1 , { x :Bangle . appRect . x2 / 2 , y :Bangle . appRect . y2 / 2 , type :0 } ) ;
380
357
} , 0 ) ;
381
- } , BTN , { edge :'rising' } ) ) ) ;
358
+ } , BTN , { edge :'rising' , repeat :true } ) ) ) ;
359
+
360
+ function clearBtnHandler ( ) {
361
+ if ( btnHandler ) { clearWatch ( btnHandler ) ; btnHandler = undefined ; }
362
+ }
382
363
}
383
364
384
365
function showMessageSettings ( msg ) {
0 commit comments