summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiku Isokoski <riksu9000@gmail.com>2022-06-16 22:41:54 +0300
committerGitHub <noreply@github.com>2022-06-16 21:41:54 +0200
commit9b775c6a91b91531edda67892b93041e5fb3f882 (patch)
tree7b2f4e4f4c1e96211de2e0eab8e9d0c1cb95bbd9
parent10ca036ffb09e1921b7ea684816b7cd9f5b0f510 (diff)
Automatically create screens for applist and settings (#1153)
Apps and settings are now stored in a single array (two arrays in total). Replace magic values with appsPerScreen and entriesPerScreen.
-rw-r--r--src/displayapp/screens/ApplicationList.cpp72
-rw-r--r--src/displayapp/screens/ApplicationList.h31
-rw-r--r--src/displayapp/screens/settings/Settings.cpp83
-rw-r--r--src/displayapp/screens/settings/Settings.h41
4 files changed, 101 insertions, 126 deletions
diff --git a/src/displayapp/screens/ApplicationList.cpp b/src/displayapp/screens/ApplicationList.cpp
index 9798a861..9fd408e1 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 <functional>
#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,18 +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() {
@@ -38,42 +37,11 @@ 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},
- }};
-
- return std::make_unique<Screens::Tile>(0, 2, app, settingsController, batteryController, dateTimeController, applications);
-}
-
-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},
- }};
+std::unique_ptr<Screen> ApplicationList::CreateScreen(unsigned int screenNum) const {
+ std::array<Tile::Applications, appsPerScreen> apps;
+ for (int i = 0; i < appsPerScreen; i++) {
+ apps[i] = applications[screenNum * appsPerScreen + i];
+ }
- return std::make_unique<Screens::Tile>(1, 2, app, settingsController, batteryController, dateTimeController, applications);
+ return std::make_unique<Screens::Tile>(screenNum, nScreens, app, settingsController, batteryController, dateTimeController, apps);
}
-
-/*std::unique_ptr<Screen> ApplicationList::CreateScreen3() {
- std::array<Screens::Tile::Applications, 6> applications {
- {{"A", Apps::Meter},
- {"B", Apps::Navigation},
- {"C", Apps::Clock},
- {"D", Apps::Music},
- {"E", Apps::SysInfo},
- {"F", Apps::Brightness}
- }
- };
-
- 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 f430a89e..14d7623c 100644
--- a/src/displayapp/screens/ApplicationList.h
+++ b/src/displayapp/screens/ApplicationList.h
@@ -1,5 +1,6 @@
#pragma once
+#include <array>
#include <memory>
#include "displayapp/screens/Screen.h"
@@ -7,6 +8,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 +24,34 @@ 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<2> screens;
- std::unique_ptr<Screen> CreateScreen1();
- std::unique_ptr<Screen> CreateScreen2();
- // std::unique_ptr<Screen> CreateScreen3();
+ static constexpr int appsPerScreen = 6;
+
+ // Increment this when more space is needed
+ static constexpr int nScreens = 2;
+
+ static constexpr std::array<Tile::Applications, appsPerScreen * nScreens> 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},
+ }};
+ ScreenList<nScreens> screens;
};
}
}
diff --git a/src/displayapp/screens/settings/Settings.cpp b/src/displayapp/screens/settings/Settings.cpp
index a91b8f77..ffa01d18 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 <functional>
#include "displayapp/Apps.h"
#include "displayapp/DisplayApp.h"
-#include "displayapp/screens/Symbols.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, entriesPerScreen> screens;
+ for (int i = 0; i < entriesPerScreen; i++) {
+ screens[i] = entries[screenNum * entriesPerScreen + 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 be090075..a86db44f 100644
--- a/src/displayapp/screens/settings/Settings.h
+++ b/src/displayapp/screens/settings/Settings.h
@@ -1,8 +1,11 @@
#pragma once
-#include <cstdint>
+#include <array>
+#include <memory>
#include "displayapp/screens/Screen.h"
#include "displayapp/screens/ScreenList.h"
+#include "displayapp/screens/Symbols.h"
+#include "displayapp/screens/List.h"
namespace Pinetime {
@@ -17,14 +20,38 @@ 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 int entriesPerScreen = 4;
+
+ // Increment this when more space is needed
+ static constexpr int nScreens = 4;
+
+ static constexpr std::array<List::Applications, entriesPerScreen * nScreens> 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},
+ }};
+ ScreenList<nScreens> screens;
};
}
}