diff options
| author | Reinhold Gschweicher <pyro4hell@gmail.com> | 2025-05-24 21:59:43 +0200 |
|---|---|---|
| committer | mark9064 <30447455+mark9064@users.noreply.github.com> | 2025-05-30 22:57:12 +0100 |
| commit | 85a0542d936066a90b74316b686dd911c1451d58 (patch) | |
| tree | 435996b5cbd547fa922e490c374845a66cdb3518 /src/displayapp | |
| parent | 8423ed675bf195bc81be19c78106bae860c8e2b8 (diff) | |
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`.
Diffstat (limited to 'src/displayapp')
| -rw-r--r-- | src/displayapp/DisplayApp.cpp | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index add00650..f5b2efde 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -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()) { |
