Optimize SettingWatchFace
This commit is contained in:
parent
99b5b49993
commit
bfedf47d1a
|
@ -1,32 +1,31 @@
|
|||
#include "displayapp/screens/settings/SettingWatchFace.h"
|
||||
#include <lvgl/lvgl.h>
|
||||
#include "displayapp/DisplayApp.h"
|
||||
#include "displayapp/screens/CheckboxList.h"
|
||||
#include "displayapp/screens/Screen.h"
|
||||
#include "components/settings/Settings.h"
|
||||
#include "displayapp/screens/WatchFaceInfineat.h"
|
||||
#include "displayapp/screens/WatchFaceCasioStyleG7710.h"
|
||||
|
||||
using namespace Pinetime::Applications::Screens;
|
||||
|
||||
constexpr const char* SettingWatchFace::title;
|
||||
constexpr const char* SettingWatchFace::symbol;
|
||||
|
||||
auto SettingWatchFace::CreateScreenList() const {
|
||||
std::array<std::function<std::unique_ptr<Screen>()>, nScreens> screens;
|
||||
for (size_t i = 0; i < screens.size(); i++) {
|
||||
screens[i] = [this, i]() -> std::unique_ptr<Screen> {
|
||||
return CreateScreen(i);
|
||||
};
|
||||
}
|
||||
return screens;
|
||||
}
|
||||
|
||||
SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app,
|
||||
Pinetime::Controllers::Settings& settingsController,
|
||||
Pinetime::Controllers::FS& filesystem)
|
||||
: Screen(app),
|
||||
settingsController {settingsController},
|
||||
filesystem {filesystem},
|
||||
screens {app,
|
||||
0,
|
||||
{[this]() -> std::unique_ptr<Screen> {
|
||||
return CreateScreen1();
|
||||
},
|
||||
[this]() -> std::unique_ptr<Screen> {
|
||||
return CreateScreen2();
|
||||
}},
|
||||
Screens::ScreenListModes::UpDown} {
|
||||
screens {app, 0, CreateScreenList(), Screens::ScreenListModes::UpDown} {
|
||||
}
|
||||
|
||||
SettingWatchFace::~SettingWatchFace() {
|
||||
|
@ -37,32 +36,15 @@ bool SettingWatchFace::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
|
|||
return screens.OnTouchEvent(event);
|
||||
}
|
||||
|
||||
std::unique_ptr<Screen> SettingWatchFace::CreateScreen1() {
|
||||
std::array<Screens::CheckboxList::Item, 4> watchfaces {
|
||||
{{"Digital face", true}, {"Analog face", true}, {"PineTimeStyle", true}, {"Terminal", true}}};
|
||||
return std::make_unique<Screens::CheckboxList>(
|
||||
0,
|
||||
2,
|
||||
app,
|
||||
title,
|
||||
symbol,
|
||||
settingsController.GetClockFace(),
|
||||
[&settings = settingsController](uint32_t clockFace) {
|
||||
settings.SetClockFace(clockFace);
|
||||
settings.SaveSettings();
|
||||
},
|
||||
watchfaces);
|
||||
}
|
||||
std::unique_ptr<Screen> SettingWatchFace::CreateScreen(unsigned int screenNum) const {
|
||||
std::array<Screens::CheckboxList::Item, settingsPerScreen> watchfacesOnThisScreen;
|
||||
for (int i = 0; i < settingsPerScreen; i++) {
|
||||
watchfacesOnThisScreen[i] = watchfaces[screenNum * settingsPerScreen + i];
|
||||
}
|
||||
|
||||
std::unique_ptr<Screen> SettingWatchFace::CreateScreen2() {
|
||||
std::array<Screens::CheckboxList::Item, 4> watchfaces {
|
||||
{{"Infineat face", Applications::Screens::WatchFaceInfineat::IsAvailable(filesystem)},
|
||||
{"Casio G7710", Applications::Screens::WatchFaceCasioStyleG7710::IsAvailable(filesystem)},
|
||||
{"", false},
|
||||
{"", false}}};
|
||||
return std::make_unique<Screens::CheckboxList>(
|
||||
1,
|
||||
2,
|
||||
screenNum,
|
||||
nScreens,
|
||||
app,
|
||||
title,
|
||||
symbol,
|
||||
|
@ -71,5 +53,5 @@ std::unique_ptr<Screen> SettingWatchFace::CreateScreen2() {
|
|||
settings.SetClockFace(clockFace);
|
||||
settings.SaveSettings();
|
||||
},
|
||||
watchfaces);
|
||||
watchfacesOnThisScreen);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
#include "components/settings/Settings.h"
|
||||
#include "displayapp/screens/Screen.h"
|
||||
#include "displayapp/screens/Symbols.h"
|
||||
#include "displayapp/screens/CheckboxList.h"
|
||||
#include "displayapp/screens/WatchFaceInfineat.h"
|
||||
#include "displayapp/screens/WatchFaceCasioStyleG7710.h"
|
||||
|
||||
namespace Pinetime {
|
||||
|
||||
|
@ -22,14 +25,30 @@ namespace Pinetime {
|
|||
bool OnTouchEvent(TouchEvents event) override;
|
||||
|
||||
private:
|
||||
auto CreateScreenList() const;
|
||||
std::unique_ptr<Screen> CreateScreen(unsigned int screenNum) const;
|
||||
|
||||
Controllers::Settings& settingsController;
|
||||
Pinetime::Controllers::FS& filesystem;
|
||||
ScreenList<2> screens;
|
||||
|
||||
static constexpr const char* title = "Watch face";
|
||||
static constexpr const char* symbol = Symbols::home;
|
||||
std::unique_ptr<Screen> CreateScreen1();
|
||||
std::unique_ptr<Screen> CreateScreen2();
|
||||
|
||||
static constexpr int settingsPerScreen = 4;
|
||||
|
||||
// Increment this when more space is needed
|
||||
static constexpr int nScreens = 2;
|
||||
|
||||
std::array<Screens::CheckboxList::Item, settingsPerScreen * nScreens> watchfaces {
|
||||
{{"Digital face", true},
|
||||
{"Analog face", true},
|
||||
{"PineTimeStyle", true},
|
||||
{"Terminal", true},
|
||||
{"Infineat face", Applications::Screens::WatchFaceInfineat::IsAvailable(filesystem)},
|
||||
{"Casio G7710", Applications::Screens::WatchFaceCasioStyleG7710::IsAvailable(filesystem)},
|
||||
{"", false},
|
||||
{"", false}}};
|
||||
ScreenList<nScreens> screens;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user