1
1
#include " displayapp/screens/WatchFaceMixed.h"
2
2
#include < cmath>
3
+ #include < cstdint>
4
+ #include < limits>
3
5
#include < lvgl/lvgl.h>
4
6
#include " displayapp/screens/Symbols.h"
5
7
#include " displayapp/screens/WeatherSymbols.h"
@@ -157,7 +159,7 @@ WatchFaceMixed::WatchFaceMixed(Controllers::DateTime& dateTimeController,
157
159
lv_label_set_align (label_time_ampm, LV_LABEL_ALIGN_RIGHT);
158
160
159
161
label_date = lv_label_create (lv_scr_act (), nullptr );
160
- lv_obj_align (label_date, lv_scr_act (), LV_ALIGN_CENTER, 0 , 30 );
162
+ lv_obj_align (label_date, lv_scr_act (), LV_ALIGN_CENTER, 0 , 20 );
161
163
lv_label_set_align (label_date, LV_LABEL_ALIGN_CENTER);
162
164
163
165
// Notification
@@ -173,13 +175,13 @@ WatchFaceMixed::WatchFaceMixed(Controllers::DateTime& dateTimeController,
173
175
lv_obj_set_style_local_text_color (weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (0x999999 ));
174
176
lv_obj_set_style_local_text_font (weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &fontawesome_weathericons);
175
177
lv_label_set_text (weatherIcon, " " );
176
- lv_obj_align (weatherIcon, lv_scr_act (), LV_ALIGN_IN_TOP_MID , -20 , 50 );
178
+ lv_obj_align (weatherIcon, lv_scr_act (), LV_ALIGN_CENTER , -23 , 50 );
177
179
lv_obj_set_auto_realign (weatherIcon, true );
178
180
179
181
temperature = lv_label_create (lv_scr_act (), nullptr );
180
182
lv_obj_set_style_local_text_color (temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (0x999999 ));
181
183
lv_label_set_text (temperature, " " );
182
- lv_obj_align (temperature, lv_scr_act (), LV_ALIGN_IN_TOP_MID, 20 , 50 );
184
+ lv_obj_align (temperature, lv_scr_act (), LV_ALIGN_CENTER, 22 , 50 );
183
185
184
186
// HeartBeat
185
187
@@ -324,20 +326,89 @@ void WatchFaceMixed::UpdateSteps() {
324
326
lv_obj_realign (stepIcon);
325
327
}
326
328
329
+ uint32_t linear_color_gradient (uint32_t startingColor, uint32_t endingColor, uint8_t progress){
330
+ constexpr decltype (progress) maxProgress = std::numeric_limits<decltype (progress)>::max ();
331
+ uint32_t res = 0 ;
332
+ res += ((maxProgress-progress)*((startingColor&0xff0000 ) >> 16 ) + progress*((endingColor&0xff0000 ) >> 16 )) / maxProgress;
333
+ res <<= 8 ;
334
+ res += ((maxProgress - progress) * ((startingColor&0x00ff00 ) >> 8 ) + progress * ((endingColor&0x00ff00 ) >> 8 )) / maxProgress;
335
+ res <<= 8 ;
336
+ res += ((maxProgress - progress) * (startingColor&0x0000ff ) + progress * (endingColor&0x0000ff )) / maxProgress;
337
+
338
+ return res;
339
+ }
340
+
327
341
void WatchFaceMixed::UpdateWeather () {
328
342
auto optCurrentWeather = currentWeather.Get ();
329
343
if (optCurrentWeather) {
330
344
int16_t temp = optCurrentWeather->temperature .Celsius ();
331
345
char tempUnit = ' C' ;
346
+
347
+ enum TempColor : uint32_t {
348
+ VeryCold = 0x6495ed ,
349
+ Freezing = 0x00ffff ,
350
+ Cold = 0x808080 ,
351
+ Hot = 0xfafd0f ,
352
+ VeryHot = 0xff0000
353
+ };
354
+ if (temp < -30 ) {
355
+ lv_obj_set_style_local_text_color (temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (TempColor::VeryCold));
356
+ } else if (-30 <= temp && temp < 0 ) {
357
+ lv_obj_set_style_local_text_color (temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (linear_color_gradient (TempColor::VeryCold, TempColor::Freezing, 255 *(temp+30 )/30 )));
358
+ } else if (0 <= temp && temp < 10 ) {
359
+ lv_obj_set_style_local_text_color (temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (linear_color_gradient (TempColor::Freezing, TempColor::Cold, 255 *temp/10 )));
360
+ } else if (10 <= temp && temp < 18 ) {
361
+ lv_obj_set_style_local_text_color (temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (linear_color_gradient (TempColor::Cold, TempColor::Hot, 255 *(temp-10 )/8 )));
362
+ } else if (18 <= temp && temp < 50 ) {
363
+ lv_obj_set_style_local_text_color (temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (linear_color_gradient (TempColor::Hot, TempColor::VeryHot, 255 *(temp-18 )/32 )));
364
+ } else if (temp >= 50 ) {
365
+ lv_obj_set_style_local_text_color (temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (TempColor::VeryHot));
366
+ }
332
367
if (settingsController.GetWeatherFormat () == Controllers::Settings::WeatherFormat::Imperial) {
333
368
temp = optCurrentWeather->temperature .Fahrenheit ();
334
369
tempUnit = ' F' ;
335
370
}
336
371
lv_label_set_text_fmt (temperature, " %d°%c" , temp, tempUnit);
372
+
337
373
lv_label_set_text (weatherIcon, Symbols::GetSymbol (optCurrentWeather->iconId ));
374
+ using Icons = Pinetime::Controllers::SimpleWeatherService::Icons;
375
+ switch (optCurrentWeather->iconId ){
376
+ case Icons::Sun:
377
+ lv_obj_set_style_local_text_color (weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (0xfafd0f ));
378
+ break ;
379
+ case Icons::CloudsSun:
380
+ lv_obj_set_style_local_text_color (weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (0xc4c745 ));
381
+ break ;
382
+ case Icons::Clouds:
383
+ lv_obj_set_style_local_text_color (weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (0xcbd0d2 ));
384
+ break ;
385
+ case Icons::BrokenClouds:
386
+ lv_obj_set_style_local_text_color (weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (0x7e8796 ));
387
+ break ;
388
+ case Icons::CloudShowerHeavy:
389
+ lv_obj_set_style_local_text_color (weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (0x000080 ));
390
+ break ;
391
+ case Icons::CloudSunRain:
392
+ lv_obj_set_style_local_text_color (weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (0xbfddea ));
393
+ break ;
394
+ case Icons::Thunderstorm:
395
+ lv_obj_set_style_local_text_color (weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (0xC4893D ));
396
+ break ;
397
+ case Icons::Snow:
398
+ lv_obj_set_style_local_text_color (weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (0xffffff ));
399
+ break ;
400
+ case Icons::Smog:
401
+ lv_obj_set_style_local_text_color (weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (0x697379 ));
402
+ break ;
403
+ default :
404
+ lv_obj_set_style_local_text_color (weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (0x999999 ));
405
+ break ;
406
+ }
338
407
} else {
339
408
lv_label_set_text_static (temperature, " " );
409
+ lv_obj_set_style_local_text_color (temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (0x999999 ));
340
410
lv_label_set_text (weatherIcon, " " );
411
+ lv_obj_set_style_local_text_color (weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (0x999999 ));
341
412
}
342
413
lv_obj_realign (temperature);
343
414
lv_obj_realign (weatherIcon);
0 commit comments