Skip to content

Commit 85a0542

Browse files
NeroBurnermark9064
authored andcommitted
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`.
1 parent 8423ed6 commit 85a0542

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

src/displayapp/DisplayApp.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
#include "libs/lv_conf.h"
5555
#include "UserApps.h"
5656

57+
#include <algorithm>
58+
5759
using namespace Pinetime::Applications;
5860
using namespace Pinetime::Applications::Display;
5961

@@ -516,10 +518,9 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
516518
switch (app) {
517519
case Apps::Launcher: {
518520
std::array<Screens::Tile::Applications, UserAppTypes::Count> apps;
519-
int i = 0;
520-
for (const auto& userApp : userApps) {
521-
apps[i++] = Screens::Tile::Applications {userApp.icon, userApp.app, true};
522-
}
521+
std::ranges::transform(userApps, apps.begin(), [](const auto& userApp) {
522+
return Screens::Tile::Applications {userApp.icon, userApp.app, true};
523+
});
523524
currentScreen = std::make_unique<Screens::ApplicationList>(this,
524525
settingsController,
525526
batteryController,
@@ -530,13 +531,12 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
530531
std::move(apps));
531532
} break;
532533
case Apps::Clock: {
533-
const auto* watchFace =
534-
std::find_if(userWatchFaces.begin(), userWatchFaces.end(), [this](const WatchFaceDescription& watchfaceDescription) {
535-
return watchfaceDescription.watchFace == settingsController.GetWatchFace();
536-
});
537-
if (watchFace != userWatchFaces.end())
534+
const auto* watchFace = std::ranges::find_if(userWatchFaces, [this](const WatchFaceDescription& watchfaceDescription) {
535+
return watchfaceDescription.watchFace == settingsController.GetWatchFace();
536+
});
537+
if (watchFace != userWatchFaces.end()) {
538538
currentScreen.reset(watchFace->create(controllers));
539-
else {
539+
} else {
540540
currentScreen.reset(userWatchFaces[0].create(controllers));
541541
}
542542
settingsController.SetAppMenu(0);
@@ -587,11 +587,11 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
587587
break;
588588
case Apps::SettingWatchFace: {
589589
std::array<Screens::SettingWatchFace::Item, UserWatchFaceTypes::Count> items;
590-
int i = 0;
591-
for (const auto& userWatchFace : userWatchFaces) {
592-
items[i++] =
593-
Screens::SettingWatchFace::Item {userWatchFace.name, userWatchFace.watchFace, userWatchFace.isAvailable(controllers.filesystem)};
594-
}
590+
std::ranges::transform(userWatchFaces, items.begin(), [this](const WatchFaceDescription& userWatchFace) {
591+
return Screens::SettingWatchFace::Item {userWatchFace.name,
592+
userWatchFace.watchFace,
593+
userWatchFace.isAvailable(controllers.filesystem)};
594+
});
595595
currentScreen = std::make_unique<Screens::SettingWatchFace>(this, std::move(items), settingsController, filesystem);
596596
} break;
597597
case Apps::SettingTimeFormat:
@@ -639,7 +639,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
639639
currentScreen = std::make_unique<Screens::FlashLight>(*systemTask, brightnessController);
640640
break;
641641
default: {
642-
const auto* d = std::find_if(userApps.begin(), userApps.end(), [app](const AppDescription& appDescription) {
642+
const auto* d = std::ranges::find_if(userApps, [app](const AppDescription& appDescription) {
643643
return appDescription.app == app;
644644
});
645645
if (d != userApps.end()) {

0 commit comments

Comments
 (0)