DisplayApp: use std::ranges function where possible

Instead of raw for loops use `std::ranges::transform` where possible.
And also use `std::ranges::find_if` instead of `std::find_if`.
This commit is contained in:
Reinhold Gschweicher 2025-05-24 21:59:43 +02:00 committed by mark9064
parent 8423ed675b
commit 85a0542d93

View file

@ -54,6 +54,8 @@
#include "libs/lv_conf.h"
#include "UserApps.h"
#include <algorithm>
using namespace Pinetime::Applications;
using namespace Pinetime::Applications::Display;
@ -516,10 +518,9 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
switch (app) {
case Apps::Launcher: {
std::array<Screens::Tile::Applications, UserAppTypes::Count> apps;
int i = 0;
for (const auto& userApp : userApps) {
apps[i++] = Screens::Tile::Applications {userApp.icon, userApp.app, true};
}
std::ranges::transform(userApps, apps.begin(), [](const auto& userApp) {
return Screens::Tile::Applications {userApp.icon, userApp.app, true};
});
currentScreen = std::make_unique<Screens::ApplicationList>(this,
settingsController,
batteryController,
@ -530,13 +531,12 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
std::move(apps));
} 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())
const auto* watchFace = std::ranges::find_if(userWatchFaces, [this](const WatchFaceDescription& watchfaceDescription) {
return watchfaceDescription.watchFace == settingsController.GetWatchFace();
});
if (watchFace != userWatchFaces.end()) {
currentScreen.reset(watchFace->create(controllers));
else {
} else {
currentScreen.reset(userWatchFaces[0].create(controllers));
}
settingsController.SetAppMenu(0);
@ -587,11 +587,11 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
break;
case Apps::SettingWatchFace: {
std::array<Screens::SettingWatchFace::Item, UserWatchFaceTypes::Count> items;
int i = 0;
for (const auto& userWatchFace : userWatchFaces) {
items[i++] =
Screens::SettingWatchFace::Item {userWatchFace.name, userWatchFace.watchFace, userWatchFace.isAvailable(controllers.filesystem)};
}
std::ranges::transform(userWatchFaces, items.begin(), [this](const WatchFaceDescription& userWatchFace) {
return Screens::SettingWatchFace::Item {userWatchFace.name,
userWatchFace.watchFace,
userWatchFace.isAvailable(controllers.filesystem)};
});
currentScreen = std::make_unique<Screens::SettingWatchFace>(this, std::move(items), settingsController, filesystem);
} break;
case Apps::SettingTimeFormat:
@ -639,7 +639,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
currentScreen = std::make_unique<Screens::FlashLight>(*systemTask, brightnessController);
break;
default: {
const auto* d = std::find_if(userApps.begin(), userApps.end(), [app](const AppDescription& appDescription) {
const auto* d = std::ranges::find_if(userApps, [app](const AppDescription& appDescription) {
return appDescription.app == app;
});
if (d != userApps.end()) {