|
1 | 1 | #include "displayapp/screens/settings/SettingWatchFace.h" |
2 | 2 | #include <lvgl/lvgl.h> |
3 | 3 | #include "displayapp/DisplayApp.h" |
| 4 | +#include "displayapp/screens/CheckboxList.h" |
4 | 5 | #include "displayapp/screens/Screen.h" |
5 | 6 | #include "displayapp/screens/Styles.h" |
6 | 7 | #include "displayapp/screens/Symbols.h" |
| 8 | +#include "components/settings/Settings.h" |
7 | 9 |
|
8 | 10 | using namespace Pinetime::Applications::Screens; |
9 | 11 |
|
10 | | -namespace { |
11 | | - void event_handler(lv_obj_t* obj, lv_event_t event) { |
12 | | - auto* screen = static_cast<SettingWatchFace*>(obj->user_data); |
13 | | - screen->UpdateSelected(obj, event); |
14 | | - } |
15 | | -} |
16 | | - |
17 | | -constexpr std::array<const char*, 4> SettingWatchFace::options; |
| 12 | +constexpr const char* SettingWatchFace::title; |
| 13 | +constexpr const char* SettingWatchFace::symbol; |
18 | 14 |
|
19 | 15 | SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController) |
20 | | - : Screen(app), settingsController {settingsController} { |
21 | | - |
22 | | - lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr); |
23 | | - |
24 | | - // lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111)); |
25 | | - lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); |
26 | | - lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10); |
27 | | - lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5); |
28 | | - lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); |
29 | | - |
30 | | - lv_obj_set_pos(container1, 10, 60); |
31 | | - lv_obj_set_width(container1, LV_HOR_RES - 20); |
32 | | - lv_obj_set_height(container1, LV_VER_RES - 50); |
33 | | - lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); |
34 | | - |
35 | | - lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); |
36 | | - lv_label_set_text_static(title, "Watch face"); |
37 | | - lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); |
38 | | - lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 10, 15); |
39 | | - |
40 | | - lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr); |
41 | | - lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); |
42 | | - lv_label_set_text_static(icon, Symbols::home); |
43 | | - lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER); |
44 | | - lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); |
45 | | - |
46 | | - for (unsigned int i = 0; i < options.size(); i++) { |
47 | | - cbOption[i] = lv_checkbox_create(container1, nullptr); |
48 | | - lv_checkbox_set_text(cbOption[i], options[i]); |
49 | | - cbOption[i]->user_data = this; |
50 | | - lv_obj_set_event_cb(cbOption[i], event_handler); |
51 | | - SetRadioButtonStyle(cbOption[i]); |
52 | | - |
53 | | - if (settingsController.GetClockFace() == i) { |
54 | | - lv_checkbox_set_checked(cbOption[i], true); |
55 | | - } |
56 | | - } |
| 16 | + : Screen(app), |
| 17 | + settingsController {settingsController}, |
| 18 | + screens {app, |
| 19 | + settingsController.GetWatchfacesMenu(), |
| 20 | + { |
| 21 | + [this]() -> std::unique_ptr<Screen> { |
| 22 | + return CreateScreen1(); |
| 23 | + }, |
| 24 | + [this]() -> std::unique_ptr<Screen> { |
| 25 | + return CreateScreen2(); |
| 26 | + } |
| 27 | + }, |
| 28 | + Screens::ScreenListModes::UpDown} { |
57 | 29 | } |
58 | 30 |
|
59 | 31 | SettingWatchFace::~SettingWatchFace() { |
60 | 32 | lv_obj_clean(lv_scr_act()); |
61 | 33 | settingsController.SaveSettings(); |
62 | 34 | } |
63 | 35 |
|
64 | | -void SettingWatchFace::UpdateSelected(lv_obj_t* object, lv_event_t event) { |
65 | | - if (event == LV_EVENT_VALUE_CHANGED) { |
66 | | - for (unsigned int i = 0; i < options.size(); i++) { |
67 | | - if (object == cbOption[i]) { |
68 | | - lv_checkbox_set_checked(cbOption[i], true); |
69 | | - settingsController.SetClockFace(i); |
70 | | - } else { |
71 | | - lv_checkbox_set_checked(cbOption[i], false); |
72 | | - } |
73 | | - } |
74 | | - } |
| 36 | +bool SettingWatchFace::OnTouchEvent(Pinetime::Applications::TouchEvents event) { |
| 37 | + return screens.OnTouchEvent(event); |
| 38 | +} |
| 39 | + |
| 40 | +std::unique_ptr<Screen> SettingWatchFace::CreateScreen1() { |
| 41 | + std::array<const char*, 4> watchfaces {" Digital face", " Analog face", " PineTimeStyle", " Terminal"}; |
| 42 | + return std::make_unique<Screens::CheckboxList>(0, 2, app, settingsController, title, |
| 43 | + symbol, &Controllers::Settings::SetClockFace, |
| 44 | + &Controllers::Settings::GetClockFace, |
| 45 | + watchfaces); |
| 46 | +} |
| 47 | + |
| 48 | +std::unique_ptr<Screen> SettingWatchFace::CreateScreen2() { |
| 49 | + std::array<const char*, 4> watchfaces {" Infineat face", "", "", ""}; |
| 50 | + return std::make_unique<Screens::CheckboxList>(1, 2, app, settingsController, title, |
| 51 | + symbol, &Controllers::Settings::SetClockFace, |
| 52 | + &Controllers::Settings::GetClockFace, |
| 53 | + watchfaces); |
75 | 54 | } |
0 commit comments