Skip to content

Commit b561e7f

Browse files
committed
Implement CheckboxList screen
1 parent f9d2b78 commit b561e7f

File tree

3 files changed

+166
-0
lines changed

3 files changed

+166
-0
lines changed

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ list(APPEND SOURCE_FILES
396396
displayapp/screens/Motion.cpp
397397
displayapp/screens/FlashLight.cpp
398398
displayapp/screens/List.cpp
399+
displayapp/screens/CheckboxList.cpp
399400
displayapp/screens/BatteryInfo.cpp
400401
displayapp/screens/Steps.cpp
401402
displayapp/screens/Timer.cpp
@@ -604,6 +605,7 @@ set(INCLUDE_FILES
604605
displayapp/screens/FirmwareUpdate.h
605606
displayapp/screens/FirmwareValidation.h
606607
displayapp/screens/ApplicationList.h
608+
displayapp/screens/CheckboxList.h
607609
displayapp/Apps.h
608610
displayapp/screens/Notifications.h
609611
displayapp/screens/HeartRate.h
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#pragma once
2+
3+
#include <lvgl/lvgl.h>
4+
#include <cstdint>
5+
#include <memory>
6+
#include "displayapp/screens/Screen.h"
7+
#include "displayapp/Apps.h"
8+
#include "components/settings/Settings.h"
9+
10+
#define MAXLISTITEMS 4
11+
12+
namespace Pinetime {
13+
namespace Applications {
14+
namespace Screens {
15+
class CheckboxList : public Screen {
16+
public:
17+
CheckboxList(const uint8_t screenID,
18+
const uint8_t numScreens,
19+
DisplayApp* app,
20+
Controllers::Settings& settingsController,
21+
const char* optionsTitle,
22+
const char* optionsSymbol,
23+
void (Controllers::Settings::*SetOptionIndex)(uint8_t),
24+
uint8_t (Controllers::Settings::*GetOptionIndex)() const,
25+
std::array<const char*, MAXLISTITEMS> options);
26+
27+
~CheckboxList() override;
28+
29+
void UpdateSelected(lv_obj_t* object, lv_event_t event);
30+
31+
private:
32+
const uint8_t screenID;
33+
Controllers::Settings& settingsController;
34+
const char* optionsTitle;
35+
const char* optionsSymbol;
36+
void (Controllers::Settings::*SetOptionIndex)(uint8_t);
37+
uint8_t (Controllers::Settings::*GetOptionIndex)() const;
38+
std::array<const char*, MAXLISTITEMS> options;
39+
40+
lv_obj_t* cbOption[MAXLISTITEMS];
41+
42+
lv_point_t pageIndicatorBasePoints[2];
43+
lv_point_t pageIndicatorPoints[2];
44+
lv_obj_t* pageIndicatorBase;
45+
lv_obj_t* pageIndicator;
46+
};
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)