@@ -7,8 +7,27 @@ if (isClock) {
77 Bangle . setUI ( "clock" ) ;
88}
99
10+ // once at the start
11+ let background = require ( "clockbg" ) ;
12+
13+ // to fill the whole area
14+ background . fillRect ( Bangle . appRect . x + 3 , Bangle . appRect . y + 3 , Bangle . appRect . x + Bangle . appRect . w - 5 , Bangle . appRect . y + Bangle . appRect . h - 5 ) ;
15+ // if you ever need to reload to a new background (this could take ~100ms)
16+ //background.reload();
17+
18+ // Call this to unload (free memory - eg in .remove when fast loading)
19+ //background.unload();
20+
21+ // If .unload has been called and you might have fast-loaded back, call .load to ensure everything is loaded again!
22+ // It won't reload if it's already been loaded
23+ //background.load();
24+
1025// Load the clock infos
1126let clockInfoItems = require ( "clock_info" ) . load ( ) ;
27+ if ( clockInfoItems [ 0 ] . items [ 6 ] ) { // TODO: Should maybe be more robust against changes to clock info, i.e. search for "clock" among items.
28+ let clockItem = clockInfoItems [ 0 ] . items . pop ( ) ;
29+ clockInfoItems [ 0 ] . items . unshift ( clockItem ) ;
30+ }
1231// Add the
1332let clockInfoMenu = require ( "clock_info" ) . addInteractive ( clockInfoItems , {
1433 // Add the dimensions we're rendering to here - these are used to detect taps on the clock info area
@@ -20,21 +39,25 @@ let clockInfoMenu = require("clock_info").addInteractive(clockInfoItems, {
2039 // info: data returned from itm.get() containing text/img/etc
2140 // options: options passed into addInteractive
2241 // Clear the background
23- g . reset ( ) . clearRect ( options . x , options . y , options . x + options . w - 1 , options . y + options . h - 1 ) ;
42+ background . fillRect ( options . x , options . y , options . x + options . w - 1 , options . y + options . h - 1 ) ;
2443 // indicate focus - we're using a border, but you could change color?
25- if ( options . focus ) g . drawRect ( options . x , options . y , options . x + options . w - 1 , options . y + options . h - 1 ) ; // show if focused
44+ if ( options . focus ) g . fillRect ( options . x , options . y , options . x + options . w - 1 , options . y + options . h - 1 ) ; // show if focused
45+ background . fillRect ( options . x + 3 , options . y + 3 , options . x + options . w - 5 , options . y + options . h - 5 ) ;
2646 // we're drawing center-aligned here
2747 var midx = options . x + options . w / 2 ;
28- let scale = 5 ;
29- if ( info . img ) g . drawImage ( info . img , midx - 12 * scale , options . y + 4 , { scale :scale } ) ; // draw the image
30- g . setFont ( "6x8:2" ) . setFontAlign ( 0 , 1 ) . drawString ( info . text , midx , options . y + 160 ) ; // draw the text
48+ let scale = 4 ;
49+ if ( info . img ) require ( "clock_info" ) . drawBorderedImage ( info . img , midx - 12 * scale , options . y + 10 , { scale :scale } ) ; // draw the image
50+ let foundFontText = g . findFont ( info . text , {
51+ w : Bangle . appRect . w - 9 , // optional: width available (default = screen width)
52+ h : Bangle . appRect . h * 2 / 5 , // optional: height available (default = screen height)
53+ min : 10 , // optional: min font height
54+ max : 60 , // optional: max font height
55+ wrap : true , // optional: allow word wrap?
56+ trim : true // optional: trim to the specified height, add '...'
57+ } ) ; // TODO: g.findFont returns max size 28px. Would be nice with bigger font if there's room.
58+ //print(foundFontText);
59+ g . setFont ( foundFontText . font ) . setFontAlign ( 0 , 1 ) . drawString ( foundFontText . text , midx , options . y + 165 ) ; // draw the text
3160 }
3261} ) ;
33- setTimeout (
34- ( ) => {
35- clockInfoMenu . menuA = 0 ;
36- if ( clockInfoItems [ 0 ] . items [ 6 ] ) clockInfoMenu . menuB = 6 ; // Assume clkinfoclk is at indices (0,6)
37- clockInfoMenu . redraw ( )
38- } , 5
39- )
40- E . prependListener ( "kill" , ( ) => { clockInfoMenu . menuA = 0 ; clockInfoMenu . menuB = 6 ; } ) // reset to initial menu state to prepare for next launch.
62+
63+ E . prependListener ( "kill" , ( ) => { clockInfoMenu . menuA = 0 ; clockInfoMenu . menuB = 0 ; } ) // reset to initial menu state to prepare for next launch.
0 commit comments