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.
This commit is contained in:
parent
10ca036ffb
commit
9b775c6a91
|
@ -1,13 +1,23 @@
|
||||||
#include "displayapp/screens/ApplicationList.h"
|
#include "displayapp/screens/ApplicationList.h"
|
||||||
#include <lvgl/lvgl.h>
|
#include <lvgl/lvgl.h>
|
||||||
#include <array>
|
#include <functional>
|
||||||
#include "displayapp/screens/Symbols.h"
|
|
||||||
#include "displayapp/screens/Tile.h"
|
|
||||||
#include "displayapp/Apps.h"
|
#include "displayapp/Apps.h"
|
||||||
#include "displayapp/DisplayApp.h"
|
#include "displayapp/DisplayApp.h"
|
||||||
|
|
||||||
using namespace Pinetime::Applications::Screens;
|
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,
|
ApplicationList::ApplicationList(Pinetime::Applications::DisplayApp* app,
|
||||||
Pinetime::Controllers::Settings& settingsController,
|
Pinetime::Controllers::Settings& settingsController,
|
||||||
Pinetime::Controllers::Battery& batteryController,
|
Pinetime::Controllers::Battery& batteryController,
|
||||||
|
@ -16,18 +26,7 @@ ApplicationList::ApplicationList(Pinetime::Applications::DisplayApp* app,
|
||||||
settingsController {settingsController},
|
settingsController {settingsController},
|
||||||
batteryController {batteryController},
|
batteryController {batteryController},
|
||||||
dateTimeController {dateTimeController},
|
dateTimeController {dateTimeController},
|
||||||
screens {app,
|
screens {app, settingsController.GetAppMenu(), CreateScreenList(), Screens::ScreenListModes::UpDown} {
|
||||||
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} {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ApplicationList::~ApplicationList() {
|
ApplicationList::~ApplicationList() {
|
||||||
|
@ -38,42 +37,11 @@ bool ApplicationList::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
|
||||||
return screens.OnTouchEvent(event);
|
return screens.OnTouchEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Screen> ApplicationList::CreateScreen1() {
|
std::unique_ptr<Screen> ApplicationList::CreateScreen(unsigned int screenNum) const {
|
||||||
std::array<Screens::Tile::Applications, 6> applications {{
|
std::array<Tile::Applications, appsPerScreen> apps;
|
||||||
{Symbols::stopWatch, Apps::StopWatch},
|
for (int i = 0; i < appsPerScreen; i++) {
|
||||||
{Symbols::clock, Apps::Alarm},
|
apps[i] = applications[screenNum * appsPerScreen + i];
|
||||||
{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() {
|
return std::make_unique<Screens::Tile>(screenNum, nScreens, app, settingsController, batteryController, dateTimeController, apps);
|
||||||
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, 2, app, settingsController, batteryController, dateTimeController, applications);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*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);
|
|
||||||
}*/
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "displayapp/screens/Screen.h"
|
#include "displayapp/screens/Screen.h"
|
||||||
|
@ -7,6 +8,8 @@
|
||||||
#include "components/datetime/DateTimeController.h"
|
#include "components/datetime/DateTimeController.h"
|
||||||
#include "components/settings/Settings.h"
|
#include "components/settings/Settings.h"
|
||||||
#include "components/battery/BatteryController.h"
|
#include "components/battery/BatteryController.h"
|
||||||
|
#include "displayapp/screens/Symbols.h"
|
||||||
|
#include "displayapp/screens/Tile.h"
|
||||||
|
|
||||||
namespace Pinetime {
|
namespace Pinetime {
|
||||||
namespace Applications {
|
namespace Applications {
|
||||||
|
@ -21,14 +24,34 @@ 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::Battery& batteryController;
|
Pinetime::Controllers::Battery& batteryController;
|
||||||
Controllers::DateTime& dateTimeController;
|
Controllers::DateTime& dateTimeController;
|
||||||
|
|
||||||
ScreenList<2> screens;
|
static constexpr int appsPerScreen = 6;
|
||||||
std::unique_ptr<Screen> CreateScreen1();
|
|
||||||
std::unique_ptr<Screen> CreateScreen2();
|
// Increment this when more space is needed
|
||||||
// std::unique_ptr<Screen> CreateScreen3();
|
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;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,33 +1,27 @@
|
||||||
#include "displayapp/screens/settings/Settings.h"
|
#include "displayapp/screens/settings/Settings.h"
|
||||||
#include <lvgl/lvgl.h>
|
#include <lvgl/lvgl.h>
|
||||||
#include <array>
|
#include <functional>
|
||||||
#include "displayapp/screens/List.h"
|
|
||||||
#include "displayapp/Apps.h"
|
#include "displayapp/Apps.h"
|
||||||
#include "displayapp/DisplayApp.h"
|
#include "displayapp/DisplayApp.h"
|
||||||
#include "displayapp/screens/Symbols.h"
|
|
||||||
|
|
||||||
using namespace Pinetime::Applications::Screens;
|
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)
|
Settings::Settings(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController)
|
||||||
: Screen(app),
|
: Screen(app),
|
||||||
settingsController {settingsController},
|
settingsController {settingsController},
|
||||||
screens {app,
|
screens {app, settingsController.GetSettingsMenu(), CreateScreenList(), Screens::ScreenListModes::UpDown} {
|
||||||
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} {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings::~Settings() {
|
Settings::~Settings() {
|
||||||
|
@ -38,48 +32,11 @@ bool Settings::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
|
||||||
return screens.OnTouchEvent(event);
|
return screens.OnTouchEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Screen> Settings::CreateScreen1() {
|
std::unique_ptr<Screen> Settings::CreateScreen(unsigned int screenNum) const {
|
||||||
std::array<Screens::List::Applications, 4> applications {{
|
std::array<List::Applications, entriesPerScreen> screens;
|
||||||
{Symbols::sun, "Display", Apps::SettingDisplay},
|
for (int i = 0; i < entriesPerScreen; i++) {
|
||||||
{Symbols::eye, "Wake Up", Apps::SettingWakeUp},
|
screens[i] = entries[screenNum * entriesPerScreen + i];
|
||||||
{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() {
|
return std::make_unique<Screens::List>(screenNum, nScreens, app, settingsController, screens);
|
||||||
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},
|
|
||||||
}};
|
|
||||||
|
|
||||||
return std::make_unique<Screens::List>(3, 4, app, settingsController, applications);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
#include <array>
|
||||||
|
#include <memory>
|
||||||
#include "displayapp/screens/Screen.h"
|
#include "displayapp/screens/Screen.h"
|
||||||
#include "displayapp/screens/ScreenList.h"
|
#include "displayapp/screens/ScreenList.h"
|
||||||
|
#include "displayapp/screens/Symbols.h"
|
||||||
|
#include "displayapp/screens/List.h"
|
||||||
|
|
||||||
namespace Pinetime {
|
namespace Pinetime {
|
||||||
|
|
||||||
|
@ -17,14 +20,38 @@ namespace Pinetime {
|
||||||
bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override;
|
bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
auto CreateScreenList() const;
|
||||||
|
std::unique_ptr<Screen> CreateScreen(unsigned int screenNum) const;
|
||||||
|
|
||||||
Controllers::Settings& settingsController;
|
Controllers::Settings& settingsController;
|
||||||
|
|
||||||
ScreenList<4> screens;
|
static constexpr int entriesPerScreen = 4;
|
||||||
|
|
||||||
std::unique_ptr<Screen> CreateScreen1();
|
// Increment this when more space is needed
|
||||||
std::unique_ptr<Screen> CreateScreen2();
|
static constexpr int nScreens = 4;
|
||||||
std::unique_ptr<Screen> CreateScreen3();
|
|
||||||
std::unique_ptr<Screen> CreateScreen4();
|
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;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user