From 39bc166e549e8ccae75468aa2dd3613d51f54e27 Mon Sep 17 00:00:00 2001 From: Jean-François Milants Date: Sun, 10 Dec 2023 18:35:19 +0100 Subject: Watch face selection at build time Watch faces can now be selected at buid time. It's implemented in a similar way than the selection of user apps, using a list of watch face description that is generated at build time (consteval, constexpr) --- src/displayapp/DisplayApp.cpp | 48 ++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 26 deletions(-) (limited to 'src/displayapp/DisplayApp.cpp') diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 98be6324..3b34d7b8 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -11,7 +11,6 @@ #include "components/motion/MotionController.h" #include "components/motor/MotorController.h" #include "displayapp/screens/ApplicationList.h" -#include "displayapp/screens/Clock.h" #include "displayapp/screens/FirmwareUpdate.h" #include "displayapp/screens/FirmwareValidation.h" #include "displayapp/screens/InfiniPaint.h" @@ -435,17 +434,17 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio filesystem, std::move(apps)); } break; - case Apps::Clock: - currentScreen = std::make_unique(dateTimeController, - batteryController, - bleController, - notificationManager, - settingsController, - heartRateController, - motionController, - systemTask->nimble().weather(), - filesystem); - break; + case Apps::Clock: { + const auto* watchFace = + std::find_if(userWatchFaces.begin(), userWatchFaces.end(), [this](const WatchFaceDescription& watchfaceDescription) { + return watchfaceDescription.watchFace == settingsController.GetWatchFace(); + }); + if (watchFace != userWatchFaces.end()) + currentScreen.reset(watchFace->create(controllers)); + else { + currentScreen.reset(userWatchFaces[0].create(controllers)); + } + } break; case Apps::Error: currentScreen = std::make_unique(bootError); break; @@ -489,9 +488,14 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio case Apps::Settings: currentScreen = std::make_unique(this, settingsController); break; - case Apps::SettingWatchFace: - currentScreen = std::make_unique(this, settingsController, filesystem); - break; + case Apps::SettingWatchFace: { + std::array items; + int i = 0; + for (const auto& userWatchFace : userWatchFaces) { + items[i++] = Screens::CheckboxList::Item {userWatchFace.name, userWatchFace.isAvailable(controllers.filesystem)}; + } + currentScreen = std::make_unique(this, std::move(items), settingsController, filesystem); + } break; case Apps::SettingTimeFormat: currentScreen = std::make_unique(settingsController); break; @@ -536,18 +540,10 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio const auto* d = std::find_if(userApps.begin(), userApps.end(), [app](const AppDescription& appDescription) { return appDescription.app == app; }); - if (d != userApps.end()) + if (d != userApps.end()) { currentScreen.reset(d->create(controllers)); - else { - currentScreen = std::make_unique(dateTimeController, - batteryController, - bleController, - notificationManager, - settingsController, - heartRateController, - motionController, - systemTask->nimble().weather(), - filesystem); + } else { + currentScreen.reset(userWatchFaces[0].create(controllers)); } break; } -- cgit v1.2.3-70-g09d2