@@ -5,11 +5,43 @@ let current = weather.get();
55
66Bangle . loadWidgets ( ) ;
77
8+
89var layout = new Layout ( { type :"v" , bgCol : g . theme . bg , c : [
910 { filly : 1 } ,
1011 { type : "h" , filly : 0 , c : [
11- { type : "custom" , width : g . getWidth ( ) / 2 , height : g . getWidth ( ) / 2 , valign : - 1 , txt : "unknown" , id : "icon" ,
12- render : l => weather . drawIcon ( l , l . x + l . w / 2 , l . y + l . h / 2 , l . w / 2 - 5 ) } ,
12+ { type : "v" , width : g . getWidth ( ) / 2 , c : [ // Vertical container for icon + UV
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 - 10 ) } ,
15+ { type : "custom" , fillx : 1 , height : 20 , id : "uvDisplay" ,
16+ render : l => {
17+ if ( ! current || current . uv === undefined ) return ;
18+ const uv = Math . min ( parseInt ( current . uv ) , 11 ) ; // Cap at 11
19+
20+ // UV color thresholds: [max_value, color] based on WHO standards
21+ const colors = [ [ 2 , "#0F0" ] , [ 5 , "#FF0" ] , [ 7 , "#F80" ] , [ 10 , "#F00" ] , [ 11 , "#F0F" ] ] ;
22+ const color = colors . find ( c => uv <= c [ 0 ] ) [ 1 ] ;
23+
24+ // Setup and measure label
25+ g . setFont ( "6x8" ) . setFontAlign ( - 1 , 0 ) ;
26+ const label = "UV: " ;
27+ const labelW = g . stringWidth ( label ) ;
28+
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 ;
33+
34+ // Draw label
35+ g . setColor ( g . theme . fg ) . drawString ( label , x , y ) ;
36+
37+ // Draw UV blocks
38+ g . setColor ( color ) ;
39+ for ( let i = 0 ; i < uv ; i ++ ) {
40+ g . fillRect ( x + labelW + i * 5 , y - 3 , x + labelW + i * 5 + 3 , y + 3 ) ;
41+ }
42+ }
43+ } ,
44+ ] } ,
1345 { type : "v" , fillx : 1 , c : [
1446 { type : "h" , pad : 2 , c : [
1547 { type : "txt" , font : "18%" , id : "temp" , label : "000" } ,
@@ -108,4 +140,4 @@ Bangle.setUI("clock");
108140// This matters for widgets that hide themselves for clocks, like widclk or widclose
109141delete Bangle . CLOCK ;
110142
111- Bangle . drawWidgets ( ) ;
143+ Bangle . drawWidgets ( ) ;
0 commit comments