From 73fca1fba3ebbd4bc5ce3ac31d343d29c157876f Mon Sep 17 00:00:00 2001 From: sykomaniac Date: Tue, 1 Mar 2022 21:47:12 +0000 Subject: [PATCH 1/6] WIP: Add basic settings page - Add long press settings page and a close button --- src/displayapp/screens/WatchFaceDigital.cpp | 66 +++++++++++++++++++++ src/displayapp/screens/WatchFaceDigital.h | 10 ++++ 2 files changed, 76 insertions(+) diff --git a/src/displayapp/screens/WatchFaceDigital.cpp b/src/displayapp/screens/WatchFaceDigital.cpp index 56155d52a3..1a77099d39 100644 --- a/src/displayapp/screens/WatchFaceDigital.cpp +++ b/src/displayapp/screens/WatchFaceDigital.cpp @@ -15,6 +15,13 @@ #include "components/settings/Settings.h" using namespace Pinetime::Applications::Screens; +namespace { + void event_handler(lv_obj_t* obj, lv_event_t event) { + auto* screen = static_cast(obj->user_data); + screen->UpdateSelected(obj, event); + } +} + WatchFaceDigital::WatchFaceDigital(DisplayApp* app, Controllers::DateTime& dateTimeController, Controllers::Battery& batteryController, @@ -93,6 +100,28 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app, lv_label_set_text_static(stepIcon, Symbols::shoe); lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_LEFT_MID, -5, 0); + btnSet = lv_btn_create(lv_scr_act(), nullptr); + btnSet->user_data = this; + lv_obj_set_height(btnSet, 150); + lv_obj_set_width(btnSet, 150); + lv_obj_align(btnSet, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); + lv_obj_set_style_local_radius(btnSet, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 30); + lv_obj_set_style_local_bg_opa(btnSet, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_50); + lv_obj_set_event_cb(btnSet, event_handler); + lbl_btnSet = lv_label_create(btnSet, nullptr); + lv_obj_set_style_local_text_font(lbl_btnSet, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48); + lv_label_set_text_static(lbl_btnSet, Symbols::settings); + lv_obj_set_hidden(btnSet, true); + + btnClose = lv_btn_create(lv_scr_act(), nullptr); + btnClose->user_data = this; + lv_obj_set_size(btnClose, 60, 60); + lv_obj_align(btnClose, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); + lv_obj_set_style_local_bg_opa(btnClose, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_50); + lv_obj_set_style_local_value_str(btnClose, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "X"); + lv_obj_set_event_cb(btnClose, event_handler); + lv_obj_set_hidden(btnClose, true); + taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); Refresh(); } @@ -212,4 +241,41 @@ void WatchFaceDigital::Refresh() { lv_obj_realign(stepValue); lv_obj_realign(stepIcon); } + + if (!lv_obj_get_hidden(btnSet)) { + if ((savedTick > 0) && (lv_tick_get() - savedTick > 3000)) { + lv_obj_set_hidden(btnSet, true); + savedTick = 0; + } + } +} + +bool WatchFaceDigital::OnTouchEvent(Pinetime::Applications::TouchEvents event) { + if ((event == Pinetime::Applications::TouchEvents::LongTap) && lv_obj_get_hidden(btnClose)) { + lv_obj_set_hidden(btnSet, false); + savedTick = lv_tick_get(); + return true; + } + return false; +} + +void WatchFaceDigital::CloseMenu() { + settingsController.SaveSettings(); + lv_obj_set_hidden(btnClose, true); +} + +void WatchFaceDigital::UpdateSelected(lv_obj_t* object, lv_event_t event) { + auto valueTime = settingsController.GetPTSColorTime(); + auto valueBar = settingsController.GetPTSColorBar(); + auto valueBG = settingsController.GetPTSColorBG(); + + if (event == LV_EVENT_CLICKED) { + if (object == btnClose) { + CloseMenu(); + } + if (object == btnSet) { + lv_obj_set_hidden(btnSet, true); + lv_obj_set_hidden(btnClose, false); + } + } } diff --git a/src/displayapp/screens/WatchFaceDigital.h b/src/displayapp/screens/WatchFaceDigital.h index d33434c07b..17e19c685f 100644 --- a/src/displayapp/screens/WatchFaceDigital.h +++ b/src/displayapp/screens/WatchFaceDigital.h @@ -35,6 +35,9 @@ namespace Pinetime { void Refresh() override; + bool OnTouchEvent(TouchEvents event) override; + void UpdateSelected(lv_obj_t *object, lv_event_t event); + private: uint8_t displayedHour = -1; uint8_t displayedMinute = -1; @@ -68,6 +71,11 @@ namespace Pinetime { lv_obj_t* stepValue; lv_obj_t* notificationIcon; + uint32_t savedTick = 0; + lv_obj_t* btnSet; + lv_obj_t* lbl_btnSet; + lv_obj_t* btnClose; + Controllers::DateTime& dateTimeController; Controllers::Battery& batteryController; Controllers::Ble& bleController; @@ -76,6 +84,8 @@ namespace Pinetime { Controllers::HeartRateController& heartRateController; Controllers::MotionController& motionController; + void CloseMenu(); + lv_task_t* taskRefresh; }; } From f05fd968b2f470d950e9e6631dd22386a4e11bf7 Mon Sep 17 00:00:00 2001 From: sykomaniac Date: Sat, 5 Mar 2022 07:15:58 +0000 Subject: [PATCH 2/6] WIP: add setting values --- src/components/settings/Settings.h | 28 ++++++++++++++++++++ src/displayapp/screens/BatteryIcon.cpp | 36 +++++++++++++++++++++----- src/displayapp/screens/BatteryIcon.h | 3 +++ 3 files changed, 60 insertions(+), 7 deletions(-) diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index 24a826072f..f027dcd5f8 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -17,6 +17,8 @@ namespace Pinetime { RaiseWrist = 2, Shake = 3, }; + enum class BatteryPercentage : u_int8_t { ON, OFF }; + enum class BatteryColor : u_int8_t { ON, OFF }; enum class Colors : uint8_t { White, Silver, @@ -41,6 +43,10 @@ namespace Pinetime { Colors ColorBar = Colors::Teal; Colors ColorBG = Colors::Black; }; + struct DigitalWatchStyle { + BatteryPercentage Percentage = BatteryPercentage::OFF; + BatteryColor Color = BatteryColor::OFF; + }; Settings(Pinetime::Controllers::FS& fs); @@ -94,6 +100,26 @@ namespace Pinetime { return settings.PTS.ColorBG; }; + void SetDWSBatteryPercentageStatus(BatteryPercentage status) { + if (status != settings.DWS.Percentage) { + settingsChanged = true; + } + settings.DWS.Percentage = status; + }; + BatteryPercentage GetDWSBatteryPercentageStatus() const { + return settings.DWS.Percentage; + }; + + void SetDWSBatteryColorStatus(BatteryColor status) { + if (status != settings.DWS.Color) { + settingsChanged = true; + } + settings.DWS.Color = status; + }; + BatteryColor GetDWSBatteryColorStatus() const { + return settings.DWS.Color; + }; + void SetAppMenu(uint8_t menu) { appMenu = menu; }; @@ -227,6 +253,8 @@ namespace Pinetime { PineTimeStyle PTS; + DigitalWatchStyle DWS; + std::bitset<4> wakeUpMode {0}; uint16_t shakeWakeThreshold = 150; Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium; diff --git a/src/displayapp/screens/BatteryIcon.cpp b/src/displayapp/screens/BatteryIcon.cpp index 08aaab70f1..0cc9bb2b56 100644 --- a/src/displayapp/screens/BatteryIcon.cpp +++ b/src/displayapp/screens/BatteryIcon.cpp @@ -1,28 +1,50 @@ #include "displayapp/screens/BatteryIcon.h" #include +#include #include "displayapp/screens/Symbols.h" using namespace Pinetime::Applications::Screens; const char* BatteryIcon::GetBatteryIcon(uint8_t batteryPercent) { - if (batteryPercent > 87) + if (batteryPercent > 87) { return Symbols::batteryFull; - if (batteryPercent > 62) + } + if (batteryPercent > 62) { return Symbols::batteryThreeQuarter; - if (batteryPercent > 37) + } + if (batteryPercent > 37) { return Symbols::batteryHalf; - if (batteryPercent > 12) + } + if (batteryPercent > 12) { return Symbols::batteryOneQuarter; + } return Symbols::batteryEmpty; } +const lv_color_t BatteryIcon::GetBatteryColor(uint8_t batteryPercent) { + if (batteryPercent > 75) { + return LV_COLOR_GREEN; + } + if (batteryPercent > 50) { + return LV_COLOR_YELLOW; + } + if (batteryPercent > 25) { + return LV_COLOR_ORANGE; + } + return LV_COLOR_RED; +} + +const lv_color_t BatteryIcon::GetDefaultBatteryColor() { + return LV_COLOR_WHITE; +} + const char* BatteryIcon::GetUnknownIcon() { return Symbols::batteryEmpty; } const char* BatteryIcon::GetPlugIcon(bool isCharging) { - if (isCharging) + if (isCharging) { return Symbols::plug; - else - return ""; + } + return ""; } diff --git a/src/displayapp/screens/BatteryIcon.h b/src/displayapp/screens/BatteryIcon.h index bec2e4e059..d0a9a5aa0e 100644 --- a/src/displayapp/screens/BatteryIcon.h +++ b/src/displayapp/screens/BatteryIcon.h @@ -1,5 +1,6 @@ #pragma once #include +#include namespace Pinetime { namespace Applications { @@ -8,6 +9,8 @@ namespace Pinetime { public: static const char* GetUnknownIcon(); static const char* GetBatteryIcon(uint8_t batteryPercent); + static const lv_color_t GetBatteryColor(uint8_t batteryPercent); + static const lv_color_t GetDefaultBatteryColor(); static const char* GetPlugIcon(bool isCharging); }; } From f083f752908dc9b8f8ddc521edadfe6888af310e Mon Sep 17 00:00:00 2001 From: sykomaniac Date: Wed, 9 Mar 2022 12:13:49 +0000 Subject: [PATCH 3/6] WIP: Updates to follow settings and adjust display accordingly --- src/displayapp/screens/BatteryIcon.cpp | 5 ++++- src/displayapp/screens/BatteryIcon.h | 2 +- src/displayapp/screens/WatchFaceDigital.cpp | 21 +++++++++++++++++---- src/displayapp/screens/WatchFaceDigital.h | 1 + 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/displayapp/screens/BatteryIcon.cpp b/src/displayapp/screens/BatteryIcon.cpp index 0cc9bb2b56..ecffc9408f 100644 --- a/src/displayapp/screens/BatteryIcon.cpp +++ b/src/displayapp/screens/BatteryIcon.cpp @@ -34,7 +34,10 @@ const lv_color_t BatteryIcon::GetBatteryColor(uint8_t batteryPercent) { return LV_COLOR_RED; } -const lv_color_t BatteryIcon::GetDefaultBatteryColor() { +const lv_color_t BatteryIcon::GetDefaultBatteryColor(uint8_t batteryPercent) { + if (batteryPercent == 100) { + return LV_COLOR_GREEN; + } return LV_COLOR_WHITE; } diff --git a/src/displayapp/screens/BatteryIcon.h b/src/displayapp/screens/BatteryIcon.h index d0a9a5aa0e..c46b7904aa 100644 --- a/src/displayapp/screens/BatteryIcon.h +++ b/src/displayapp/screens/BatteryIcon.h @@ -10,7 +10,7 @@ namespace Pinetime { static const char* GetUnknownIcon(); static const char* GetBatteryIcon(uint8_t batteryPercent); static const lv_color_t GetBatteryColor(uint8_t batteryPercent); - static const lv_color_t GetDefaultBatteryColor(); + static const lv_color_t GetDefaultBatteryColor(uint8_t batteryPercent); static const char* GetPlugIcon(bool isCharging); }; } diff --git a/src/displayapp/screens/WatchFaceDigital.cpp b/src/displayapp/screens/WatchFaceDigital.cpp index 1a77099d39..59923cafe3 100644 --- a/src/displayapp/screens/WatchFaceDigital.cpp +++ b/src/displayapp/screens/WatchFaceDigital.cpp @@ -45,10 +45,14 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app, lv_label_set_text_static(batteryIcon, Symbols::batteryFull); lv_obj_align(batteryIcon, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 0, 0); + batteryValue = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_text_static(batteryValue, ""); + lv_obj_align(batteryValue, batteryIcon, LV_ALIGN_OUT_LEFT_MID, -5, 0); + batteryPlug = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(batteryPlug, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFF0000)); lv_label_set_text_static(batteryPlug, Symbols::plug); - lv_obj_align(batteryPlug, batteryIcon, LV_ALIGN_OUT_LEFT_MID, -5, 0); + lv_obj_align(batteryPlug, batteryValue, LV_ALIGN_OUT_LEFT_MID, -5, 0); bleIcon = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(bleIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x0082FC)); @@ -140,11 +144,19 @@ void WatchFaceDigital::Refresh() { batteryPercentRemaining = batteryController.PercentRemaining(); if (batteryPercentRemaining.IsUpdated()) { auto batteryPercent = batteryPercentRemaining.Get(); - if (batteryPercent == 100) { - lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN); + + if (settingsController.GetDWSBatteryColorStatus() == Controllers::Settings::BatteryColor::ON) { + lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, BatteryIcon::GetBatteryColor(batteryPercent)); } else { - lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); + lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, BatteryIcon::GetDefaultBatteryColor(batteryPercent)); } + + if (settingsController.GetDWSBatteryPercentageStatus() == Controllers::Settings::BatteryPercentage::ON) { + lv_label_set_text_fmt(batteryValue, "%lu%%", batteryPercent); + } else { + lv_label_set_text_static(batteryValue, ""); + } + lv_label_set_text_static(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent)); } @@ -154,6 +166,7 @@ void WatchFaceDigital::Refresh() { lv_label_set_text(bleIcon, BleIcon::GetIcon(bleRadioEnabled.Get(), bleState.Get())); } lv_obj_realign(batteryIcon); + lv_obj_realign(batteryValue); lv_obj_realign(batteryPlug); lv_obj_realign(bleIcon); diff --git a/src/displayapp/screens/WatchFaceDigital.h b/src/displayapp/screens/WatchFaceDigital.h index 17e19c685f..ad4ff91dc4 100644 --- a/src/displayapp/screens/WatchFaceDigital.h +++ b/src/displayapp/screens/WatchFaceDigital.h @@ -64,6 +64,7 @@ namespace Pinetime { lv_obj_t* backgroundLabel; lv_obj_t* batteryIcon; lv_obj_t* bleIcon; + lv_obj_t* batteryValue; lv_obj_t* batteryPlug; lv_obj_t* heartbeatIcon; lv_obj_t* heartbeatValue; From fe8ac6329286a29999411f406ebe52a32b576dac Mon Sep 17 00:00:00 2001 From: sykomaniac Date: Wed, 9 Mar 2022 14:24:05 +0000 Subject: [PATCH 4/6] WIP: Add settings entry to configure percentage display --- src/displayapp/screens/WatchFaceDigital.cpp | 69 +++++++++++++++++++-- src/displayapp/screens/WatchFaceDigital.h | 5 ++ 2 files changed, 68 insertions(+), 6 deletions(-) diff --git a/src/displayapp/screens/WatchFaceDigital.cpp b/src/displayapp/screens/WatchFaceDigital.cpp index 59923cafe3..9b217fee32 100644 --- a/src/displayapp/screens/WatchFaceDigital.cpp +++ b/src/displayapp/screens/WatchFaceDigital.cpp @@ -117,6 +117,23 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app, lv_label_set_text_static(lbl_btnSet, Symbols::settings); lv_obj_set_hidden(btnSet, true); + settingsTitle = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_text_static(settingsTitle, "Display Settings"); + lv_label_set_align(settingsTitle, LV_LABEL_ALIGN_CENTER); + lv_obj_align(settingsTitle, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 15); + lv_obj_set_hidden(settingsTitle, true); + + optionsTotal = 0; + cbOption[optionsTotal] = lv_checkbox_create(lv_scr_act(), nullptr); + lv_checkbox_set_text_static(cbOption[optionsTotal], " Show Percent"); + cbOption[optionsTotal]->user_data = this; + lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); + if (settingsController.GetDWSBatteryPercentageStatus() == Controllers::Settings::BatteryPercentage::ON) { + lv_checkbox_set_checked(cbOption[optionsTotal], true); + } + lv_obj_set_hidden(cbOption[optionsTotal], true); + optionsTotal++; + btnClose = lv_btn_create(lv_scr_act(), nullptr); btnClose->user_data = this; lv_obj_set_size(btnClose, 60, 60); @@ -124,7 +141,7 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app, lv_obj_set_style_local_bg_opa(btnClose, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_50); lv_obj_set_style_local_value_str(btnClose, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "X"); lv_obj_set_event_cb(btnClose, event_handler); - lv_obj_set_hidden(btnClose, true); + lv_obj_set_hidden(settingsTitle, true); taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); Refresh(); @@ -272,15 +289,55 @@ bool WatchFaceDigital::OnTouchEvent(Pinetime::Applications::TouchEvents event) { return false; } +bool WatchFaceDigital::OnButtonPushed() { + if (!lv_obj_get_hidden(btnClose)) { + CloseMenu(); + return true; + } + return false; +} + void WatchFaceDigital::CloseMenu() { settingsController.SaveSettings(); - lv_obj_set_hidden(btnClose, true); + HideSettingsMenuItems(true); +} + +void WatchFaceDigital::HideSettingsMenuItems(bool visible) { + lv_obj_set_hidden(btnClose, visible); + lv_obj_set_hidden(settingsTitle, visible); + for (int index = 0; index < optionsTotal; ++index) { + lv_obj_set_hidden(cbOption[index], visible); + } } void WatchFaceDigital::UpdateSelected(lv_obj_t* object, lv_event_t event) { - auto valueTime = settingsController.GetPTSColorTime(); - auto valueBar = settingsController.GetPTSColorBar(); - auto valueBG = settingsController.GetPTSColorBG(); + if (event == LV_EVENT_VALUE_CHANGED) { + int index = 0; + for (; index < optionsTotal; ++index) { + if (cbOption[index] == object) { + break; + } + } + + if (index == 0) { + if (settingsController.GetDWSBatteryPercentageStatus() == Controllers::Settings::BatteryPercentage::ON) { + settingsController.SetDWSBatteryPercentageStatus(Controllers::Settings::BatteryPercentage::OFF); + lv_checkbox_set_checked(cbOption[index], false); + } else { + settingsController.SetDWSBatteryPercentageStatus(Controllers::Settings::BatteryPercentage::ON); + lv_checkbox_set_checked(cbOption[index], true); + } + }; + if (index == 1) { + if (settingsController.GetDWSBatteryColorStatus() == Controllers::Settings::BatteryColor::ON) { + settingsController.SetDWSBatteryColorStatus(Controllers::Settings::BatteryColor::OFF); + lv_checkbox_set_checked(cbOption[index], false); + } else { + settingsController.SetDWSBatteryColorStatus(Controllers::Settings::BatteryColor::ON); + lv_checkbox_set_checked(cbOption[index], true); + } + }; + } if (event == LV_EVENT_CLICKED) { if (object == btnClose) { @@ -288,7 +345,7 @@ void WatchFaceDigital::UpdateSelected(lv_obj_t* object, lv_event_t event) { } if (object == btnSet) { lv_obj_set_hidden(btnSet, true); - lv_obj_set_hidden(btnClose, false); + HideSettingsMenuItems(false); } } } diff --git a/src/displayapp/screens/WatchFaceDigital.h b/src/displayapp/screens/WatchFaceDigital.h index ad4ff91dc4..820abdfff2 100644 --- a/src/displayapp/screens/WatchFaceDigital.h +++ b/src/displayapp/screens/WatchFaceDigital.h @@ -36,6 +36,7 @@ namespace Pinetime { void Refresh() override; bool OnTouchEvent(TouchEvents event) override; + bool OnButtonPushed() override; void UpdateSelected(lv_obj_t *object, lv_event_t event); private: @@ -73,6 +74,9 @@ namespace Pinetime { lv_obj_t* notificationIcon; uint32_t savedTick = 0; + uint8_t optionsTotal; + lv_obj_t* settingsTitle; + lv_obj_t* cbOption[1]; lv_obj_t* btnSet; lv_obj_t* lbl_btnSet; lv_obj_t* btnClose; @@ -86,6 +90,7 @@ namespace Pinetime { Controllers::MotionController& motionController; void CloseMenu(); + void HideSettingsMenuItems(bool visible); lv_task_t* taskRefresh; }; From d41512372967ff2837bfb060b66c7668325e1220 Mon Sep 17 00:00:00 2001 From: sykomaniac Date: Thu, 10 Mar 2022 22:28:42 +0000 Subject: [PATCH 5/6] WIP: Add settings page --- src/displayapp/screens/WatchFaceDigital.cpp | 48 +++++++++++++++++---- src/displayapp/screens/WatchFaceDigital.h | 3 +- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/displayapp/screens/WatchFaceDigital.cpp b/src/displayapp/screens/WatchFaceDigital.cpp index 9b217fee32..94098fc2de 100644 --- a/src/displayapp/screens/WatchFaceDigital.cpp +++ b/src/displayapp/screens/WatchFaceDigital.cpp @@ -104,11 +104,21 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app, lv_label_set_text_static(stepIcon, Symbols::shoe); lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_LEFT_MID, -5, 0); - btnSet = lv_btn_create(lv_scr_act(), nullptr); + container1 = lv_cont_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_bg_color(container1, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); + lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); + lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10); + lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5); + lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); + lv_obj_set_pos(container1, 10, 10); + lv_obj_set_width(container1, LV_HOR_RES - 20); + lv_obj_set_height(container1, LV_VER_RES - 20); + + btnSet = lv_btn_create(container1, nullptr); btnSet->user_data = this; lv_obj_set_height(btnSet, 150); lv_obj_set_width(btnSet, 150); - lv_obj_align(btnSet, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); + lv_obj_align(btnSet, container1, LV_ALIGN_CENTER, 0, 15); lv_obj_set_style_local_radius(btnSet, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 30); lv_obj_set_style_local_bg_opa(btnSet, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_50); lv_obj_set_event_cb(btnSet, event_handler); @@ -117,31 +127,42 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app, lv_label_set_text_static(lbl_btnSet, Symbols::settings); lv_obj_set_hidden(btnSet, true); - settingsTitle = lv_label_create(lv_scr_act(), nullptr); + settingsTitle = lv_label_create(container1, nullptr); lv_label_set_text_static(settingsTitle, "Display Settings"); lv_label_set_align(settingsTitle, LV_LABEL_ALIGN_CENTER); - lv_obj_align(settingsTitle, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 15); + lv_obj_align(settingsTitle, container1, LV_ALIGN_IN_TOP_MID, 0, 15); lv_obj_set_hidden(settingsTitle, true); optionsTotal = 0; - cbOption[optionsTotal] = lv_checkbox_create(lv_scr_act(), nullptr); + cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); lv_checkbox_set_text_static(cbOption[optionsTotal], " Show Percent"); cbOption[optionsTotal]->user_data = this; lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); if (settingsController.GetDWSBatteryPercentageStatus() == Controllers::Settings::BatteryPercentage::ON) { lv_checkbox_set_checked(cbOption[optionsTotal], true); } + lv_obj_align(cbOption[optionsTotal], settingsTitle, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 5); lv_obj_set_hidden(cbOption[optionsTotal], true); optionsTotal++; - btnClose = lv_btn_create(lv_scr_act(), nullptr); + cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); + lv_checkbox_set_text_static(cbOption[optionsTotal], " Color Icon"); + cbOption[optionsTotal]->user_data = this; + lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); + if (settingsController.GetDWSBatteryColorStatus() == Controllers::Settings::BatteryColor::ON) { + lv_checkbox_set_checked(cbOption[optionsTotal], true); + } + lv_obj_align(cbOption[optionsTotal], cbOption[optionsTotal-1], LV_ALIGN_OUT_BOTTOM_LEFT, 0, 5); + lv_obj_set_hidden(cbOption[optionsTotal], true); + optionsTotal++; + + btnClose = lv_btn_create(container1, nullptr); btnClose->user_data = this; lv_obj_set_size(btnClose, 60, 60); - lv_obj_align(btnClose, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); - lv_obj_set_style_local_bg_opa(btnClose, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_50); + lv_obj_align(btnClose, container1, LV_ALIGN_IN_BOTTOM_MID, 0, -5); lv_obj_set_style_local_value_str(btnClose, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "X"); lv_obj_set_event_cb(btnClose, event_handler); - lv_obj_set_hidden(settingsTitle, true); + lv_obj_set_hidden(btnClose, true); taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); Refresh(); @@ -308,6 +329,7 @@ void WatchFaceDigital::HideSettingsMenuItems(bool visible) { for (int index = 0; index < optionsTotal; ++index) { lv_obj_set_hidden(cbOption[index], visible); } + lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); } void WatchFaceDigital::UpdateSelected(lv_obj_t* object, lv_event_t event) { @@ -319,22 +341,29 @@ void WatchFaceDigital::UpdateSelected(lv_obj_t* object, lv_event_t event) { } } + batteryPercentRemaining = batteryController.PercentRemaining(); + auto batteryPercent = batteryPercentRemaining.Get(); + if (index == 0) { if (settingsController.GetDWSBatteryPercentageStatus() == Controllers::Settings::BatteryPercentage::ON) { settingsController.SetDWSBatteryPercentageStatus(Controllers::Settings::BatteryPercentage::OFF); lv_checkbox_set_checked(cbOption[index], false); + lv_label_set_text_static(batteryValue, ""); } else { settingsController.SetDWSBatteryPercentageStatus(Controllers::Settings::BatteryPercentage::ON); lv_checkbox_set_checked(cbOption[index], true); + lv_label_set_text_fmt(batteryValue, "%lu%%", batteryPercent); } }; if (index == 1) { if (settingsController.GetDWSBatteryColorStatus() == Controllers::Settings::BatteryColor::ON) { settingsController.SetDWSBatteryColorStatus(Controllers::Settings::BatteryColor::OFF); lv_checkbox_set_checked(cbOption[index], false); + lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, BatteryIcon::GetDefaultBatteryColor(batteryPercent)); } else { settingsController.SetDWSBatteryColorStatus(Controllers::Settings::BatteryColor::ON); lv_checkbox_set_checked(cbOption[index], true); + lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, BatteryIcon::GetBatteryColor(batteryPercent)); } }; } @@ -346,6 +375,7 @@ void WatchFaceDigital::UpdateSelected(lv_obj_t* object, lv_event_t event) { if (object == btnSet) { lv_obj_set_hidden(btnSet, true); HideSettingsMenuItems(false); + lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_50); } } } diff --git a/src/displayapp/screens/WatchFaceDigital.h b/src/displayapp/screens/WatchFaceDigital.h index 820abdfff2..fcc2832401 100644 --- a/src/displayapp/screens/WatchFaceDigital.h +++ b/src/displayapp/screens/WatchFaceDigital.h @@ -75,8 +75,9 @@ namespace Pinetime { uint32_t savedTick = 0; uint8_t optionsTotal; + lv_obj_t* container1; lv_obj_t* settingsTitle; - lv_obj_t* cbOption[1]; + lv_obj_t* cbOption[2]; lv_obj_t* btnSet; lv_obj_t* lbl_btnSet; lv_obj_t* btnClose; From b248476ae136c82f4f236662b8c787ee26d167c3 Mon Sep 17 00:00:00 2001 From: sykomaniac Date: Wed, 16 Mar 2022 11:59:40 +0000 Subject: [PATCH 6/6] Address review comments - Remove extra indentation - Fix settings icon alignment - Increment settings version number --- src/components/settings/Settings.h | 2 +- src/displayapp/screens/WatchFaceDigital.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index f027dcd5f8..0c876b2a1d 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -239,7 +239,7 @@ namespace Pinetime { private: Pinetime::Controllers::FS& fs; - static constexpr uint32_t settingsVersion = 0x0003; + static constexpr uint32_t settingsVersion = 0x0004; struct SettingsData { uint32_t version = settingsVersion; uint32_t stepsGoal = 10000; diff --git a/src/displayapp/screens/WatchFaceDigital.cpp b/src/displayapp/screens/WatchFaceDigital.cpp index 8a39eb1733..1bbdb15e49 100644 --- a/src/displayapp/screens/WatchFaceDigital.cpp +++ b/src/displayapp/screens/WatchFaceDigital.cpp @@ -117,7 +117,7 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app, btnSet->user_data = this; lv_obj_set_height(btnSet, 150); lv_obj_set_width(btnSet, 150); - lv_obj_align(btnSet, container1, LV_ALIGN_CENTER, 0, 15); + lv_obj_align(btnSet, container1, LV_ALIGN_CENTER, 0, 0); lv_obj_set_style_local_radius(btnSet, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 30); lv_obj_set_style_local_bg_opa(btnSet, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_50); lv_obj_set_event_cb(btnSet, event_handler); @@ -183,9 +183,9 @@ void WatchFaceDigital::Refresh() { auto batteryPercent = batteryPercentRemaining.Get(); if (settingsController.GetDWSBatteryColorStatus() == Controllers::Settings::BatteryColor::ON) { - lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, BatteryIcon::GetBatteryColor(batteryPercent)); + lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, BatteryIcon::GetBatteryColor(batteryPercent)); } else { - lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, BatteryIcon::GetDefaultBatteryColor(batteryPercent)); + lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, BatteryIcon::GetDefaultBatteryColor(batteryPercent)); } if (settingsController.GetDWSBatteryPercentageStatus() == Controllers::Settings::BatteryPercentage::ON) {