@@ -9,59 +9,66 @@ Bangle.loadWidgets();
99var layout = new Layout ( { type :"v" , bgCol : g . theme . bg , c : [
1010 { filly : 1 } ,
1111 { type : "h" , filly : 0 , c : [
12- { type : "v" , width : g . getWidth ( ) / 2 , c : [ // Vertical container for icon
13- { type : "custom" , fillx : 1 , height : g . getHeight ( ) / 2 - 30 , valign : - 1 , txt : "unknown" , id : "icon" ,
14- render : l => weather . drawIcon ( l , l . x + l . w / 2 , l . y + l . h / 2 , l . w / 2 - 5 ) } ,
15- ] } ,
16- { type : "v" , fillx : 1 , c : [
17- { type : "h" , pad : 2 , c : [
18- { type : "txt" , font : "18%" , id : "temp" , label : "000" } ,
19- { type : "txt" , font : "12%" , valign : - 1 , id : "tempUnit" , label : "°C" } ,
20- ] } ,
21- { filly : 1 } ,
22- { type : "txt" , font : "6x8" , pad : 2 , halign : 1 , label : /*LANG*/ "Humidity" } ,
23- { type : "txt" , font : "9%" , pad : 2 , halign : 1 , id : "hum" , label : "000%" } ,
24- { type : "txt" , font : "6x8" , pad : [ 2 , 2 , 2 , 2 ] , halign : - 1 , label : /*LANG*/ "Wind" } ,
25- { type : "h" , pad : [ 0 , 2 , 2 , 2 ] , halign : - 1 , c : [
26- { type : "txt" , font : "9%" , pad : 2 , id : "wind" , label : "00" } ,
27- { type : "txt" , font : "6x8" , pad : 2 , valign : - 1 , id : "windUnit" , label : "km/h" } ,
28- ] } ,
29- { type : "custom" , fillx : 1 , height : 15 , id : "uvDisplay" ,
12+ { type : "v" , width : g . getWidth ( ) / 2 , c : [ // Vertical container for icon + UV
13+ { type : "custom" , fillx : 1 , height : ( g . getHeight ( ) / 2 ) - 10 , valign : - 1 , txt : "unknown" , id : "icon" , bgCol :g . theme . bg ,
14+ render : l => weather . drawIcon ( l , l . x + l . w / 2 , l . y + l . h / 2 , l . w / 3 ) } ,
15+ { type : "custom" , fillx : 1 , height : 20 , id : "uvDisplay" ,
3016 render : l => {
31- if ( ! current || current . uv === undefined || current . uv === 0 ) return ;
17+ if ( ! current || current . uv === undefined ) return ;
3218 const uv = Math . min ( parseInt ( current . uv ) , 11 ) ; // Cap at 11
3319
3420 // UV color thresholds: [max_value, color] based on WHO standards
3521 const colors = [ [ 2 , "#0F0" ] , [ 5 , "#FF0" ] , [ 7 , "#F80" ] , [ 10 , "#F00" ] , [ 11 , "#F0F" ] ] ;
3622 const color = colors . find ( c => uv <= c [ 0 ] ) [ 1 ] ;
37- const blockH = 8 , blockW = 3 ;
3823
39- // Draw UV title and blocks on same line
24+ // Setup and measure label
4025 g . setFont ( "6x8" ) . setFontAlign ( - 1 , 0 ) ;
41- const label = "UV" ;
26+ const label = "UV: " ;
4227 const labelW = g . stringWidth ( label ) ;
4328
44- const x = l . x + 2 ;
45- const y = l . y + l . h / 2 ;
29+ // Calculate centered position (4px block + 1px spacing) * blocks - last spacing
30+ const totalW = labelW + uv * 5 - ( uv > 0 ? 1 : 0 ) ;
31+ const x = l . x + ( l . w - totalW ) / 2 ;
32+ const y = l . y + l . h + 6 ;
4633
47- // Draw title
34+ // Draw label
4835 g . setColor ( g . theme . fg ) . drawString ( label , x , y ) ;
4936
50- // Draw UV blocks after title
37+ // Draw UV blocks
5138 g . setColor ( color ) ;
5239 for ( let i = 0 ; i < uv ; i ++ ) {
53- const blockX = x + labelW + 4 + i * ( blockW + 2 ) ;
54- g . fillRect ( blockX , y - blockH / 2 , blockX + blockW , y + blockW / 2 ) ;
40+ g . fillRect ( x + labelW + i * 5 , y - 3 , x + labelW + i * 5 + 3 , y + 3 ) ;
5541 }
56-
57- // Reset graphics state to prevent interference
58- g . reset ( ) ;
5942 }
6043 } ,
6144 ] } ,
45+ { type : "v" , fillx : 1 , c : [
46+ { pad :5 } ,
47+ { type : "h" , pad : 2 , c : [
48+ { type : "txt" , font : "18%" , id : "temp" , label : "000" } ,
49+ { type : "txt" , font : "12%" , valign : - 1 , id : "tempUnit" , label : "°C" } ,
50+ ] } ,
51+ { filly : 1 } ,
52+ { type : "h" , pad : 1 , c : [
53+ { type : "txt" , font : "6x8" , pad : 2 , halign : 1 , label : /*LANG*/ "Feels:" } ,
54+ { type : "txt" , font : "9%" , pad : 2 , halign : 1 , id : "feelslike" , label : "35°F" } ,
55+ ] } ,
56+ { filly : 1 } ,
57+ { type : "h" , pad : 2 , c : [
58+ { type : "txt" , font : "6x8" , pad : 2 , halign : 1 , label : /*LANG*/ "Hum:" } ,
59+ { type : "txt" , font : "9%" , pad : 2 , halign : 1 , id : "hum" , label : "000%" } ,
60+ ] } ,
61+
62+ { filly : 1 } ,
63+ { type : "txt" , font : "6x8" , pad : 2 , halign : - 1 , label : /*LANG*/ "Wind" } ,
64+ { type : "h" , halign : - 1 , c : [
65+ { type : "txt" , font : "9%" , pad : 2 , id : "wind" , label : "00" } ,
66+ { type : "txt" , font : "6x8" , pad : 2 , valign : - 1 , id : "windUnit" , label : "km/h" } ,
67+ ] } ,
68+ ] } ,
6269 ] } ,
6370 { filly : 1 } ,
64- { type : "txt" , font : "9%" , wrap : true , height : g . getHeight ( ) * 0.18 , fillx : 1 , id : "cond" , label : /*LANG*/ "Weather condition" } ,
71+ { type : "txt" , font : "9%" , wrap : true , height : g . getHeight ( ) * 0.18 , fillx : 1 , id : "cond" , label : /*LANG*/ "Weather condition" } ,
6572 { filly : 1 } ,
6673 { type : "h" , c : [
6774 { type : "txt" , font : "6x8" , pad : 4 , id : "loc" , label : "Toronto" } ,
@@ -83,8 +90,15 @@ function draw() {
8390 layout . icon . txt = current . txt ;
8491 layout . icon . code = current . code ;
8592 const temp = locale . temp ( current . temp - 273.15 ) . match ( / ^ ( \D * \d * ) ( .* ) $ / ) ;
93+ const feelsLikeTemp = locale . temp ( current . feels - 273.15 ) . match ( / ^ ( \D * \d * ) ( .* ) $ / ) ;
8694 layout . temp . label = temp [ 1 ] ;
8795 layout . tempUnit . label = temp [ 2 ] ;
96+ if ( ! current || current . feels === undefined ) {
97+ layout . feelslike . label = "N/A" ;
98+ } else {
99+ layout . feelslike . label = feelsLikeTemp [ 1 ] + feelsLikeTemp [ 2 ] ;
100+ }
101+
88102 layout . hum . label = current . hum + "%" ;
89103 const wind = locale . speed ( current . wind ) . match ( / ^ ( \D * \d * ) ( .* ) $ / ) ;
90104 layout . wind . label = wind [ 1 ] ;
@@ -93,15 +107,13 @@ function draw() {
93107 layout . loc . label = current . loc ;
94108 layout . updateTime . label = `${ formatDuration ( Date . now ( ) - current . time ) } ago` ; // How to autotranslate this and similar?
95109 layout . update ( ) ;
96- layout . forgetLazyState ( ) ;
97110 layout . render ( ) ;
98111}
99112
100113function drawUpdateTime ( ) {
101114 if ( ! current || ! current . time ) return ;
102115 layout . updateTime . label = `${ formatDuration ( Date . now ( ) - current . time ) } ago` ;
103116 layout . update ( ) ;
104- layout . render ( ) ;
105117}
106118
107119function update ( ) {
@@ -112,9 +124,9 @@ function update() {
112124 } else {
113125 layout . forgetLazyState ( ) ;
114126 if ( NRF . getSecurityStatus ( ) . connected ) {
115- E . showMessage ( /*LANG*/ "Weather\nunknown\n\nIs Gadgetbridge\nweather\nreporting set\nup on your\nphone? " ) ;
127+ E . showMessage ( /*LANG*/ "Weather Data Expired " ) ;
116128 } else {
117- E . showMessage ( /*LANG*/ "Weather\nunknown\n\nGadgetbridge \nnot connected" ) ;
129+ E . showMessage ( /*LANG*/ "Weather\nunknown\n\nPhone \nnot connected" ) ;
118130 NRF . on ( "connect" , update ) ;
119131 }
120132 }
@@ -143,4 +155,4 @@ Bangle.setUI("clock");
143155// This matters for widgets that hide themselves for clocks, like widclk or widclose
144156delete Bangle . CLOCK ;
145157
146- Bangle . drawWidgets ( ) ;
158+ Bangle . drawWidgets ( ) ;
0 commit comments