|
| 1 | +#include "displayapp/screens/CheckboxList.h" |
| 2 | +#include "displayapp/DisplayApp.h" |
| 3 | +#include "displayapp/screens/Styles.h" |
| 4 | +#include "displayapp/screens/Symbols.h" |
| 5 | + |
| 6 | +using namespace Pinetime::Applications::Screens; |
| 7 | + |
| 8 | +namespace { |
| 9 | + static void event_handler(lv_obj_t* obj, lv_event_t event) { |
| 10 | + CheckboxList* screen = static_cast<CheckboxList*>(obj->user_data); |
| 11 | + screen->UpdateSelected(obj, event); |
| 12 | + } |
| 13 | + |
| 14 | +} |
| 15 | + |
| 16 | +CheckboxList::CheckboxList(const uint8_t screenID, |
| 17 | + const uint8_t numScreens, |
| 18 | + DisplayApp* app, |
| 19 | + Controllers::Settings& settingsController, |
| 20 | + const char* optionsTitle, |
| 21 | + const char* optionsSymbol, |
| 22 | + void (Controllers::Settings::*SetOptionIndex)(uint8_t), |
| 23 | + uint8_t (Controllers::Settings::*GetOptionIndex )() const, |
| 24 | + std::array<const char*, MAXLISTITEMS> options) |
| 25 | + : Screen(app), screenID {screenID}, settingsController {settingsController}, |
| 26 | + SetOptionIndex {SetOptionIndex}, GetOptionIndex {GetOptionIndex}, |
| 27 | + options {options} { |
| 28 | + |
| 29 | + settingsController.SetWatchfacesMenu(screenID); |
| 30 | + |
| 31 | + // Set the background to Black |
| 32 | + lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK); |
| 33 | + |
| 34 | + if (numScreens > 1) { |
| 35 | + pageIndicatorBasePoints[0].x = LV_HOR_RES - 1; |
| 36 | + pageIndicatorBasePoints[0].y = 0; |
| 37 | + pageIndicatorBasePoints[1].x = LV_HOR_RES - 1; |
| 38 | + pageIndicatorBasePoints[1].y = LV_VER_RES; |
| 39 | + |
| 40 | + pageIndicatorBase = lv_line_create(lv_scr_act(), NULL); |
| 41 | + lv_obj_set_style_local_line_width(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3); |
| 42 | + lv_obj_set_style_local_line_color(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111)); |
| 43 | + lv_line_set_points(pageIndicatorBase, pageIndicatorBasePoints, 2); |
| 44 | + |
| 45 | + const uint16_t indicatorSize = LV_VER_RES / numScreens; |
| 46 | + const uint16_t indicatorPos = indicatorSize * screenID; |
| 47 | + |
| 48 | + pageIndicatorPoints[0].x = LV_HOR_RES - 1; |
| 49 | + pageIndicatorPoints[0].y = indicatorPos; |
| 50 | + pageIndicatorPoints[1].x = LV_HOR_RES - 1; |
| 51 | + pageIndicatorPoints[1].y = indicatorPos + indicatorSize; |
| 52 | + |
| 53 | + pageIndicator = lv_line_create(lv_scr_act(), NULL); |
| 54 | + lv_obj_set_style_local_line_width(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3); |
| 55 | + lv_obj_set_style_local_line_color(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); |
| 56 | + lv_line_set_points(pageIndicator, pageIndicatorPoints, 2); |
| 57 | + } |
| 58 | + |
| 59 | + lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr); |
| 60 | + |
| 61 | + lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); |
| 62 | + lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10); |
| 63 | + lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5); |
| 64 | + lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); |
| 65 | + |
| 66 | + lv_obj_set_pos(container1, 10, 60); |
| 67 | + lv_obj_set_width(container1, LV_HOR_RES - 20); |
| 68 | + lv_obj_set_height(container1, LV_VER_RES - 50); |
| 69 | + lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); |
| 70 | + |
| 71 | + lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); |
| 72 | + lv_label_set_text_static(title, optionsTitle); |
| 73 | + lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); |
| 74 | + lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 10, 15); |
| 75 | + |
| 76 | + lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr); |
| 77 | + lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); |
| 78 | + lv_label_set_text_static(icon, optionsSymbol); |
| 79 | + lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER); |
| 80 | + lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); |
| 81 | + |
| 82 | + for (unsigned int i = 0; i < options.size(); i++) { |
| 83 | + if (strcmp(options[i], "")) { |
| 84 | + cbOption[i] = lv_checkbox_create(container1, nullptr); |
| 85 | + lv_checkbox_set_text(cbOption[i], options[i]); |
| 86 | + cbOption[i]->user_data = this; |
| 87 | + lv_obj_set_event_cb(cbOption[i], event_handler); |
| 88 | + SetRadioButtonStyle(cbOption[i]); |
| 89 | + |
| 90 | + if (static_cast<unsigned int>((settingsController.*GetOptionIndex)() - MAXLISTITEMS*screenID) == i) { |
| 91 | + lv_checkbox_set_checked(cbOption[i], true); |
| 92 | + } |
| 93 | + } |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +CheckboxList::~CheckboxList() { |
| 98 | + lv_obj_clean(lv_scr_act()); |
| 99 | + settingsController.SaveSettings(); |
| 100 | +} |
| 101 | + |
| 102 | +void CheckboxList::UpdateSelected(lv_obj_t* object, lv_event_t event) { |
| 103 | + if (event == LV_EVENT_VALUE_CHANGED) { |
| 104 | + for (unsigned int i = 0; i < options.size(); i++) { |
| 105 | + if (strcmp(options[i], "")) { |
| 106 | + if (object == cbOption[i]) { |
| 107 | + lv_checkbox_set_checked(cbOption[i], true); |
| 108 | + (settingsController.*SetOptionIndex)(MAXLISTITEMS*screenID + i); |
| 109 | + } else { |
| 110 | + lv_checkbox_set_checked(cbOption[i], false); |
| 111 | + } |
| 112 | + } |
| 113 | + } |
| 114 | + } |
| 115 | +} |
0 commit comments