@@ -10,18 +10,24 @@ if (isClock) {
1010// once at the start
1111let background = require ( "clockbg" ) ;
1212let clock_info = require ( "clock_info" ) ;
13+ const R = Bangle . appRect ;
14+ let txtg = Graphics . createArrayBuffer ( R . w >> 1 , 32 , 2 ) ;
15+ txtg . transparent = 0 ;
16+ txtg . palette = new Uint16Array ( [ 0 , g . theme . bg , g . theme . bg , g . theme . fg ] ) ;
1317
1418// Load the clock infos
1519let clockInfoItems = clock_info . load ( ) ;
16- if ( clockInfoItems [ 0 ] . items [ 6 ] ) { // TODO: Should maybe be more robust against changes to clock info, i.e. search for "clock" among items.
17- let clockItem = clockInfoItems [ 0 ] . items . pop ( ) ;
18- clockInfoItems [ 0 ] . items . unshift ( clockItem ) ;
20+ let clockInfoClockIdx = clockInfoItems [ 0 ] . items . findIndex ( c => c . name == "Clock" ) ;
21+ if ( clockInfoClockIdx >= 0 ) { // pull the clock to the front
22+ let clockInfoClock = clockInfoItems [ 0 ] . items [ clockInfoClockIdx ] ;
23+ clockInfoItems [ 0 ] . items . splice ( clockInfoClockIdx , 1 ) ; // remove
24+ clockInfoItems [ 0 ] . items . unshift ( clockInfoClock ) ; // add to front
1925}
2026// Add the
2127let clockInfoMenu = clock_info . addInteractive ( clockInfoItems , {
2228 app : "bigclkinfo" ,
2329 // Add the dimensions we're rendering to here - these are used to detect taps on the clock info area
24- x : 0 , y : 0 , w : Bangle . appRect . w , h : Bangle . appRect . h , // You can add other information here you want to be passed into 'options' in 'draw'
30+ x : 0 , y : 0 , w : R . w , h : R . h , // You can add other information here you want to be passed into 'options' in 'draw'
2531 // This function draws the info
2632 draw : ( itm , info , options ) => {
2733 // itm: the item containing name/hasRange/etc
@@ -36,17 +42,32 @@ let clockInfoMenu = clock_info.addInteractive(clockInfoItems, {
3642 var midx = options . x + options . w / 2 ;
3743 let scale = 4 ;
3844 if ( info . img ) clock_info . drawBorderedImage ( info . img , midx - 12 * scale , options . y + 10 , { scale :scale } ) ; // draw the image
39- let foundFontText = g . findFont ( info . text , {
40- w : options . w - 9 , // optional: width available (default = screen width)
41- h : options . h * 2 / 5 , // optional: height available (default = screen height)
45+ let foundFontText = txtg . findFont ( info . text , {
46+ w : txtg . getWidth ( ) - 4 , // optional: width available (default = screen width)
47+ h : txtg . getHeight ( ) - 4 , // optional: height available (default = screen height)
4248 min : 10 , // optional: min font height
43- max : 60 , // optional: max font height
49+ max : 24 , // optional: max font height
4450 wrap : true , // optional: allow word wrap?
4551 trim : true // optional: trim to the specified height, add '...'
4652 } ) ; // TODO: g.findFont returns max size 28px. Would be nice with bigger font if there's room.
4753 //print(foundFontText);
48- g . setFont ( foundFontText . font ) . setFontAlign ( 0 , 1 ) . drawString ( foundFontText . text , midx , options . y + 165 ) ; // draw the text
54+ txtg . clear ( 1 ) ;
55+ txtg . setFont ( foundFontText . font ) . setFontAlign ( 0 , 1 ) ;
56+ txtg . drawString ( foundFontText . text , txtg . getWidth ( ) / 2 , txtg . getHeight ( ) - 2 ) ;
57+ txtg . filter ( [ // a gaussian filter
58+ 0 , 1 , 1 , 1 , 0 ,
59+ 1 , 1 , 1 , 1 , 1 ,
60+ 1 , 1 , 1 , 1 , 1 ,
61+ 1 , 1 , 1 , 1 , 1 ,
62+ 0 , 1 , 1 , 1 , 0 ,
63+ ] , { w :5 , h :5 , div :1 , max :1 , filter :"max" } ) ;
64+ g . drawImage ( txtg , 0 , R . h - txtg . getHeight ( ) * 2 - 4 , { scale :2 } ) ;
4965 }
5066} ) ;
5167
68+ Bangle . on ( "lock" , function ( locked ) {
69+ // ensure that when unlocked, we automaticlly focus the clockinfo
70+ if ( ! locked && ! clockInfoMenu . focus )
71+ Bangle . emit ( "touch" , 0 , { x :100 , y :100 } ) ;
72+ } ) ;
5273E . prependListener ( "kill" , ( ) => { clockInfoMenu . menuA = 0 ; clockInfoMenu . menuB = 0 ; } ) // reset to initial menu state to prepare for next launch.
0 commit comments