|
9 | 9 | using namespace Pinetime::Applications::Screens; |
10 | 10 |
|
11 | 11 | namespace { |
12 | | - void event_handler(lv_obj_t* obj, lv_event_t event) { |
| 12 | + void TimeoutEventHandler(lv_obj_t* obj, lv_event_t event) { |
13 | 13 | auto* screen = static_cast<SettingDisplay*>(obj->user_data); |
14 | 14 | screen->UpdateSelected(obj, event); |
15 | 15 | } |
| 16 | + |
| 17 | + void AlwaysOnEventHandler(lv_obj_t* obj, lv_event_t event) { |
| 18 | + if (event == LV_EVENT_VALUE_CHANGED) { |
| 19 | + auto* screen = static_cast<SettingDisplay*>(obj->user_data); |
| 20 | + screen->ToggleAlwaysOn(); |
| 21 | + } |
| 22 | + } |
16 | 23 | } |
17 | 24 |
|
18 | | -constexpr std::array<uint16_t, 7> SettingDisplay::options; |
| 25 | +constexpr std::array<uint16_t, 6> SettingDisplay::options; |
19 | 26 |
|
20 | 27 | SettingDisplay::SettingDisplay(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController) |
21 | 28 | : app {app}, settingsController {settingsController} { |
@@ -46,34 +53,36 @@ SettingDisplay::SettingDisplay(Pinetime::Applications::DisplayApp* app, Pinetime |
46 | 53 | char buffer[4]; |
47 | 54 | for (unsigned int i = 0; i < options.size(); i++) { |
48 | 55 | cbOption[i] = lv_checkbox_create(container1, nullptr); |
49 | | - if (options[i] == 0) { |
50 | | - sprintf(buffer, "%s", "Always On"); |
51 | | - } else { |
52 | | - sprintf(buffer, "%2ds", options[i] / 1000); |
53 | | - } |
| 56 | + snprintf(buffer, sizeof(buffer), "%2" PRIu16 "s", options[i] / 1000); |
54 | 57 | lv_checkbox_set_text(cbOption[i], buffer); |
55 | 58 | cbOption[i]->user_data = this; |
56 | | - lv_obj_set_event_cb(cbOption[i], event_handler); |
| 59 | + lv_obj_set_event_cb(cbOption[i], TimeoutEventHandler); |
57 | 60 | SetRadioButtonStyle(cbOption[i]); |
58 | 61 |
|
59 | 62 | if (settingsController.GetScreenTimeOut() == options[i]) { |
60 | 63 | lv_checkbox_set_checked(cbOption[i], true); |
61 | 64 | } |
62 | 65 | } |
| 66 | + |
| 67 | + alwaysOnCheckbox = lv_checkbox_create(container1, nullptr); |
| 68 | + lv_checkbox_set_text(alwaysOnCheckbox, "Always On"); |
| 69 | + lv_checkbox_set_checked(alwaysOnCheckbox, settingsController.GetAlwaysOnDisplay()); |
| 70 | + lv_obj_add_state(alwaysOnCheckbox, LV_STATE_DEFAULT); |
| 71 | + alwaysOnCheckbox->user_data = this; |
| 72 | + lv_obj_set_event_cb(alwaysOnCheckbox, AlwaysOnEventHandler); |
63 | 73 | } |
64 | 74 |
|
65 | 75 | SettingDisplay::~SettingDisplay() { |
66 | 76 | lv_obj_clean(lv_scr_act()); |
67 | 77 | settingsController.SaveSettings(); |
68 | 78 | } |
69 | 79 |
|
70 | | -void SettingDisplay::UpdateSelected(lv_obj_t* object, lv_event_t event) { |
71 | | - if (settingsController.GetScreenTimeOut() == 0) { |
72 | | - settingsController.SetAlwaysOnDisplay(true); |
73 | | - } else { |
74 | | - settingsController.SetAlwaysOnDisplay(false); |
75 | | - } |
| 80 | +void SettingDisplay::ToggleAlwaysOn() { |
| 81 | + settingsController.SetAlwaysOnDisplay(!settingsController.GetAlwaysOnDisplay()); |
| 82 | + lv_checkbox_set_checked(alwaysOnCheckbox, settingsController.GetAlwaysOnDisplay()); |
| 83 | +} |
76 | 84 |
|
| 85 | +void SettingDisplay::UpdateSelected(lv_obj_t* object, lv_event_t event) { |
77 | 86 | if (event == LV_EVENT_CLICKED) { |
78 | 87 | for (unsigned int i = 0; i < options.size(); i++) { |
79 | 88 | if (object == cbOption[i]) { |
|
0 commit comments