Optimize SettingTimeFormat
This commit is contained in:
parent
23a68ba45a
commit
9c5b1437ec
|
@ -14,7 +14,7 @@ namespace {
|
|||
}
|
||||
}
|
||||
|
||||
constexpr std::array<const char*, 2> SettingTimeFormat::options;
|
||||
constexpr std::array<SettingTimeFormat::Option, 2> 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);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,14 @@ namespace Pinetime {
|
|||
void UpdateSelected(lv_obj_t* object, lv_event_t event);
|
||||
|
||||
private:
|
||||
static constexpr std::array<const char*, 2> options = {"12-hour", "24-hour"};
|
||||
struct Option {
|
||||
Controllers::Settings::ClockType clockType;
|
||||
const char* name;
|
||||
};
|
||||
static constexpr std::array<Option, 2> options = {{
|
||||
{Controllers::Settings::ClockType::H12, "12-hour"},
|
||||
{Controllers::Settings::ClockType::H24, "24-hour"},
|
||||
}};
|
||||
Controllers::Settings& settingsController;
|
||||
lv_obj_t* cbOption[options.size()];
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user