Checkbox list now receives a function pointer to call when the setting has changed. This allow to remove the dependency between CheckBoxList (UI component) with SettingController.
This commit is contained in:
parent
6dd67eb5a2
commit
cf8b422899
|
@ -52,6 +52,11 @@ namespace Pinetime {
|
|||
|
||||
Settings(Pinetime::Controllers::FS& fs);
|
||||
|
||||
Settings(const Settings&) = delete;
|
||||
Settings& operator=(const Settings&) = delete;
|
||||
Settings(Settings&&) = delete;
|
||||
Settings& operator=(Settings&&) = delete;
|
||||
|
||||
void Init();
|
||||
void SaveSettings();
|
||||
|
||||
|
@ -135,14 +140,6 @@ namespace Pinetime {
|
|||
appMenu = menu;
|
||||
};
|
||||
|
||||
void SetWatchfacesMenu(uint8_t menu) {
|
||||
watchFacesMenu = menu;
|
||||
};
|
||||
|
||||
uint8_t GetWatchfacesMenu() const {
|
||||
return watchFacesMenu;
|
||||
};
|
||||
|
||||
uint8_t GetAppMenu() const {
|
||||
return appMenu;
|
||||
};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "displayapp/screens/CheckboxList.h"
|
||||
#include "displayapp/DisplayApp.h"
|
||||
#include "displayapp/screens/CheckboxList.h"
|
||||
#include "displayapp/screens/Styles.h"
|
||||
|
||||
using namespace Pinetime::Applications::Screens;
|
||||
|
@ -9,27 +9,21 @@ namespace {
|
|||
CheckboxList* screen = static_cast<CheckboxList*>(obj->user_data);
|
||||
screen->UpdateSelected(obj, event);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
CheckboxList::CheckboxList(const uint8_t screenID,
|
||||
const uint8_t numScreens,
|
||||
DisplayApp* app,
|
||||
Controllers::Settings& settingsController,
|
||||
const char* optionsTitle,
|
||||
const char* optionsSymbol,
|
||||
void (Controllers::Settings::*SetOptionIndex)(uint8_t),
|
||||
uint8_t (Controllers::Settings::*GetOptionIndex)() const,
|
||||
uint32_t originalValue,
|
||||
std::function<void(uint32_t)>OnValueChanged,
|
||||
std::array<const char*, MaxItems> options)
|
||||
: Screen(app),
|
||||
screenID {screenID},
|
||||
settingsController {settingsController},
|
||||
SetOptionIndex {SetOptionIndex},
|
||||
GetOptionIndex {GetOptionIndex},
|
||||
options {options} {
|
||||
|
||||
settingsController.SetWatchfacesMenu(screenID);
|
||||
|
||||
OnValueChanged{std::move(OnValueChanged)},
|
||||
options {options},
|
||||
newValue{originalValue} {
|
||||
// Set the background to Black
|
||||
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
|
||||
|
||||
|
@ -39,7 +33,7 @@ CheckboxList::CheckboxList(const uint8_t screenID,
|
|||
pageIndicatorBasePoints[1].x = LV_HOR_RES - 1;
|
||||
pageIndicatorBasePoints[1].y = LV_VER_RES;
|
||||
|
||||
pageIndicatorBase = lv_line_create(lv_scr_act(), NULL);
|
||||
pageIndicatorBase = lv_line_create(lv_scr_act(), nullptr);
|
||||
lv_obj_set_style_local_line_width(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3);
|
||||
lv_obj_set_style_local_line_color(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111));
|
||||
lv_line_set_points(pageIndicatorBase, pageIndicatorBasePoints.data(), 2);
|
||||
|
@ -52,7 +46,7 @@ CheckboxList::CheckboxList(const uint8_t screenID,
|
|||
pageIndicatorPoints[1].x = LV_HOR_RES - 1;
|
||||
pageIndicatorPoints[1].y = indicatorPos + indicatorSize;
|
||||
|
||||
pageIndicator = lv_line_create(lv_scr_act(), NULL);
|
||||
pageIndicator = lv_line_create(lv_scr_act(), nullptr);
|
||||
lv_obj_set_style_local_line_width(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3);
|
||||
lv_obj_set_style_local_line_color(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
|
||||
lv_line_set_points(pageIndicator, pageIndicatorPoints.data(), 2);
|
||||
|
@ -89,7 +83,7 @@ CheckboxList::CheckboxList(const uint8_t screenID,
|
|||
lv_obj_set_event_cb(cbOption[i], event_handler);
|
||||
SetRadioButtonStyle(cbOption[i]);
|
||||
|
||||
if (static_cast<unsigned int>((settingsController.*GetOptionIndex)() - MaxItems * screenID) == i) {
|
||||
if (static_cast<unsigned int>(originalValue - MaxItems * screenID) == i) {
|
||||
lv_checkbox_set_checked(cbOption[i], true);
|
||||
}
|
||||
}
|
||||
|
@ -98,6 +92,7 @@ CheckboxList::CheckboxList(const uint8_t screenID,
|
|||
|
||||
CheckboxList::~CheckboxList() {
|
||||
lv_obj_clean(lv_scr_act());
|
||||
OnValueChanged(newValue);
|
||||
}
|
||||
|
||||
void 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) {
|
|||
if (strcmp(options[i], "")) {
|
||||
if (object == cbOption[i]) {
|
||||
lv_checkbox_set_checked(cbOption[i], true);
|
||||
(settingsController.*SetOptionIndex)(MaxItems * screenID + i);
|
||||
newValue = MaxItems * screenID + i;
|
||||
} else {
|
||||
lv_checkbox_set_checked(cbOption[i], false);
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <lvgl/lvgl.h>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <array>
|
||||
#include "displayapp/screens/Screen.h"
|
||||
#include "displayapp/Apps.h"
|
||||
#include "components/settings/Settings.h"
|
||||
#include "displayapp/screens/Screen.h"
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <lvgl/lvgl.h>
|
||||
#include <memory>
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Applications {
|
||||
|
@ -14,34 +14,27 @@ namespace Pinetime {
|
|||
class CheckboxList : public Screen {
|
||||
public:
|
||||
static constexpr size_t MaxItems = 4;
|
||||
|
||||
CheckboxList(const uint8_t screenID,
|
||||
const uint8_t numScreens,
|
||||
DisplayApp* app,
|
||||
Controllers::Settings& settingsController,
|
||||
const char* optionsTitle,
|
||||
const char* optionsSymbol,
|
||||
void (Controllers::Settings::*SetOptionIndex)(uint8_t),
|
||||
uint8_t (Controllers::Settings::*GetOptionIndex)() const,
|
||||
uint32_t originalValue,
|
||||
std::function<void(uint32_t)>OnValueChanged,
|
||||
std::array<const char*, MaxItems> options);
|
||||
|
||||
~CheckboxList() override;
|
||||
|
||||
void UpdateSelected(lv_obj_t* object, lv_event_t event);
|
||||
|
||||
private:
|
||||
const uint8_t screenID;
|
||||
Controllers::Settings& settingsController;
|
||||
const char* optionsTitle;
|
||||
const char* optionsSymbol;
|
||||
void (Controllers::Settings::*SetOptionIndex)(uint8_t);
|
||||
uint8_t (Controllers::Settings::*GetOptionIndex)() const;
|
||||
std::function<void(uint32_t)>OnValueChanged;
|
||||
std::array<const char*, MaxItems> options;
|
||||
std::array<lv_obj_t*, MaxItems> cbOption;
|
||||
std::array<lv_point_t, 2> pageIndicatorBasePoints;
|
||||
std::array<lv_point_t, 2> pageIndicatorPoints;
|
||||
lv_obj_t* pageIndicatorBase;
|
||||
lv_obj_t* pageIndicator;
|
||||
uint32_t newValue;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
#include "displayapp/DisplayApp.h"
|
||||
#include "displayapp/screens/CheckboxList.h"
|
||||
#include "displayapp/screens/Screen.h"
|
||||
#include "displayapp/screens/Styles.h"
|
||||
#include "displayapp/screens/Symbols.h"
|
||||
#include "components/settings/Settings.h"
|
||||
|
||||
using namespace Pinetime::Applications::Screens;
|
||||
|
@ -16,7 +14,7 @@ SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app, Pine
|
|||
: Screen(app),
|
||||
settingsController {settingsController},
|
||||
screens {app,
|
||||
settingsController.GetWatchfacesMenu(),
|
||||
0,
|
||||
{[this]() -> std::unique_ptr<Screen> {
|
||||
return CreateScreen1();
|
||||
},
|
||||
|
@ -28,7 +26,6 @@ SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app, Pine
|
|||
|
||||
SettingWatchFace::~SettingWatchFace() {
|
||||
lv_obj_clean(lv_scr_act());
|
||||
settingsController.SaveSettings();
|
||||
}
|
||||
|
||||
bool SettingWatchFace::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
|
||||
|
@ -40,11 +37,13 @@ std::unique_ptr<Screen> SettingWatchFace::CreateScreen1() {
|
|||
return std::make_unique<Screens::CheckboxList>(0,
|
||||
2,
|
||||
app,
|
||||
settingsController,
|
||||
title,
|
||||
symbol,
|
||||
&Controllers::Settings::SetClockFace,
|
||||
&Controllers::Settings::GetClockFace,
|
||||
settingsController.GetClockFace(),
|
||||
[&settings = settingsController](uint32_t clockFace) {
|
||||
settings.SetClockFace(clockFace);
|
||||
settings.SaveSettings();
|
||||
},
|
||||
watchfaces);
|
||||
}
|
||||
|
||||
|
@ -53,10 +52,12 @@ std::unique_ptr<Screen> SettingWatchFace::CreateScreen2() {
|
|||
return std::make_unique<Screens::CheckboxList>(1,
|
||||
2,
|
||||
app,
|
||||
settingsController,
|
||||
title,
|
||||
symbol,
|
||||
&Controllers::Settings::SetClockFace,
|
||||
&Controllers::Settings::GetClockFace,
|
||||
settingsController.GetClockFace(),
|
||||
[&settings = settingsController](uint32_t clockFace) {
|
||||
settings.SetClockFace(clockFace);
|
||||
settings.SaveSettings();
|
||||
},
|
||||
watchfaces);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user