From 9c5b1437ecd032c163f2caf3afeac32b90b7f7ae Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Thu, 13 Oct 2022 21:24:33 +0300 Subject: [PATCH] Optimize SettingTimeFormat --- .../screens/settings/SettingTimeFormat.cpp | 13 +++---------- src/displayapp/screens/settings/SettingTimeFormat.h | 9 ++++++++- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/displayapp/screens/settings/SettingTimeFormat.cpp b/src/displayapp/screens/settings/SettingTimeFormat.cpp index 5502794b..e137c0af 100644 --- a/src/displayapp/screens/settings/SettingTimeFormat.cpp +++ b/src/displayapp/screens/settings/SettingTimeFormat.cpp @@ -14,7 +14,7 @@ namespace { } } -constexpr std::array SettingTimeFormat::options; +constexpr std::array SettingTimeFormat::options; SettingTimeFormat::SettingTimeFormat(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController) : Screen(app), settingsController {settingsController} { @@ -44,7 +44,7 @@ SettingTimeFormat::SettingTimeFormat(Pinetime::Applications::DisplayApp* app, Pi for (unsigned int i = 0; i < options.size(); i++) { cbOption[i] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text(cbOption[i], options[i]); + lv_checkbox_set_text(cbOption[i], options[i].name); cbOption[i]->user_data = this; lv_obj_set_event_cb(cbOption[i], event_handler); SetRadioButtonStyle(cbOption[i]); @@ -67,14 +67,7 @@ void SettingTimeFormat::UpdateSelected(lv_obj_t* object, lv_event_t event) { for (unsigned int i = 0; i < options.size(); 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); - }; - + settingsController.SetClockType(options[i].clockType); } else { lv_checkbox_set_checked(cbOption[i], false); } diff --git a/src/displayapp/screens/settings/SettingTimeFormat.h b/src/displayapp/screens/settings/SettingTimeFormat.h index 01ca2c9b..dc0413ec 100644 --- a/src/displayapp/screens/settings/SettingTimeFormat.h +++ b/src/displayapp/screens/settings/SettingTimeFormat.h @@ -20,7 +20,14 @@ namespace Pinetime { void UpdateSelected(lv_obj_t* object, lv_event_t event); private: - static constexpr std::array options = {"12-hour", "24-hour"}; + struct Option { + Controllers::Settings::ClockType clockType; + const char* name; + }; + static constexpr std::array options = {{ + {Controllers::Settings::ClockType::H12, "12-hour"}, + {Controllers::Settings::ClockType::H24, "24-hour"}, + }}; Controllers::Settings& settingsController; lv_obj_t* cbOption[options.size()]; };