summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiku Isokoski <riksu9000@gmail.com>2022-05-20 08:55:40 (GMT)
committerMichele Bini <michele.bini@gmail.com>2022-06-07 03:01:47 (GMT)
commitd4224e1ce2f6825f07e23a0b1ec1963bfa03f37c (patch)
tree205372acb7abb84efe19361e27faf5f88a982803
parent6f169f67a2e7fe926092655cb68e7672b61bd8e3 (diff)
Automatically create enough screens for all apps and settings
-rw-r--r--src/displayapp/screens/ApplicationList.cpp73
-rw-r--r--src/displayapp/screens/ApplicationList.h28
-rw-r--r--src/displayapp/screens/settings/Settings.cpp83
-rw-r--r--src/displayapp/screens/settings/Settings.h34
4 files changed, 91 insertions, 127 deletions
diff --git a/src/displayapp/screens/ApplicationList.cpp b/src/displayapp/screens/ApplicationList.cpp
index de1f728..f04b9ef 100644
--- a/src/displayapp/screens/ApplicationList.cpp
+++ b/src/displayapp/screens/ApplicationList.cpp
@@ -1,13 +1,23 @@
#include "displayapp/screens/ApplicationList.h"
#include <lvgl/lvgl.h>
#include <array>
-#include "displayapp/screens/Symbols.h"
-#include "displayapp/screens/Tile.h"
#include "displayapp/Apps.h"
#include "displayapp/DisplayApp.h"
using namespace Pinetime::Applications::Screens;
+constexpr std::array<Tile::Applications, ApplicationList::applications.size()> ApplicationList::applications;
+
+auto ApplicationList::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;
+}
+
ApplicationList::ApplicationList(Pinetime::Applications::DisplayApp* app,
Pinetime::Controllers::Settings& settingsController,
Pinetime::Controllers::Battery& batteryController,
@@ -16,20 +26,7 @@ ApplicationList::ApplicationList(Pinetime::Applications::DisplayApp* app,
settingsController {settingsController},
batteryController {batteryController},
dateTimeController {dateTimeController},
- screens {app,
- settingsController.GetAppMenu(),
- {
- [this]() -> std::unique_ptr<Screen> {
- return CreateScreen1();
- },
- [this]() -> std::unique_ptr<Screen> {
- return CreateScreen2();
- },
- [this]() -> std::unique_ptr<Screen> {
- return CreateScreen3();
- }
- },
- Screens::ScreenListModes::UpDown} {
+ screens {app, settingsController.GetAppMenu(), CreateScreenList(), Screens::ScreenListModes::UpDown} {
}
ApplicationList::~ApplicationList() {
@@ -40,44 +37,12 @@ bool ApplicationList::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
return screens.OnTouchEvent(event);
}
-std::unique_ptr<Screen> ApplicationList::CreateScreen1() {
- std::array<Screens::Tile::Applications, 6> applications {{
- {Symbols::stopWatch, Apps::StopWatch},
- {Symbols::clock, Apps::Alarm},
- {Symbols::hourGlass, Apps::Timer},
- {Symbols::shoe, Apps::Steps},
- {Symbols::heartBeat, Apps::HeartRate},
- {Symbols::music, Apps::Music},
- }};
+std::unique_ptr<Screen> ApplicationList::CreateScreen(unsigned int screenNum) const {
+ std::array<Tile::Applications, 6> apps;
+ for (int i = 0; i < 6; i++) {
+ apps[i] = applications[screenNum * 6 + i];
+ }
- return std::make_unique<Screens::Tile>(0, 3, app, settingsController, batteryController, dateTimeController, applications);
+ return std::make_unique<Screens::Tile>(screenNum, nScreens, app, settingsController, batteryController, dateTimeController, apps);
}
-std::unique_ptr<Screen> ApplicationList::CreateScreen2() {
- std::array<Screens::Tile::Applications, 6> applications {{
- {Symbols::paintbrush, Apps::Paint},
- {Symbols::paddle, Apps::Paddle},
- {"2", Apps::Twos},
- {Symbols::chartLine, Apps::Motion},
- {Symbols::drum, Apps::Metronome},
- {Symbols::map, Apps::Navigation},
- }};
-
- return std::make_unique<Screens::Tile>(1, 3, app, settingsController, batteryController, dateTimeController, applications);
-}
-
-std::unique_ptr<Screen> ApplicationList::CreateScreen3() {
- std::array<Screens::Tile::Applications, 6> applications {
- {
-
- {Symbols::drum, Apps::Jumpscore},
- {"", Apps::None},
- {"B", Apps::Navigation},
- {"C", Apps::Clock},
- {"E", Apps::SysInfo},
- {"", Apps::None}
- }
- };
-
- return std::make_unique<Screens::Tile>(2, 3, app, settingsController, batteryController, dateTimeController, applications);
-}
diff --git a/src/displayapp/screens/ApplicationList.h b/src/displayapp/screens/ApplicationList.h
index 27ebbac..ac11a9b 100644
--- a/src/displayapp/screens/ApplicationList.h
+++ b/src/displayapp/screens/ApplicationList.h
@@ -7,6 +7,8 @@
#include "components/datetime/DateTimeController.h"
#include "components/settings/Settings.h"
#include "components/battery/BatteryController.h"
+#include "displayapp/screens/Symbols.h"
+#include "displayapp/screens/Tile.h"
namespace Pinetime {
namespace Applications {
@@ -21,14 +23,32 @@ 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::Battery& batteryController;
Controllers::DateTime& dateTimeController;
- ScreenList<3> screens;
- std::unique_ptr<Screen> CreateScreen1();
- std::unique_ptr<Screen> CreateScreen2();
- std::unique_ptr<Screen> CreateScreen3();
+ static constexpr std::array<Tile::Applications, 13> applications {{
+ {Symbols::stopWatch, Apps::StopWatch},
+ {Symbols::clock, Apps::Alarm},
+ {Symbols::hourGlass, Apps::Timer},
+ {Symbols::shoe, Apps::Steps},
+ {Symbols::heartBeat, Apps::HeartRate},
+ {Symbols::music, Apps::Music},
+
+ {Symbols::paintbrush, Apps::Paint},
+ {Symbols::paddle, Apps::Paddle},
+ {"2", Apps::Twos},
+ {Symbols::chartLine, Apps::Motion},
+ {Symbols::drum, Apps::Metronome},
+ {Symbols::map, Apps::Navigation},
+
+ {Symbols::drum, Apps::Jumpscore},
+ }};
+ static constexpr int nScreens = (applications.size() + 5) / 6;
+ ScreenList<nScreens> screens;
};
}
}
diff --git a/src/displayapp/screens/settings/Settings.cpp b/src/displayapp/screens/settings/Settings.cpp
index a91b8f7..98d8c22 100644
--- a/src/displayapp/screens/settings/Settings.cpp
+++ b/src/displayapp/screens/settings/Settings.cpp
@@ -1,33 +1,27 @@
#include "displayapp/screens/settings/Settings.h"
#include <lvgl/lvgl.h>
#include <array>
-#include "displayapp/screens/List.h"
-#include "displayapp/Apps.h"
#include "displayapp/DisplayApp.h"
-#include "displayapp/screens/Symbols.h"
+#include "displayapp/Apps.h"
using namespace Pinetime::Applications::Screens;
+constexpr std::array<List::Applications, Settings::entries.size()> Settings::entries;
+
+auto Settings::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;
+}
+
Settings::Settings(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController)
: Screen(app),
settingsController {settingsController},
- screens {app,
- settingsController.GetSettingsMenu(),
- {
- [this]() -> std::unique_ptr<Screen> {
- return CreateScreen1();
- },
- [this]() -> std::unique_ptr<Screen> {
- return CreateScreen2();
- },
- [this]() -> std::unique_ptr<Screen> {
- return CreateScreen3();
- },
- [this]() -> std::unique_ptr<Screen> {
- return CreateScreen4();
- },
- },
- Screens::ScreenListModes::UpDown} {
+ screens {app, settingsController.GetSettingsMenu(), CreateScreenList(), Screens::ScreenListModes::UpDown} {
}
Settings::~Settings() {
@@ -38,48 +32,11 @@ bool Settings::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
return screens.OnTouchEvent(event);
}
-std::unique_ptr<Screen> Settings::CreateScreen1() {
- std::array<Screens::List::Applications, 4> applications {{
- {Symbols::sun, "Display", Apps::SettingDisplay},
- {Symbols::eye, "Wake Up", Apps::SettingWakeUp},
- {Symbols::clock, "Time format", Apps::SettingTimeFormat},
- {Symbols::home, "Watch face", Apps::SettingWatchFace},
- }};
-
- return std::make_unique<Screens::List>(0, 4, app, settingsController, applications);
-}
-
-std::unique_ptr<Screen> Settings::CreateScreen2() {
- std::array<Screens::List::Applications, 4> applications {{
- {Symbols::shoe, "Steps", Apps::SettingSteps},
- {Symbols::clock, "Set date", Apps::SettingSetDate},
- {Symbols::clock, "Set time", Apps::SettingSetTime},
- {Symbols::batteryHalf, "Battery", Apps::BatteryInfo},
- }};
-
- return std::make_unique<Screens::List>(1, 4, app, settingsController, applications);
-}
-
-std::unique_ptr<Screen> Settings::CreateScreen3() {
-
- std::array<Screens::List::Applications, 4> applications {{
- {Symbols::clock, "Chimes", Apps::SettingChimes},
- {Symbols::tachometer, "Shake Calib.", Apps::SettingShakeThreshold},
- {Symbols::check, "Firmware", Apps::FirmwareValidation},
- {Symbols::bluetooth, "Bluetooth", Apps::SettingBluetooth},
- }};
-
- return std::make_unique<Screens::List>(2, 4, app, settingsController, applications);
-}
-
-std::unique_ptr<Screen> Settings::CreateScreen4() {
-
- std::array<Screens::List::Applications, 4> applications {{
- {Symbols::list, "About", Apps::SysInfo},
- {Symbols::none, "None", Apps::None},
- {Symbols::none, "None", Apps::None},
- {Symbols::none, "None", Apps::None},
- }};
+std::unique_ptr<Screen> Settings::CreateScreen(unsigned int screenNum) const {
+ std::array<List::Applications, 4> screens;
+ for (int i = 0; i < 4; i++) {
+ screens[i] = entries[screenNum * 4 + i];
+ }
- return std::make_unique<Screens::List>(3, 4, app, settingsController, applications);
+ return std::make_unique<Screens::List>(screenNum, nScreens, app, settingsController, screens);
}
diff --git a/src/displayapp/screens/settings/Settings.h b/src/displayapp/screens/settings/Settings.h
index be09007..4ef507a 100644
--- a/src/displayapp/screens/settings/Settings.h
+++ b/src/displayapp/screens/settings/Settings.h
@@ -3,6 +3,8 @@
#include <cstdint>
#include "displayapp/screens/Screen.h"
#include "displayapp/screens/ScreenList.h"
+#include "displayapp/screens/Symbols.h"
+#include "displayapp/screens/List.h"
namespace Pinetime {
@@ -17,14 +19,34 @@ namespace Pinetime {
bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override;
private:
- Controllers::Settings& settingsController;
+ auto CreateScreenList() const;
+ std::unique_ptr<Screen> CreateScreen(unsigned int screenNum) const;
- ScreenList<4> screens;
+ Controllers::Settings& settingsController;
- std::unique_ptr<Screen> CreateScreen1();
- std::unique_ptr<Screen> CreateScreen2();
- std::unique_ptr<Screen> CreateScreen3();
- std::unique_ptr<Screen> CreateScreen4();
+ static constexpr std::array<List::Applications, 16> entries {{
+ {Symbols::sun, "Display", Apps::SettingDisplay},
+ {Symbols::eye, "Wake Up", Apps::SettingWakeUp},
+ {Symbols::clock, "Time format", Apps::SettingTimeFormat},
+ {Symbols::home, "Watch face", Apps::SettingWatchFace},
+
+ {Symbols::shoe, "Steps", Apps::SettingSteps},
+ {Symbols::clock, "Set date", Apps::SettingSetDate},
+ {Symbols::clock, "Set time", Apps::SettingSetTime},
+ {Symbols::batteryHalf, "Battery", Apps::BatteryInfo},
+
+ {Symbols::clock, "Chimes", Apps::SettingChimes},
+ {Symbols::tachometer, "Shake Calib.", Apps::SettingShakeThreshold},
+ {Symbols::check, "Firmware", Apps::FirmwareValidation},
+ {Symbols::bluetooth, "Bluetooth", Apps::SettingBluetooth},
+
+ {Symbols::list, "About", Apps::SysInfo},
+ {Symbols::none, "None", Apps::None},
+ {Symbols::none, "None", Apps::None},
+ {Symbols::none, "None", Apps::None},
+ }};
+ static constexpr int nScreens = (entries.size() + 3) / 4;
+ ScreenList<nScreens> screens;
};
}
}