mirror of
https://github.com/InfiniTimeOrg/InfiniTime.git
synced 2024-12-25 10:41:42 +03:00
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)
|
SettingTimeFormat::SettingTimeFormat(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController)
|
||||||
: Screen(app), settingsController {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++) {
|
for (unsigned int i = 0; i < options.size(); i++) {
|
||||||
cbOption[i] = lv_checkbox_create(container1, nullptr);
|
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;
|
cbOption[i]->user_data = this;
|
||||||
lv_obj_set_event_cb(cbOption[i], event_handler);
|
lv_obj_set_event_cb(cbOption[i], event_handler);
|
||||||
SetRadioButtonStyle(cbOption[i]);
|
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++) {
|
for (unsigned int i = 0; i < options.size(); i++) {
|
||||||
if (object == cbOption[i]) {
|
if (object == cbOption[i]) {
|
||||||
lv_checkbox_set_checked(cbOption[i], true);
|
lv_checkbox_set_checked(cbOption[i], true);
|
||||||
|
settingsController.SetClockType(options[i].clockType);
|
||||||
if (i == 0) {
|
|
||||||
settingsController.SetClockType(Controllers::Settings::ClockType::H12);
|
|
||||||
};
|
|
||||||
if (i == 1) {
|
|
||||||
settingsController.SetClockType(Controllers::Settings::ClockType::H24);
|
|
||||||
};
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
lv_checkbox_set_checked(cbOption[i], false);
|
lv_checkbox_set_checked(cbOption[i], false);
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,14 @@ namespace Pinetime {
|
|||||||
void UpdateSelected(lv_obj_t* object, lv_event_t event);
|
void UpdateSelected(lv_obj_t* object, lv_event_t event);
|
||||||
|
|
||||||
private:
|
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;
|
Controllers::Settings& settingsController;
|
||||||
lv_obj_t* cbOption[options.size()];
|
lv_obj_t* cbOption[options.size()];
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user