Skip to content

Commit a3bfbb5

Browse files
committed
Implement SettingWatchFace list
1 parent b561e7f commit a3bfbb5

File tree

4 files changed

+55
-62
lines changed

4 files changed

+55
-62
lines changed

src/components/settings/Settings.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ namespace Pinetime {
133133
return settingsMenu;
134134
};
135135

136+
void SetWatchfacesMenu(uint8_t menu) {
137+
watchFacesMenu = menu;
138+
};
139+
140+
uint8_t GetWatchfacesMenu() const {
141+
return watchFacesMenu;
142+
};
143+
136144
void SetClockType(ClockType clocktype) {
137145
if (clocktype != settings.clockType) {
138146
settingsChanged = true;
@@ -262,6 +270,7 @@ namespace Pinetime {
262270

263271
uint8_t appMenu = 0;
264272
uint8_t settingsMenu = 0;
273+
uint8_t watchFacesMenu = 0;
265274
/* ble state is intentionally not saved with the other watch settings and initialized
266275
* to off (false) on every boot because we always want ble to be enabled on startup
267276
*/

src/displayapp/screens/Clock.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ Clock::Clock(DisplayApp* app,
4343
case 2:
4444
return WatchFacePineTimeStyleScreen();
4545
break;
46-
// case 3:
47-
// return WatchFaceTerminalScreen();
48-
// break;
4946
case 3:
47+
return WatchFaceTerminalScreen();
48+
break;
49+
case 4:
5050
return WatchFaceInfineatScreen();
5151
break;
5252
}
Lines changed: 35 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,54 @@
11
#include "displayapp/screens/settings/SettingWatchFace.h"
22
#include <lvgl/lvgl.h>
33
#include "displayapp/DisplayApp.h"
4+
#include "displayapp/screens/CheckboxList.h"
45
#include "displayapp/screens/Screen.h"
56
#include "displayapp/screens/Styles.h"
67
#include "displayapp/screens/Symbols.h"
8+
#include "components/settings/Settings.h"
79

810
using namespace Pinetime::Applications::Screens;
911

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;
1814

1915
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} {
5729
}
5830

5931
SettingWatchFace::~SettingWatchFace() {
6032
lv_obj_clean(lv_scr_act());
6133
settingsController.SaveSettings();
6234
}
6335

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);
7554
}

src/displayapp/screens/settings/SettingWatchFace.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
#include <cstdint>
55
#include <lvgl/lvgl.h>
66

7+
#include "displayapp/screens/ScreenList.h"
78
#include "components/settings/Settings.h"
89
#include "displayapp/screens/Screen.h"
10+
#include "displayapp/screens/Symbols.h"
911

1012
namespace Pinetime {
1113

@@ -17,13 +19,16 @@ namespace Pinetime {
1719
SettingWatchFace(DisplayApp* app, Pinetime::Controllers::Settings& settingsController);
1820
~SettingWatchFace() override;
1921

20-
void UpdateSelected(lv_obj_t* object, lv_event_t event);
22+
bool OnTouchEvent(TouchEvents event) override;
2123

2224
private:
23-
static constexpr std::array<const char*, 4> options = {" Digital face", " Analog face", " PineTimeStyle", " Terminal"};
2425
Controllers::Settings& settingsController;
26+
ScreenList<2> screens;
2527

26-
lv_obj_t* cbOption[options.size()];
28+
static constexpr const char* title = "Watch face";
29+
static constexpr const char* symbol = Symbols::home;
30+
std::unique_ptr<Screen> CreateScreen1();
31+
std::unique_ptr<Screen> CreateScreen2();
2732
};
2833
}
2934
}

0 commit comments

Comments
 (0)