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:
Riku Isokoski
2022-06-16 22:41:54 +03:00
committed by GitHub
parent 10ca036ffb
commit 9b775c6a91
4 changed files with 100 additions and 125 deletions

View File

@@ -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},
}};
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>(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},
}};
return std::make_unique<Screens::List>(3, 4, app, settingsController, applications);
return std::make_unique<Screens::List>(screenNum, nScreens, app, settingsController, screens);
}