@@ -9,16 +9,16 @@ Graphics.prototype.setFontBold = function(scale) {
99{ // must be inside our own scope here so that when we are unloaded everything disappears
1010 // we also define functions using 'let fn = function() {..}' for the same reason. function decls are global
1111let drawTimeout ;
12-
13- let calcStrLength = function ( str , limitLength ) {
12+ let showInlineClkInfo = true ;
13+ let calcStrLength = function ( str , maxLength ) {
1414
1515 //too long
1616
1717 // Example maximum length
1818 var truncatedText = str ;
1919
20- if ( str . length > limitLength ) {
21- truncatedText = str . substring ( 0 , limitLength - 3 ) + "..." ;
20+ if ( str . length > maxLength ) {
21+ truncatedText = str . substring ( 0 , maxLength - 3 ) + "..." ;
2222 }
2323
2424 return truncatedText ;
@@ -62,7 +62,6 @@ let bRoundedRectangle= function(x1,y1,x2,y2,r) {
6262 } ;
6363
6464
65-
6665//CLOCK INFO
6766let clockInfoItems = require ( "clock_info" ) . load ( ) ;
6867
@@ -84,7 +83,7 @@ let clockInfoMenuLeft = require("clock_info").addInteractive(clockInfoItems, {
8483 // indicate focus - we're using a border, but you could change color?
8584 if ( options . focus ) {
8685 // show if focused
87- g . setColor ( 0 , 15 , 255 ) ;
86+ g . setColor ( 0 , 255 , 15 ) ;
8887 bRoundedRectangle ( options . x , options . y , options . x + options . w , options . y + options . h , 8 ) ;
8988 } else {
9089 g . setColor ( g . theme . fg ) ;
@@ -117,7 +116,7 @@ let clockInfoMenuRight = require("clock_info").addInteractive(clockInfoItems, {
117116 // indicate focus - we're using a border, but you could change color?
118117 if ( options . focus ) {
119118 // show if focused
120- g . setColor ( 0 , 15 , 255 ) ;
119+ g . setColor ( 0 , 255 , 15 ) ;
121120 bRoundedRectangle ( options . x , options . y , options . x + options . w , options . y + options . h , 8 ) ;
122121 } else {
123122 g . setColor ( g . theme . fg ) ;
@@ -132,12 +131,39 @@ let clockInfoMenuRight = require("clock_info").addInteractive(clockInfoItems, {
132131 g . setFont ( "Vector" , 16 ) . setFontAlign ( 0 , 1 ) . drawString ( calcStrLength ( info . text , 8 ) , midx , midy + 23 ) ; // draw the text
133132 }
134133} ) ;
134+ let clockInfoMenuInline ;
135+
136+ if ( showInlineClkInfo ) {
137+ clockInfoMenuInline = require ( "clock_info" ) . addInteractive ( clockInfoItems , {
138+ // Add the dimensions we're rendering to here - these are used to detect taps on the clock info area
139+ x : g . getWidth ( ) / 2 + 6 , y : 69 , w : 95 , h :25 ,
140+ // You can add other information here you want to be passed into 'options' in 'draw'
141+ // This function draws the info
142+ draw : ( itm , info , options ) => {
143+ // itm: the item containing name/hasRange/etc
144+ // info: data returned from itm.get() containing text/img/etc
145+ // options: options passed into addInteractive
146+ // Clear the background
147+ g . reset ( ) . clearRect ( options . x , options . y , options . x + options . w , options . y + options . h ) ;
148+ // indicate focus - we're using a border, but you could change color?
149+ if ( options . focus ) {
150+ // show if focused
151+ g . setColor ( 0 , 255 , 15 ) ;
152+
153+ }
154+ // we're drawing center-aligned here
155+ //var midx = options.x+options.w/2;
156+ var midy = options . y + options . h / 2 ;
157+ if ( info . img ) {
158+ g . drawImage ( info . img , options . x + 4 , midy - 7.2 , { scale : 0.63 } ) ;
159+ } // draw the image
160+ g . setFont ( "Vector" , 15 ) . setFontAlign ( - 1 , 0 ) . drawString ( calcStrLength ( info . text , 6 ) , options . x + 22 , midy + 1 ) ; // draw the text
161+ }
162+ } ) ;
163+
164+ }
135165
136166
137-
138-
139-
140-
141167
142168// DRAW FACE
143169let draw = function ( ) {
@@ -150,7 +176,7 @@ let draw = function() {
150176 // draw the current time (4x size 7 segment)
151177
152178 // align bottom right
153-
179+
154180 g . setFontBold ( ) ;
155181
156182 if ( meridian != "" ) {
@@ -163,13 +189,13 @@ let draw = function() {
163189 var meridianStrWidth = g . stringWidth ( meridian ) ;
164190 var totalStrWidth = meridianStrWidth + padding + clkStrWidth ;
165191 var startX = ( ( g . getWidth ( ) - totalStrWidth ) / 2 ) + 6 ;
166- g . clearRect ( 0 , 0 , g . getWidth ( ) , 90 ) ;
192+ g . clearRect ( 0 , 0 , g . getWidth ( ) , 64 ) ;
167193 g . setFontBold ( ) ;
168194 g . setFontAlign ( - 1 , 1 ) ;
169- g . drawString ( clock , startX , Y + 2 , true ) ;
195+ g . drawString ( clock , startX , Y - 2 ) ;
170196 g . setFont ( "Vector" , 20 ) ;
171197 g . setFontAlign ( - 1 , 1 ) ;
172- g . drawString ( meridian , startX + clkStrWidth + padding , Y - 5 , true ) ;
198+ g . drawString ( meridian , startX + clkStrWidth + padding , Y - 9 , true ) ;
173199
174200 } else {
175201
@@ -179,15 +205,17 @@ let draw = function() {
179205
180206 }
181207
182-
183208 // draw the date, in a normal font
184- g . setFont ( "Vector" , 18 ) ;
185- g . setFontAlign ( 0 , 0 ) ; // align center bottom
209+ g . setFont ( "Vector" , 16 ) ;
210+ g . setFontAlign ( 1 , 0 ) ; // align center bottom
186211 // pad the date - this clears the background if the date were to change length
187- var dateStr = require ( "locale" ) . dow ( new Date ( ) , 1 ) + ", " + require ( "locale" ) . month ( new Date ( ) , true ) + " " + new Date ( ) . getDate ( ) ;
188- g . drawString ( " " + dateStr + " " , g . getWidth ( ) / 2 , Y + 9 , true /*clear background*/ ) ;
212+ var dateStr = require ( "locale" ) . dow ( new Date ( ) , 1 ) + ", " + new Date ( ) . getDate ( ) ;
213+ //print(g.stringHeight(dateStr));
214+ g . drawString ( " " + dateStr + " " , g . getWidth ( ) / 2 + 6 , Y + 9 , true /*clear background*/ ) ;
189215
190216 Bangle . drawWidgets ( ) ;
217+ g . setColor ( "#ffffff" ) ;
218+
191219
192220 // queue next draw
193221 if ( drawTimeout ) clearTimeout ( drawTimeout ) ;
@@ -210,11 +238,14 @@ Bangle.setUI({
210238 delete Graphics . prototype . setFontBold ;
211239 clockInfoMenuRight . remove ( ) ;
212240 clockInfoMenuLeft . remove ( ) ;
241+ if ( showInlineClkInfo ) clockInfoMenuInline . remove ( ) ;
213242
214243 } } ) ;
215244
216245g . clear ( ) ;
217246// Load widgets
218247Bangle . loadWidgets ( ) ;
219248draw ( ) ;
249+
250+
220251}
0 commit comments