1- #include " displayapp/screens/CheckboxList.h"
21#include " displayapp/DisplayApp.h"
2+ #include " displayapp/screens/CheckboxList.h"
33#include " displayapp/screens/Styles.h"
44
55using namespace Pinetime ::Applications::Screens;
@@ -9,27 +9,21 @@ namespace {
99 CheckboxList* screen = static_cast <CheckboxList*>(obj->user_data );
1010 screen->UpdateSelected (obj, event);
1111 }
12-
1312}
1413
1514CheckboxList::CheckboxList (const uint8_t screenID,
1615 const uint8_t numScreens,
1716 DisplayApp* app,
18- Controllers::Settings& settingsController,
1917 const char * optionsTitle,
2018 const char * optionsSymbol,
21- void (Controllers::Settings::*SetOptionIndex)( uint8_t ) ,
22- uint8_t (Controllers::Settings::*GetOptionIndex)() const ,
19+ uint32_t originalValue ,
20+ std::function< void ( uint32_t )>OnValueChanged ,
2321 std::array<const char*, MaxItems> options)
2422 : Screen(app),
2523 screenID {screenID},
26- settingsController {settingsController},
27- SetOptionIndex {SetOptionIndex},
28- GetOptionIndex {GetOptionIndex},
29- options {options} {
30-
31- settingsController.SetWatchfacesMenu (screenID);
32-
24+ OnValueChanged{std::move (OnValueChanged)},
25+ options {options},
26+ newValue{originalValue} {
3327 // Set the background to Black
3428 lv_obj_set_style_local_bg_color (lv_scr_act (), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
3529
@@ -39,7 +33,7 @@ CheckboxList::CheckboxList(const uint8_t screenID,
3933 pageIndicatorBasePoints[1 ].x = LV_HOR_RES - 1 ;
4034 pageIndicatorBasePoints[1 ].y = LV_VER_RES;
4135
42- pageIndicatorBase = lv_line_create (lv_scr_act (), NULL );
36+ pageIndicatorBase = lv_line_create (lv_scr_act (), nullptr );
4337 lv_obj_set_style_local_line_width (pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3 );
4438 lv_obj_set_style_local_line_color (pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (0x111111 ));
4539 lv_line_set_points (pageIndicatorBase, pageIndicatorBasePoints.data (), 2 );
@@ -52,7 +46,7 @@ CheckboxList::CheckboxList(const uint8_t screenID,
5246 pageIndicatorPoints[1 ].x = LV_HOR_RES - 1 ;
5347 pageIndicatorPoints[1 ].y = indicatorPos + indicatorSize;
5448
55- pageIndicator = lv_line_create (lv_scr_act (), NULL );
49+ pageIndicator = lv_line_create (lv_scr_act (), nullptr );
5650 lv_obj_set_style_local_line_width (pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3 );
5751 lv_obj_set_style_local_line_color (pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
5852 lv_line_set_points (pageIndicator, pageIndicatorPoints.data (), 2 );
@@ -89,7 +83,7 @@ CheckboxList::CheckboxList(const uint8_t screenID,
8983 lv_obj_set_event_cb (cbOption[i], event_handler);
9084 SetRadioButtonStyle (cbOption[i]);
9185
92- if (static_cast <unsigned int >((settingsController.*GetOptionIndex)() - MaxItems * screenID) == i) {
86+ if (static_cast <unsigned int >(originalValue - MaxItems * screenID) == i) {
9387 lv_checkbox_set_checked (cbOption[i], true );
9488 }
9589 }
@@ -98,6 +92,7 @@ CheckboxList::CheckboxList(const uint8_t screenID,
9892
9993CheckboxList::~CheckboxList () {
10094 lv_obj_clean (lv_scr_act ());
95+ OnValueChanged (newValue);
10196}
10297
10398void CheckboxList::UpdateSelected (lv_obj_t * object, lv_event_t event) {
@@ -106,7 +101,7 @@ void CheckboxList::UpdateSelected(lv_obj_t* object, lv_event_t event) {
106101 if (strcmp (options[i], " " )) {
107102 if (object == cbOption[i]) {
108103 lv_checkbox_set_checked (cbOption[i], true );
109- (settingsController.*SetOptionIndex)( MaxItems * screenID + i) ;
104+ newValue = MaxItems * screenID + i;
110105 } else {
111106 lv_checkbox_set_checked (cbOption[i], false );
112107 }
0 commit comments