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