From eb6c362c8fbe7489d1a4f8623afda1155872c049 Mon Sep 17 00:00:00 2001 From: Julian Vos Date: Mon, 25 Nov 2024 20:28:28 +0000 Subject: [PATCH] feat: add option to switch which segment gets replaced with weather --- src/components/settings/Settings.h | 14 ++ .../screens/WatchFaceCasioStyleG7710.cpp | 178 +++++++++++++----- .../screens/WatchFaceCasioStyleG7710.h | 8 + 3 files changed, 154 insertions(+), 46 deletions(-) diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index b48104de3b..fdd8f982af 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -45,8 +45,11 @@ namespace Pinetime { PTSWeather weatherEnable = PTSWeather::Off; }; + enum class CasioWeatherSegment : uint8_t { WeekNumber, DayCounter, DayOfWeek }; + struct CasioStyleG7710 { PTSWeather weatherEnable = PTSWeather::Off; + CasioWeatherSegment weatherSegment = CasioWeatherSegment::DayCounter; }; struct WatchFaceInfineat { @@ -168,6 +171,17 @@ namespace Pinetime { return settings.casio.weatherEnable; } + void SetCasioWeatherSegment(CasioWeatherSegment weatherSegment) { + if (weatherSegment != settings.casio.weatherSegment) + settingsChanged = true; + + settings.casio.weatherSegment = weatherSegment; + } + + CasioWeatherSegment GetCasioWeatherSegment() const { + return settings.casio.weatherSegment; + } + void SetAppMenu(uint8_t menu) { appMenu = menu; }; diff --git a/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp b/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp index 85005d1757..5375a63778 100644 --- a/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp +++ b/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp @@ -101,17 +101,12 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(Controllers::DateTime& dateTi lv_obj_set_style_local_text_color(label_day_of_year, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); lv_obj_set_style_local_text_font(label_day_of_year, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, font_segment40); lv_label_set_text_static(label_day_of_year, "181-184"); - if (settingsController.GetCasioWeather() == Pinetime::Controllers::Settings::PTSWeather::On) { - lv_obj_set_hidden(label_day_of_year, true); - } else { - lv_obj_set_hidden(label_day_of_year, false); - } weatherIcon = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); lv_obj_set_style_local_text_font(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &fontawesome_weathericons); lv_label_set_text_static(weatherIcon, ""); - lv_obj_align(weatherIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 110, 30); + lv_obj_set_auto_realign(weatherIcon, true); if (settingsController.GetCasioWeather() == Pinetime::Controllers::Settings::PTSWeather::On) { lv_obj_set_hidden(weatherIcon, false); @@ -121,13 +116,18 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(Controllers::DateTime& dateTi label_temperature = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(label_temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); - lv_obj_set_style_local_text_font(label_temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, font_segment40); lv_label_set_text(label_temperature, ""); - lv_obj_align(label_temperature, nullptr, LV_ALIGN_IN_TOP_RIGHT, -5, 30); + + label_temperature_segment = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(label_temperature_segment, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); + lv_obj_set_style_local_text_font(label_temperature_segment, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, font_segment40); + lv_label_set_text(label_temperature_segment, ""); + + lv_obj_set_hidden(label_temperature_segment, true); + lv_obj_set_hidden(label_temperature, true); + if (settingsController.GetCasioWeather() == Pinetime::Controllers::Settings::PTSWeather::On) { - lv_obj_set_hidden(label_temperature, false); - } else { - lv_obj_set_hidden(label_temperature, true); + UpdateWeatherPosition(); } lv_style_init(&style_line); @@ -218,6 +218,16 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(Controllers::DateTime& dateTi lv_obj_set_event_cb(btnWeather, event_handler); lv_obj_set_hidden(btnWeather, true); + btnSegment = lv_btn_create(lv_scr_act(), nullptr); + btnSegment->user_data = this; + lv_obj_set_size(btnSegment, 160, 60); + lv_obj_align(btnSegment, lv_scr_act(), LV_ALIGN_CENTER, 0, 80); + lv_obj_set_style_local_bg_opa(btnSegment, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_50); + lv_obj_t* lblSegment = lv_label_create(btnSegment, nullptr); + lv_label_set_text_static(lblSegment, "Segment"); + lv_obj_set_event_cb(btnSegment, event_handler); + lv_obj_set_hidden(btnSegment, true); + btnClose = lv_btn_create(lv_scr_act(), nullptr); btnClose->user_data = this; lv_obj_set_size(btnClose, 60, 60); @@ -372,30 +382,7 @@ void WatchFaceCasioStyleG7710::Refresh() { } if (settingsController.GetCasioWeather() == Pinetime::Controllers::Settings::PTSWeather::On) { - currentWeather = weatherService.Current(); - - if (currentWeather.IsUpdated()) { - auto optCurrentWeather = currentWeather.Get(); - - if (optCurrentWeather) { - int16_t temp = optCurrentWeather->temperature.Celsius(); - char tempUnit = 'C'; - - if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) { - temp = optCurrentWeather->temperature.Fahrenheit(); - tempUnit = 'F'; - } - - lv_label_set_text_fmt(label_temperature, "%d°%c", temp, tempUnit); - lv_label_set_text(weatherIcon, Symbols::GetSymbol(optCurrentWeather->iconId)); - } else { - lv_label_set_text_static(label_temperature, ""); - lv_label_set_text(weatherIcon, ""); - } - - lv_obj_realign(label_temperature); - lv_obj_realign(weatherIcon); - } + DrawWeather(); } if (!lv_obj_get_hidden(btnClose)) { @@ -406,6 +393,80 @@ void WatchFaceCasioStyleG7710::Refresh() { } } +void WatchFaceCasioStyleG7710::UpdateWeatherPosition() { + lv_obj_set_hidden(label_day_of_year, false); + lv_obj_set_hidden(label_week_number, false); + lv_obj_set_hidden(label_day_of_week, false); + + lv_obj_set_hidden(weatherIcon, true); + lv_obj_set_hidden(label_temperature_segment, true); + lv_obj_set_hidden(label_temperature, true); + + if (settingsController.GetCasioWeather() == Controllers::Settings::PTSWeather::Off) { + return; + } + + lv_obj_set_hidden(weatherIcon, false); + + switch (settingsController.GetCasioWeatherSegment()) { + case Controllers::Settings::CasioWeatherSegment::DayCounter: + lv_obj_set_hidden(label_day_of_year, true); + + lv_obj_set_hidden(label_temperature_segment, false); + lv_obj_align(weatherIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 110, 30); + lv_obj_align(label_temperature_segment, nullptr, LV_ALIGN_IN_TOP_RIGHT, -5, 30); + break; + case Controllers::Settings::CasioWeatherSegment::WeekNumber: + lv_obj_set_hidden(label_week_number, true); + + lv_obj_set_hidden(label_temperature, false); + lv_obj_align(weatherIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 35, 15); + lv_label_set_align(label_temperature, LV_LABEL_ALIGN_CENTER); + lv_obj_align(label_temperature, nullptr, LV_ALIGN_IN_TOP_LEFT, 20, 40); + break; + case Controllers::Settings::CasioWeatherSegment::DayOfWeek: + lv_obj_set_hidden(label_day_of_week, true); + + lv_obj_set_hidden(label_temperature, false); + lv_obj_align(weatherIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 35, 55); + lv_label_set_align(label_temperature, LV_LABEL_ALIGN_CENTER); + lv_obj_align(label_temperature, nullptr, LV_ALIGN_IN_TOP_LEFT, 20, 80); + break; + } + + DrawWeather(); +} + +void WatchFaceCasioStyleG7710::DrawWeather() { + currentWeather = weatherService.Current(); + + if (currentWeather.IsUpdated()) { + auto optCurrentWeather = currentWeather.Get(); + + if (optCurrentWeather) { + int16_t temp = optCurrentWeather->temperature.Celsius(); + char tempUnit = 'C'; + + if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) { + temp = optCurrentWeather->temperature.Fahrenheit(); + tempUnit = 'F'; + } + + lv_label_set_text_fmt(label_temperature, "%d°%c", temp, tempUnit); + lv_label_set_text_fmt(label_temperature_segment, "%d°%c", temp, tempUnit); + lv_label_set_text(weatherIcon, Symbols::GetSymbol(optCurrentWeather->iconId)); + } else { + lv_label_set_text_static(label_temperature, ""); + lv_label_set_text_static(label_temperature_segment, ""); + lv_label_set_text(weatherIcon, ""); + } + + lv_obj_realign(label_temperature); + lv_obj_realign(label_temperature_segment); + lv_obj_realign(weatherIcon); + } +} + bool WatchFaceCasioStyleG7710::IsAvailable(Pinetime::Controllers::FS& filesystem) { lfs_file file = {}; @@ -433,6 +494,8 @@ bool WatchFaceCasioStyleG7710::OnTouchEvent(Pinetime::Applications::TouchEvents } if ((event == Pinetime::Applications::TouchEvents::LongTap) && lv_obj_get_hidden(btnClose)) { lv_obj_set_hidden(btnWeather, false); + lv_obj_set_hidden(btnSegment, false); + lv_obj_set_hidden(btnClose, false); savedTick = lv_tick_get(); return true; @@ -446,6 +509,8 @@ bool WatchFaceCasioStyleG7710::OnTouchEvent(Pinetime::Applications::TouchEvents void WatchFaceCasioStyleG7710::CloseMenu() { settingsController.SaveSettings(); lv_obj_set_hidden(btnWeather, true); + lv_obj_set_hidden(btnSegment, true); + lv_obj_set_hidden(btnClose, true); } @@ -458,21 +523,42 @@ bool WatchFaceCasioStyleG7710::OnButtonPushed() { return false; } +void WatchFaceCasioStyleG7710::HandleWeatherButton() { + if (lv_obj_get_hidden(weatherIcon)) { + settingsController.SetCasioWeather(Controllers::Settings::PTSWeather::On); + } else { + settingsController.SetCasioWeather(Controllers::Settings::PTSWeather::Off); + } + + UpdateWeatherPosition(); +} + +void WatchFaceCasioStyleG7710::HandleSegmentButton() { + switch (settingsController.GetCasioWeatherSegment()) { + case Controllers::Settings::CasioWeatherSegment::DayCounter: + settingsController.SetCasioWeatherSegment(Controllers::Settings::CasioWeatherSegment::WeekNumber); + break; + case Controllers::Settings::CasioWeatherSegment::WeekNumber: + settingsController.SetCasioWeatherSegment(Controllers::Settings::CasioWeatherSegment::DayOfWeek); + break; + case Controllers::Settings::CasioWeatherSegment::DayOfWeek: + settingsController.SetCasioWeatherSegment(Controllers::Settings::CasioWeatherSegment::DayCounter); + break; + } + + UpdateWeatherPosition(); +} + void WatchFaceCasioStyleG7710::UpdateSelected(lv_obj_t* object, lv_event_t event) { if (event == LV_EVENT_CLICKED) { if (object == btnWeather) { - if (lv_obj_get_hidden(weatherIcon)) { - lv_obj_set_hidden(weatherIcon, false); - lv_obj_set_hidden(label_temperature, false); - lv_obj_set_hidden(label_day_of_year, true); - settingsController.SetCasioWeather(Controllers::Settings::PTSWeather::On); - } else { - lv_obj_set_hidden(weatherIcon, true); - lv_obj_set_hidden(label_temperature, true); - lv_obj_set_hidden(label_day_of_year, false); - settingsController.SetCasioWeather(Controllers::Settings::PTSWeather::Off); - } + HandleWeatherButton(); } + + if (object == btnSegment) { + HandleSegmentButton(); + } + if (object == btnClose) { CloseMenu(); } diff --git a/src/displayapp/screens/WatchFaceCasioStyleG7710.h b/src/displayapp/screens/WatchFaceCasioStyleG7710.h index 1e2e945676..a71777ab0f 100644 --- a/src/displayapp/screens/WatchFaceCasioStyleG7710.h +++ b/src/displayapp/screens/WatchFaceCasioStyleG7710.h @@ -46,6 +46,9 @@ namespace Pinetime { void Refresh() override; + void UpdateWeatherPosition(); + void DrawWeather(); + static bool IsAvailable(Pinetime::Controllers::FS& filesystem); private: @@ -95,9 +98,11 @@ namespace Pinetime { lv_obj_t* notificationIcon; lv_obj_t* line_icons; lv_obj_t* btnWeather; + lv_obj_t* btnSegment; lv_obj_t* btnClose; lv_obj_t* weatherIcon; lv_obj_t* label_temperature; + lv_obj_t* label_temperature_segment; BatteryIcon batteryIcon; @@ -114,8 +119,11 @@ namespace Pinetime { lv_font_t* font_dot40 = nullptr; lv_font_t* font_segment40 = nullptr; lv_font_t* font_segment115 = nullptr; + lv_font_t* font_teko_light = nullptr; void CloseMenu(); + void HandleWeatherButton(); + void HandleSegmentButton(); }; }