-
-
Notifications
You must be signed in to change notification settings - Fork 984
/
Copy pathSettingClockFormat.cpp
61 lines (54 loc) · 1.87 KB
/
SettingClockFormat.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "displayapp/screens/settings/SettingClockFormat.h"
#include <lvgl/lvgl.h>
#include "displayapp/DisplayApp.h"
#include "displayapp/screens/Styles.h"
#include "displayapp/screens/Screen.h"
#include "displayapp/screens/Symbols.h"
using namespace Pinetime::Applications::Screens;
namespace {
struct ClockOption {
Pinetime::Controllers::Settings::ClockType clockType;
const char* name;
};
constexpr std::array<ClockOption, 2> clockOptions = {{
{Pinetime::Controllers::Settings::ClockType::H12, "12-hour"},
{Pinetime::Controllers::Settings::ClockType::H24, "24-hour"},
}};
std::array<CheckboxList::Item, CheckboxList::MaxItems> CreateClockOptionArray() {
std::array<Pinetime::Applications::Screens::CheckboxList::Item, CheckboxList::MaxItems> clockOptionArray;
for (size_t i = 0; i < CheckboxList::MaxItems; i++) {
if (i >= clockOptions.size()) {
clockOptionArray[i].name = "";
clockOptionArray[i].enabled = false;
} else {
clockOptionArray[i].name = clockOptions[i].name;
clockOptionArray[i].enabled = true;
}
}
return clockOptionArray;
}
uint32_t GetDefaultClockOption(Pinetime::Controllers::Settings::ClockType currentOption) {
for (size_t i = 0; i < clockOptions.size(); i++) {
if (clockOptions[i].clockType == currentOption) {
return i;
}
}
return 0;
}
}
SettingClockFormat::SettingClockFormat(Pinetime::Controllers::Settings& settingsController)
: clockCheckboxList(
0,
1,
"Time format",
Symbols::clock,
GetDefaultClockOption(settingsController.GetClockType()),
[&settings = settingsController](uint32_t index) {
settings.SetClockType(clockOptions[index].clockType);
settings.SaveSettings();
},
CreateClockOptionArray()) {
}
SettingClockFormat::~SettingClockFormat() {
lv_obj_clean(lv_scr_act());
}