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