From f1cf3121ae3cbcc86f3222abb1f1f4c1133f5fbe Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Sat, 19 Jun 2021 16:48:19 +0300 Subject: [PATCH 1/4] New checkboxes look and less duplicate code --- src/CMakeLists.txt | 1 + src/displayapp/screens/CheckBoxes.cpp | 93 +++++++++++++ src/displayapp/screens/CheckBoxes.h | 27 ++++ .../screens/settings/SettingDisplay.cpp | 124 +++++------------- .../screens/settings/SettingDisplay.h | 18 ++- .../screens/settings/SettingTimeFormat.cpp | 82 +++--------- .../screens/settings/SettingTimeFormat.h | 15 ++- .../screens/settings/SettingWakeUp.cpp | 122 +++++------------ .../screens/settings/SettingWakeUp.h | 17 ++- .../screens/settings/SettingWatchFace.cpp | 79 +++-------- .../screens/settings/SettingWatchFace.h | 15 ++- 11 files changed, 259 insertions(+), 334 deletions(-) create mode 100644 src/displayapp/screens/CheckBoxes.cpp create mode 100644 src/displayapp/screens/CheckBoxes.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7721d6b814..a0adfbf364 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -409,6 +409,7 @@ list(APPEND SOURCE_FILES displayapp/screens/BatteryInfo.cpp displayapp/screens/Steps.cpp displayapp/screens/Timer.cpp + displayapp/screens/CheckBoxes.cpp ## Settings displayapp/screens/settings/QuickSettings.cpp diff --git a/src/displayapp/screens/CheckBoxes.cpp b/src/displayapp/screens/CheckBoxes.cpp new file mode 100644 index 0000000000..3475d14225 --- /dev/null +++ b/src/displayapp/screens/CheckBoxes.cpp @@ -0,0 +1,93 @@ +#include "CheckBoxes.h" +#include +#include "displayapp/DisplayApp.h" +#include "displayapp/screens/Screen.h" +#include "displayapp/screens/Symbols.h" + +using namespace Pinetime::Applications::Screens; + +namespace { + static void event_handler(lv_obj_t* obj, lv_event_t event) { + CheckBoxes* screen = static_cast(obj->user_data); + screen->UpdateSelected(obj, event); + } +} + +CheckBoxes::CheckBoxes(const char* symbol, const char* titleText, Options *options, DisplayApp* app) : Screen(app), options {options} { + + lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr); + + 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, 0); + lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 4); + lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); + + lv_obj_set_pos(container1, 0, 40); + lv_obj_set_width(container1, LV_HOR_RES); + lv_obj_set_height(container1, LV_VER_RES - 40); + lv_cont_set_layout(container1, LV_LAYOUT_GRID); + + lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_text(title, titleText); + lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); + lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 5); + + lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); + lv_label_set_text(icon, symbol); + lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER); + lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); + + for (optionsTotal = 0; optionsTotal < 6; optionsTotal++) { + if (strcmp(options[optionsTotal].title, "") == 0) { + break; + } + } + + lv_style_init(&buttonStyle); + lv_style_set_bg_color(&buttonStyle, LV_STATE_DEFAULT, lv_color_hex(0x111111)); + lv_style_set_bg_opa(&buttonStyle, LV_STATE_CHECKED, LV_OPA_30); + lv_style_set_bg_color(&buttonStyle, LV_STATE_CHECKED, LV_COLOR_AQUA); + if (optionsTotal <= 4) { + lv_style_set_radius(&buttonStyle, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); + } + + for (uint8_t i = 0; i < optionsTotal; i++) { + buttons[i] = lv_btn_create(container1, nullptr); + lv_obj_set_style_local_value_str(buttons[i], LV_BTN_PART_MAIN, LV_STATE_DEFAULT, options[i].title); + lv_obj_add_style(buttons[i], LV_BTN_PART_MAIN, &buttonStyle); + if (optionsTotal <= 4) { + lv_obj_set_size(buttons[i], LV_HOR_RES, 47); + } else { + lv_obj_set_size(buttons[i], 117, 64); + } + if (options[i].state == true) { + lv_obj_add_state(buttons[i], LV_STATE_CHECKED); + } + buttons[i]->user_data = this; + lv_obj_set_event_cb(buttons[i], event_handler); + } +} + +CheckBoxes::~CheckBoxes() { + lv_obj_clean(lv_scr_act()); +} + +bool CheckBoxes::Refresh() { + return running; +} + +void CheckBoxes::UpdateSelected(lv_obj_t* object, lv_event_t event) { + if (event != LV_EVENT_CLICKED) { + return; + } + for (uint8_t i = 0; i < optionsTotal; i++) { + if (object == buttons[i]) { + lv_obj_add_state(buttons[i], LV_STATE_CHECKED); + options[i].state = true; + } else { + lv_obj_clear_state(buttons[i], LV_STATE_CHECKED); + options[i].state = false; + } + } +} diff --git a/src/displayapp/screens/CheckBoxes.h b/src/displayapp/screens/CheckBoxes.h new file mode 100644 index 0000000000..9c95180c88 --- /dev/null +++ b/src/displayapp/screens/CheckBoxes.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include +#include "displayapp/screens/Screen.h" + +namespace Pinetime::Applications::Screens { + class CheckBoxes : public Screen { + public: + struct Options { + bool state; + const char* title; + }; + CheckBoxes(const char* symbol, const char* titleText, Options *options, DisplayApp* app); + ~CheckBoxes() override; + + bool Refresh() override; + void UpdateSelected(lv_obj_t* object, lv_event_t event); + + private: + struct Options *options; + + uint8_t optionsTotal; + lv_obj_t* buttons[6]; + lv_style_t buttonStyle; + }; +} diff --git a/src/displayapp/screens/settings/SettingDisplay.cpp b/src/displayapp/screens/settings/SettingDisplay.cpp index 4954185df3..90345619cc 100644 --- a/src/displayapp/screens/settings/SettingDisplay.cpp +++ b/src/displayapp/screens/settings/SettingDisplay.cpp @@ -7,107 +7,47 @@ using namespace Pinetime::Applications::Screens; -namespace { - static void event_handler(lv_obj_t* obj, lv_event_t event) { - SettingDisplay* screen = static_cast(obj->user_data); - screen->UpdateSelected(obj, event); - } -} - SettingDisplay::SettingDisplay(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController) - : Screen(app), settingsController {settingsController} { - - lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr); - - 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, 60); - lv_obj_set_width(container1, LV_HOR_RES - 20); - lv_obj_set_height(container1, LV_VER_RES - 50); - lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); - - lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_text_static(title, "Display timeout"); - lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); - lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 10, 15); - - lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); - lv_label_set_text_static(icon, Symbols::sun); - lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER); - lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); + : Screen(app), settingsController {settingsController}, screen {[this, &settingsController]() { + return CreateScreen(); + }()} { +} - optionsTotal = 0; - cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text_static(cbOption[optionsTotal], " 5 seconds"); - cbOption[optionsTotal]->user_data = this; - lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); - if (settingsController.GetScreenTimeOut() == 5000) { - lv_checkbox_set_checked(cbOption[optionsTotal], true); - } - optionsTotal++; - cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text_static(cbOption[optionsTotal], " 15 seconds"); - cbOption[optionsTotal]->user_data = this; - lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); - if (settingsController.GetScreenTimeOut() == 15000) { - lv_checkbox_set_checked(cbOption[optionsTotal], true); - } - optionsTotal++; - cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text_static(cbOption[optionsTotal], " 20 seconds"); - cbOption[optionsTotal]->user_data = this; - lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); - if (settingsController.GetScreenTimeOut() == 20000) { - lv_checkbox_set_checked(cbOption[optionsTotal], true); +std::unique_ptr SettingDisplay::CreateScreen() { + switch (settingsController.GetScreenTimeOut()) { + case 5000: + options[0].state = true; + break; + case 10000: + options[1].state = true; + break; + case 15000: + options[2].state = true; + break; + case 20000: + options[3].state = true; + break; + case 25000: + options[4].state = true; + break; + case 30000: + options[5].state = true; + break; } - optionsTotal++; - cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text_static(cbOption[optionsTotal], " 30 seconds"); - cbOption[optionsTotal]->user_data = this; - lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); - if (settingsController.GetScreenTimeOut() == 30000) { - lv_checkbox_set_checked(cbOption[optionsTotal], true); - } - optionsTotal++; + + return std::make_unique(Symbols::sun, "Display timeout", options, app); } SettingDisplay::~SettingDisplay() { + for (uint8_t i = 0; i < 6; i++) { + if (options[i].state == true) { + settingsController.SetScreenTimeOut((i + 1) * 5000); + } + } lv_obj_clean(lv_scr_act()); settingsController.SaveSettings(); } bool SettingDisplay::Refresh() { - return running; + return screen->Refresh(); } - -void SettingDisplay::UpdateSelected(lv_obj_t* object, lv_event_t event) { - if (event == LV_EVENT_VALUE_CHANGED) { - for (int i = 0; i < optionsTotal; i++) { - if (object == cbOption[i]) { - lv_checkbox_set_checked(cbOption[i], true); - - if (i == 0) { - settingsController.SetScreenTimeOut(5000); - }; - if (i == 1) { - settingsController.SetScreenTimeOut(15000); - }; - if (i == 2) { - settingsController.SetScreenTimeOut(20000); - }; - if (i == 3) { - settingsController.SetScreenTimeOut(30000); - }; - - app->PushMessage(Applications::Display::Messages::UpdateTimeOut); - - } else { - lv_checkbox_set_checked(cbOption[i], false); - } - } - } -} \ No newline at end of file diff --git a/src/displayapp/screens/settings/SettingDisplay.h b/src/displayapp/screens/settings/SettingDisplay.h index b8ed87ec60..9c4a9452ff 100644 --- a/src/displayapp/screens/settings/SettingDisplay.h +++ b/src/displayapp/screens/settings/SettingDisplay.h @@ -2,26 +2,34 @@ #include #include +#include #include "components/settings/Settings.h" #include "displayapp/screens/Screen.h" +#include "displayapp/screens/CheckBoxes.h" namespace Pinetime { - namespace Applications { namespace Screens { - class SettingDisplay : public Screen { public: SettingDisplay(DisplayApp* app, Pinetime::Controllers::Settings& settingsController); ~SettingDisplay() override; bool Refresh() override; - void UpdateSelected(lv_obj_t* object, lv_event_t event); private: + CheckBoxes::Options options[6] = { + {false, "5s"}, + {false, "10s"}, + {false, "15s"}, + {false, "20s"}, + {false, "25s"}, + {false, "30s"}, + }; + Controllers::Settings& settingsController; - uint8_t optionsTotal; - lv_obj_t* cbOption[4]; + std::unique_ptr screen; + std::unique_ptr CreateScreen(); }; } } diff --git a/src/displayapp/screens/settings/SettingTimeFormat.cpp b/src/displayapp/screens/settings/SettingTimeFormat.cpp index 031a2a72a3..df9043d10a 100644 --- a/src/displayapp/screens/settings/SettingTimeFormat.cpp +++ b/src/displayapp/screens/settings/SettingTimeFormat.cpp @@ -6,84 +6,32 @@ using namespace Pinetime::Applications::Screens; -namespace { - static void event_handler(lv_obj_t* obj, lv_event_t event) { - SettingTimeFormat* screen = static_cast(obj->user_data); - screen->UpdateSelected(obj, event); - } -} - SettingTimeFormat::SettingTimeFormat(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController) - : Screen(app), settingsController {settingsController} { - - lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr); - - 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, 60); - lv_obj_set_width(container1, LV_HOR_RES - 20); - lv_obj_set_height(container1, LV_VER_RES - 50); - lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); - - lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_text_static(title, "Time format"); - lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); - lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 15); - - lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); - lv_label_set_text_static(icon, Symbols::clock); - lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER); - lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); + : Screen(app), settingsController {settingsController}, screen {[this, &settingsController]() { + return CreateScreen(); + }()} { +} - optionsTotal = 0; - cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text_static(cbOption[optionsTotal], " 12-hour"); - cbOption[optionsTotal]->user_data = this; - lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); +std::unique_ptr SettingTimeFormat::CreateScreen() { if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) { - lv_checkbox_set_checked(cbOption[optionsTotal], true); + options[0].state = true; + } else { + options[1].state = true; } - optionsTotal++; - cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text_static(cbOption[optionsTotal], " 24-hour"); - cbOption[optionsTotal]->user_data = this; - lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); - if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) { - lv_checkbox_set_checked(cbOption[optionsTotal], true); - } - optionsTotal++; + return std::make_unique(Symbols::clock, "Time format", options, app); } SettingTimeFormat::~SettingTimeFormat() { + if (options[0].state == true) { + settingsController.SetClockType(Controllers::Settings::ClockType::H12); + } else { + settingsController.SetClockType(Controllers::Settings::ClockType::H24); + } lv_obj_clean(lv_scr_act()); settingsController.SaveSettings(); } bool SettingTimeFormat::Refresh() { - return running; + return screen->Refresh(); } - -void SettingTimeFormat::UpdateSelected(lv_obj_t* object, lv_event_t event) { - if (event == LV_EVENT_VALUE_CHANGED) { - for (int i = 0; i < optionsTotal; i++) { - if (object == cbOption[i]) { - lv_checkbox_set_checked(cbOption[i], true); - - if (i == 0) { - settingsController.SetClockType(Controllers::Settings::ClockType::H12); - }; - if (i == 1) { - settingsController.SetClockType(Controllers::Settings::ClockType::H24); - }; - - } else { - lv_checkbox_set_checked(cbOption[i], false); - } - } - } -} \ No newline at end of file diff --git a/src/displayapp/screens/settings/SettingTimeFormat.h b/src/displayapp/screens/settings/SettingTimeFormat.h index 9203b45be8..898c0c60b2 100644 --- a/src/displayapp/screens/settings/SettingTimeFormat.h +++ b/src/displayapp/screens/settings/SettingTimeFormat.h @@ -2,26 +2,31 @@ #include #include +#include #include "components/settings/Settings.h" #include "displayapp/screens/Screen.h" +#include "displayapp/screens/CheckBoxes.h" namespace Pinetime { - namespace Applications { namespace Screens { - class SettingTimeFormat : public Screen { public: SettingTimeFormat(DisplayApp* app, Pinetime::Controllers::Settings& settingsController); ~SettingTimeFormat() override; bool Refresh() override; - void UpdateSelected(lv_obj_t* object, lv_event_t event); private: + CheckBoxes::Options options[3] = { + {false, "12-hour"}, + {false, "24-hour"}, + {false, ""}, + }; + Controllers::Settings& settingsController; - uint8_t optionsTotal; - lv_obj_t* cbOption[2]; + std::unique_ptr screen; + std::unique_ptr CreateScreen(); }; } } diff --git a/src/displayapp/screens/settings/SettingWakeUp.cpp b/src/displayapp/screens/settings/SettingWakeUp.cpp index 89f0c09832..c41236eea0 100644 --- a/src/displayapp/screens/settings/SettingWakeUp.cpp +++ b/src/displayapp/screens/settings/SettingWakeUp.cpp @@ -3,109 +3,49 @@ #include "displayapp/DisplayApp.h" #include "displayapp/screens/Screen.h" #include "displayapp/screens/Symbols.h" -#include "components/settings/Settings.h" using namespace Pinetime::Applications::Screens; -namespace { - static void event_handler(lv_obj_t* obj, lv_event_t event) { - SettingWakeUp* screen = static_cast(obj->user_data); - screen->UpdateSelected(obj, event); - } -} - SettingWakeUp::SettingWakeUp(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController) - : Screen(app), settingsController {settingsController} { - - lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr); - - 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, 60); - lv_obj_set_width(container1, LV_HOR_RES - 20); - lv_obj_set_height(container1, LV_VER_RES - 50); - lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); - - lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_text_static(title, "Wake Up"); - lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); - lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 15); - - lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); - lv_label_set_text_static(icon, Symbols::clock); - lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER); - lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); + : Screen(app), settingsController {settingsController}, screen {[this, &settingsController]() { + return CreateScreen(); + }()} { +} - optionsTotal = 0; - cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text_static(cbOption[optionsTotal], " None"); - cbOption[optionsTotal]->user_data = this; - lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); - if (settingsController.getWakeUpMode() == Pinetime::Controllers::Settings::WakeUpMode::None) { - lv_checkbox_set_checked(cbOption[optionsTotal], true); - } - optionsTotal++; - cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text_static(cbOption[optionsTotal], " Single Tap"); - cbOption[optionsTotal]->user_data = this; - lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); - if (settingsController.getWakeUpMode() == Pinetime::Controllers::Settings::WakeUpMode::SingleTap) { - lv_checkbox_set_checked(cbOption[optionsTotal], true); +std::unique_ptr SettingWakeUp::CreateScreen() { + switch (settingsController.getWakeUpMode()) { + case Controllers::Settings::WakeUpMode::None: + options[0].state = true; + break; + case Controllers::Settings::WakeUpMode::SingleTap: + options[1].state = true; + break; + case Controllers::Settings::WakeUpMode::DoubleTap: + options[2].state = true; + break; + case Controllers::Settings::WakeUpMode::RaiseWrist: + options[3].state = true; + break; } - optionsTotal++; - cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text_static(cbOption[optionsTotal], " Double Tap"); - cbOption[optionsTotal]->user_data = this; - lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); - if (settingsController.getWakeUpMode() == Pinetime::Controllers::Settings::WakeUpMode::DoubleTap) { - lv_checkbox_set_checked(cbOption[optionsTotal], true); - } - optionsTotal++; - cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text_static(cbOption[optionsTotal], " Raise Wrist"); - cbOption[optionsTotal]->user_data = this; - lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); - if (settingsController.getWakeUpMode() == Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) { - lv_checkbox_set_checked(cbOption[optionsTotal], true); - } - optionsTotal++; + + return std::make_unique(Symbols::clock, "Wake up", options, app); } SettingWakeUp::~SettingWakeUp() { + if (options[0].state == true) { + settingsController.setWakeUpMode(Pinetime::Controllers::Settings::WakeUpMode::None); + } else if (options[1].state == true) { + settingsController.setWakeUpMode(Pinetime::Controllers::Settings::WakeUpMode::SingleTap); + } else if (options[2].state == true) { + settingsController.setWakeUpMode(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap); + } else if (options[3].state == true) { + settingsController.setWakeUpMode(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist); + } + lv_obj_clean(lv_scr_act()); settingsController.SaveSettings(); } bool SettingWakeUp::Refresh() { - return running; + return screen->Refresh(); } - -void SettingWakeUp::UpdateSelected(lv_obj_t* object, lv_event_t event) { - if (event == LV_EVENT_VALUE_CHANGED) { - for (int i = 0; i < optionsTotal; i++) { - if (object == cbOption[i]) { - lv_checkbox_set_checked(cbOption[i], true); - - if (i == 0) { - settingsController.setWakeUpMode(Pinetime::Controllers::Settings::WakeUpMode::None); - }; - if (i == 1) { - settingsController.setWakeUpMode(Pinetime::Controllers::Settings::WakeUpMode::SingleTap); - }; - if (i == 2) { - settingsController.setWakeUpMode(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap); - }; - if (i == 3) { - settingsController.setWakeUpMode(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist); - }; - - } else { - lv_checkbox_set_checked(cbOption[i], false); - } - } - } -} \ No newline at end of file diff --git a/src/displayapp/screens/settings/SettingWakeUp.h b/src/displayapp/screens/settings/SettingWakeUp.h index 8b33eb069d..6f5d76305a 100644 --- a/src/displayapp/screens/settings/SettingWakeUp.h +++ b/src/displayapp/screens/settings/SettingWakeUp.h @@ -2,26 +2,33 @@ #include #include +#include #include "components/settings/Settings.h" #include "displayapp/screens/Screen.h" +#include "displayapp/screens/CheckBoxes.h" namespace Pinetime { - namespace Applications { namespace Screens { - class SettingWakeUp : public Screen { public: SettingWakeUp(DisplayApp* app, Pinetime::Controllers::Settings& settingsController); ~SettingWakeUp() override; bool Refresh() override; - void UpdateSelected(lv_obj_t* object, lv_event_t event); private: + CheckBoxes::Options options[5] = { + {false, "None"}, + {false, "Single Tap"}, + {false, "Double Tap"}, + {false, "Raise Wrist"}, + {false, ""}, + }; + Controllers::Settings& settingsController; - uint8_t optionsTotal; - lv_obj_t* cbOption[4]; + std::unique_ptr screen; + std::unique_ptr CreateScreen(); }; } } diff --git a/src/displayapp/screens/settings/SettingWatchFace.cpp b/src/displayapp/screens/settings/SettingWatchFace.cpp index 457cebf664..2ff17ff225 100644 --- a/src/displayapp/screens/settings/SettingWatchFace.cpp +++ b/src/displayapp/screens/settings/SettingWatchFace.cpp @@ -6,79 +6,30 @@ using namespace Pinetime::Applications::Screens; -namespace { - static void event_handler(lv_obj_t* obj, lv_event_t event) { - SettingWatchFace* screen = static_cast(obj->user_data); - screen->UpdateSelected(obj, event); - } -} - SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController) - : Screen(app), settingsController {settingsController} { - - lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr); - - // lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111)); - 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, 60); - lv_obj_set_width(container1, LV_HOR_RES - 20); - lv_obj_set_height(container1, LV_VER_RES - 50); - lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); - - lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_text_static(title, "Watch face"); - lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); - lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 10, 15); - - lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); - lv_label_set_text_static(icon, Symbols::clock); - lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER); - lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); - - optionsTotal = 0; - cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text_static(cbOption[optionsTotal], " Digital face"); - cbOption[optionsTotal]->user_data = this; - lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); - if (settingsController.GetClockFace() == 0) { - lv_checkbox_set_checked(cbOption[optionsTotal], true); - } + : Screen(app), settingsController {settingsController}, screen {[this, &settingsController]() { + return CreateScreen(); + }()} { +} - optionsTotal++; - cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text_static(cbOption[optionsTotal], " Analog face"); - cbOption[optionsTotal]->user_data = this; - lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); - if (settingsController.GetClockFace() == 1) { - lv_checkbox_set_checked(cbOption[optionsTotal], true); - } +std::unique_ptr SettingWatchFace::CreateScreen() { + options[settingsController.GetClockFace()].state = true; - optionsTotal++; + return std::make_unique(Symbols::clock, "Watch face", options, app); } SettingWatchFace::~SettingWatchFace() { + for (uint8_t i = 0; i < 2; i++) { + if (options[i].state == true) { + settingsController.SetClockFace(i); + break; + } + } + lv_obj_clean(lv_scr_act()); settingsController.SaveSettings(); } bool SettingWatchFace::Refresh() { - return running; + return screen->Refresh(); } - -void SettingWatchFace::UpdateSelected(lv_obj_t* object, lv_event_t event) { - if (event == LV_EVENT_VALUE_CHANGED) { - for (uint8_t i = 0; i < optionsTotal; i++) { - if (object == cbOption[i]) { - lv_checkbox_set_checked(cbOption[i], true); - settingsController.SetClockFace(i); - } else { - lv_checkbox_set_checked(cbOption[i], false); - } - } - } -} \ No newline at end of file diff --git a/src/displayapp/screens/settings/SettingWatchFace.h b/src/displayapp/screens/settings/SettingWatchFace.h index 1930a22853..f093da15f1 100644 --- a/src/displayapp/screens/settings/SettingWatchFace.h +++ b/src/displayapp/screens/settings/SettingWatchFace.h @@ -2,26 +2,31 @@ #include #include +#include #include "components/settings/Settings.h" #include "displayapp/screens/Screen.h" +#include "displayapp/screens/CheckBoxes.h" namespace Pinetime { - namespace Applications { namespace Screens { - class SettingWatchFace : public Screen { public: SettingWatchFace(DisplayApp* app, Pinetime::Controllers::Settings& settingsController); ~SettingWatchFace() override; bool Refresh() override; - void UpdateSelected(lv_obj_t* object, lv_event_t event); private: + CheckBoxes::Options options[3] = { + {false, "Digital face"}, + {false, "Analog face"}, + {false, ""}, + }; + Controllers::Settings& settingsController; - uint8_t optionsTotal; - lv_obj_t* cbOption[2]; + std::unique_ptr screen; + std::unique_ptr CreateScreen(); }; } } From 71e39898517f1f3c249cd88b83171918e59fabc2 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Sun, 11 Jul 2021 12:40:52 +0300 Subject: [PATCH 2/4] Add missing break --- src/displayapp/screens/settings/SettingDisplay.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/displayapp/screens/settings/SettingDisplay.cpp b/src/displayapp/screens/settings/SettingDisplay.cpp index 90345619cc..4bd45f1070 100644 --- a/src/displayapp/screens/settings/SettingDisplay.cpp +++ b/src/displayapp/screens/settings/SettingDisplay.cpp @@ -42,6 +42,7 @@ SettingDisplay::~SettingDisplay() { for (uint8_t i = 0; i < 6; i++) { if (options[i].state == true) { settingsController.SetScreenTimeOut((i + 1) * 5000); + break; } } lv_obj_clean(lv_scr_act()); From e2e9a00edbe2cc2325134c630b499c135876d9d6 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Sat, 17 Jul 2021 15:07:12 +0300 Subject: [PATCH 3/4] Add support for selecting multiple options with a custom handler function --- src/displayapp/screens/CheckBoxes.cpp | 35 ++++-- src/displayapp/screens/CheckBoxes.h | 39 ++++--- .../screens/settings/SettingDisplay.cpp | 6 +- .../screens/settings/SettingDisplay.h | 2 + .../screens/settings/SettingTimeFormat.cpp | 6 +- .../screens/settings/SettingWakeUp.cpp | 104 +++++------------- .../screens/settings/SettingWakeUp.h | 23 ++-- .../screens/settings/SettingWatchFace.cpp | 6 +- .../screens/settings/SettingWatchFace.h | 2 + 9 files changed, 107 insertions(+), 116 deletions(-) diff --git a/src/displayapp/screens/CheckBoxes.cpp b/src/displayapp/screens/CheckBoxes.cpp index 3475d14225..0c99f336a6 100644 --- a/src/displayapp/screens/CheckBoxes.cpp +++ b/src/displayapp/screens/CheckBoxes.cpp @@ -13,7 +13,8 @@ namespace { } } -CheckBoxes::CheckBoxes(const char* symbol, const char* titleText, Options *options, DisplayApp* app) : Screen(app), options {options} { +CheckBoxes::CheckBoxes(const char* symbol, const char* titleText, Options* options, DisplayApp* app, bool (*UpdateArray)(Options*, uint8_t)) + : Screen(app), options {options}, UpdateArray {UpdateArray} { lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr); @@ -81,13 +82,31 @@ void CheckBoxes::UpdateSelected(lv_obj_t* object, lv_event_t event) { if (event != LV_EVENT_CLICKED) { return; } - for (uint8_t i = 0; i < optionsTotal; i++) { - if (object == buttons[i]) { - lv_obj_add_state(buttons[i], LV_STATE_CHECKED); - options[i].state = true; - } else { - lv_obj_clear_state(buttons[i], LV_STATE_CHECKED); - options[i].state = false; + + uint8_t clicked; + for (clicked = 0; clicked < optionsTotal; clicked++) { + if (object == buttons[clicked]) { + break; + } + } + + if (UpdateArray(options, clicked)) { + for (uint8_t i = 0; i < optionsTotal; i++) { + if (options[i].state) { + lv_obj_add_state(buttons[i], LV_STATE_CHECKED); + } else { + lv_obj_clear_state(buttons[i], LV_STATE_CHECKED); + } + } + } else { + for (uint8_t i = 0; i < optionsTotal; i++) { + if (object == buttons[i]) { + lv_obj_add_state(buttons[i], LV_STATE_CHECKED); + options[i].state = true; + } else { + lv_obj_clear_state(buttons[i], LV_STATE_CHECKED); + options[i].state = false; + } } } } diff --git a/src/displayapp/screens/CheckBoxes.h b/src/displayapp/screens/CheckBoxes.h index 9c95180c88..4781e3f318 100644 --- a/src/displayapp/screens/CheckBoxes.h +++ b/src/displayapp/screens/CheckBoxes.h @@ -4,24 +4,29 @@ #include #include "displayapp/screens/Screen.h" -namespace Pinetime::Applications::Screens { - class CheckBoxes : public Screen { - public: - struct Options { - bool state; - const char* title; - }; - CheckBoxes(const char* symbol, const char* titleText, Options *options, DisplayApp* app); - ~CheckBoxes() override; +namespace Pinetime { + namespace Applications { + namespace Screens { + class CheckBoxes : public Screen { + public: + struct Options { + bool state; + const char* title; + }; + CheckBoxes(const char* symbol, const char* titleText, Options *options, DisplayApp* app, bool (*UpdateArray)(Options*, uint8_t)); + ~CheckBoxes() override; - bool Refresh() override; - void UpdateSelected(lv_obj_t* object, lv_event_t event); + bool Refresh() override; + void UpdateSelected(lv_obj_t* object, lv_event_t event); - private: - struct Options *options; + private: + struct Options* options; + bool (*UpdateArray)(Options* options, uint8_t clicked); - uint8_t optionsTotal; - lv_obj_t* buttons[6]; - lv_style_t buttonStyle; - }; + uint8_t optionsTotal; + lv_obj_t* buttons[6]; + lv_style_t buttonStyle; + }; + } + } } diff --git a/src/displayapp/screens/settings/SettingDisplay.cpp b/src/displayapp/screens/settings/SettingDisplay.cpp index 4bd45f1070..ed743323fe 100644 --- a/src/displayapp/screens/settings/SettingDisplay.cpp +++ b/src/displayapp/screens/settings/SettingDisplay.cpp @@ -13,6 +13,10 @@ SettingDisplay::SettingDisplay(Pinetime::Applications::DisplayApp* app, Pinetime }()} { } +bool SettingDisplay::UpdateArray(Pinetime::Applications::Screens::CheckBoxes::Options* options, uint8_t clicked) { + return false; +} + std::unique_ptr SettingDisplay::CreateScreen() { switch (settingsController.GetScreenTimeOut()) { case 5000: @@ -35,7 +39,7 @@ std::unique_ptr SettingDisplay::CreateScreen() { break; } - return std::make_unique(Symbols::sun, "Display timeout", options, app); + return std::make_unique(Symbols::sun, "Display timeout", options, app, UpdateArray); } SettingDisplay::~SettingDisplay() { diff --git a/src/displayapp/screens/settings/SettingDisplay.h b/src/displayapp/screens/settings/SettingDisplay.h index 9c4a9452ff..4088a2acc3 100644 --- a/src/displayapp/screens/settings/SettingDisplay.h +++ b/src/displayapp/screens/settings/SettingDisplay.h @@ -17,6 +17,8 @@ namespace Pinetime { bool Refresh() override; + static bool UpdateArray(Pinetime::Applications::Screens::CheckBoxes::Options* options, uint8_t clicked); + private: CheckBoxes::Options options[6] = { {false, "5s"}, diff --git a/src/displayapp/screens/settings/SettingTimeFormat.cpp b/src/displayapp/screens/settings/SettingTimeFormat.cpp index df9043d10a..1b39497f9d 100644 --- a/src/displayapp/screens/settings/SettingTimeFormat.cpp +++ b/src/displayapp/screens/settings/SettingTimeFormat.cpp @@ -12,6 +12,10 @@ SettingTimeFormat::SettingTimeFormat(Pinetime::Applications::DisplayApp* app, Pi }()} { } +bool UpdateArray(Pinetime::Applications::Screens::CheckBoxes::Options* options, uint8_t clicked) { + return false; +} + std::unique_ptr SettingTimeFormat::CreateScreen() { if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) { options[0].state = true; @@ -19,7 +23,7 @@ std::unique_ptr SettingTimeFormat::CreateScreen() { options[1].state = true; } - return std::make_unique(Symbols::clock, "Time format", options, app); + return std::make_unique(Symbols::clock, "Time format", options, app, UpdateArray); } SettingTimeFormat::~SettingTimeFormat() { diff --git a/src/displayapp/screens/settings/SettingWakeUp.cpp b/src/displayapp/screens/settings/SettingWakeUp.cpp index 0e0803537f..d4fc78fbbe 100644 --- a/src/displayapp/screens/settings/SettingWakeUp.cpp +++ b/src/displayapp/screens/settings/SettingWakeUp.cpp @@ -7,101 +7,49 @@ using namespace Pinetime::Applications::Screens; -namespace { - static void event_handler(lv_obj_t* obj, lv_event_t event) { - SettingWakeUp* screen = static_cast(obj->user_data); - screen->UpdateSelected(obj, event); +bool SettingWakeUp::UpdateArray(Pinetime::Applications::Screens::CheckBoxes::Options* options, uint8_t clicked) { + options[clicked].state = !options[clicked].state; + if (clicked == 0) { + if (options[0].state) { + options[1].state = false; + } + } else if (clicked == 1) { + if (options[1].state) { + options[0].state = false; + } } + return true; } SettingWakeUp::SettingWakeUp(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController) - : Screen(app), settingsController {settingsController} { - ignoringEvents = false; - lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr); - - 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, 60); - lv_obj_set_width(container1, LV_HOR_RES - 20); - lv_obj_set_height(container1, LV_VER_RES - 50); - lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); - - lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_text_static(title, "Wake Up"); - lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); - lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 15); - - lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); - lv_label_set_text_static(icon, Symbols::clock); - lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER); - lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); + : Screen(app), settingsController {settingsController}, screen {[this, &settingsController]() { + return CreateScreen(); + }()} { +} - optionsTotal = 0; - cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text_static(cbOption[optionsTotal], " Single Tap"); - cbOption[optionsTotal]->user_data = this; - lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); +std::unique_ptr SettingWakeUp::CreateScreen() { if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap)) { - lv_checkbox_set_checked(cbOption[optionsTotal], true); + options[0].state = true; } - optionsTotal++; - cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text_static(cbOption[optionsTotal], " Double Tap"); - cbOption[optionsTotal]->user_data = this; - lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) { - lv_checkbox_set_checked(cbOption[optionsTotal], true); + options[1].state = true; } - optionsTotal++; - cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text_static(cbOption[optionsTotal], " Raise Wrist"); - cbOption[optionsTotal]->user_data = this; - lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist)) { - lv_checkbox_set_checked(cbOption[optionsTotal], true); + options[2].state = true; } - optionsTotal++; + + return std::make_unique(Symbols::sun, "Wake Up", options, app, UpdateArray); } SettingWakeUp::~SettingWakeUp() { + settingsController.setWakeUpMode(Pinetime::Controllers::Settings::WakeUpMode::SingleTap, options[0].state); + settingsController.setWakeUpMode(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap, options[1].state); + settingsController.setWakeUpMode(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist, options[2].state); + lv_obj_clean(lv_scr_act()); settingsController.SaveSettings(); } bool SettingWakeUp::Refresh() { - return running; -} - -void SettingWakeUp::UpdateSelected(lv_obj_t* object, lv_event_t event) { - using WakeUpMode = Pinetime::Controllers::Settings::WakeUpMode; - if (event == LV_EVENT_VALUE_CHANGED && !ignoringEvents) { - ignoringEvents = true; - - // Find the index of the checkbox that triggered the event - int index = 0; - for (; index < optionsTotal; ++index) { - if (cbOption[index] == object) { - break; - } - } - - // Toggle needed wakeup mode - auto mode = static_cast(index); - auto currentState = settingsController.isWakeUpModeOn(mode); - settingsController.setWakeUpMode(mode, !currentState); - - // Update checkbox according to current wakeup modes. - // This is needed because we can have extra logic when setting or unsetting wakeup modes, - // for example, when setting SingleTap, DoubleTap is unset and vice versa. - auto modes = settingsController.getWakeUpModes(); - for (int i = 0; i < optionsTotal; ++i) { - lv_checkbox_set_checked(cbOption[i], modes[i]); - } - - ignoringEvents = false; - } + return screen->Refresh(); } diff --git a/src/displayapp/screens/settings/SettingWakeUp.h b/src/displayapp/screens/settings/SettingWakeUp.h index 248dd9acfd..8e31660c0a 100644 --- a/src/displayapp/screens/settings/SettingWakeUp.h +++ b/src/displayapp/screens/settings/SettingWakeUp.h @@ -2,31 +2,34 @@ #include #include +#include #include "components/settings/Settings.h" #include "displayapp/screens/Screen.h" +#include "displayapp/screens/CheckBoxes.h" namespace Pinetime { - namespace Applications { namespace Screens { - class SettingWakeUp : public Screen { public: SettingWakeUp(DisplayApp* app, Pinetime::Controllers::Settings& settingsController); ~SettingWakeUp() override; bool Refresh() override; - void UpdateSelected(lv_obj_t* object, lv_event_t event); + + static bool UpdateArray(Pinetime::Applications::Screens::CheckBoxes::Options* options, uint8_t clicked); private: + CheckBoxes::Options options[4] = { + {false, "Single Tap"}, + {false, "Double Tap"}, + {false, "Raise Wrist"}, + {false, ""}, + }; + Controllers::Settings& settingsController; - uint8_t optionsTotal; - lv_obj_t* cbOption[4]; - // When UpdateSelected is called, it uses lv_checkbox_set_checked, - // which can cause extra events to be fired, - // which might trigger UpdateSelected again, causing a loop. - // This variable is used as a mutex to prevent that. - bool ignoringEvents; + std::unique_ptr screen; + std::unique_ptr CreateScreen(); }; } } diff --git a/src/displayapp/screens/settings/SettingWatchFace.cpp b/src/displayapp/screens/settings/SettingWatchFace.cpp index d9879cf60a..4113dcff9b 100644 --- a/src/displayapp/screens/settings/SettingWatchFace.cpp +++ b/src/displayapp/screens/settings/SettingWatchFace.cpp @@ -12,10 +12,14 @@ SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app, Pine }()} { } +bool SettingWatchFace::UpdateArray(Pinetime::Applications::Screens::CheckBoxes::Options* options, uint8_t clicked) { + return false; +} + std::unique_ptr SettingWatchFace::CreateScreen() { options[settingsController.GetClockFace()].state = true; - return std::make_unique(Symbols::clock, "Watch face", options, app); + return std::make_unique(Symbols::clock, "Watch face", options, app, UpdateArray); } SettingWatchFace::~SettingWatchFace() { diff --git a/src/displayapp/screens/settings/SettingWatchFace.h b/src/displayapp/screens/settings/SettingWatchFace.h index 591761ae10..a3201d313b 100644 --- a/src/displayapp/screens/settings/SettingWatchFace.h +++ b/src/displayapp/screens/settings/SettingWatchFace.h @@ -17,6 +17,8 @@ namespace Pinetime { bool Refresh() override; + static bool UpdateArray(Pinetime::Applications::Screens::CheckBoxes::Options* options, uint8_t clicked); + private: CheckBoxes::Options options[4] = { {false, "Digital face"}, From 002cc87d393205fc947259153264900c0ff11153 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Mon, 26 Jul 2021 16:30:38 +0300 Subject: [PATCH 4/4] Push UpdateTimeOut message, which was accidentally removed --- src/displayapp/screens/settings/SettingDisplay.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/displayapp/screens/settings/SettingDisplay.cpp b/src/displayapp/screens/settings/SettingDisplay.cpp index ed743323fe..389dad9929 100644 --- a/src/displayapp/screens/settings/SettingDisplay.cpp +++ b/src/displayapp/screens/settings/SettingDisplay.cpp @@ -49,6 +49,7 @@ SettingDisplay::~SettingDisplay() { break; } } + app->PushMessage(Applications::Display::Messages::UpdateTimeOut); lv_obj_clean(lv_scr_act()); settingsController.SaveSettings(); }