From a97e40dc8e9d07e2f920ca44592d434ed62a7efa Mon Sep 17 00:00:00 2001 From: Jason P Date: Sun, 20 Jul 2025 20:09:10 -0500 Subject: [PATCH] Show/Hide Favorites as an option --- src/graphics/Screen.cpp | 41 ++++++++++++++++++------------- src/graphics/Screen.h | 1 + src/graphics/draw/MenuHandler.cpp | 8 ++++++ 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 3a0996a25..ae0a2f836 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -1003,27 +1003,29 @@ void Screen::setFrames(FrameFocus focus) if (numMeshNodes > 0) numMeshNodes--; - // Temporary array to hold favorite node frames - std::vector favoriteFrames; + if (!hiddenFrames.show_favorites) { + // Temporary array to hold favorite node frames + std::vector favoriteFrames; - for (size_t i = 0; i < nodeDB->getNumMeshNodes(); i++) { - const meshtastic_NodeInfoLite *n = nodeDB->getMeshNodeByIndex(i); - if (n && n->num != nodeDB->getNodeNum() && n->is_favorite) { - favoriteFrames.push_back(graphics::UIRenderer::drawNodeInfo); + for (size_t i = 0; i < nodeDB->getNumMeshNodes(); i++) { + const meshtastic_NodeInfoLite *n = nodeDB->getMeshNodeByIndex(i); + if (n && n->num != nodeDB->getNodeNum() && n->is_favorite) { + favoriteFrames.push_back(graphics::UIRenderer::drawNodeInfo); + } } - } - // Insert favorite frames *after* collecting them all - if (!favoriteFrames.empty()) { - fsi.positions.firstFavorite = numframes; - for (const auto &f : favoriteFrames) { - normalFrames[numframes++] = f; - indicatorIcons.push_back(icon_node); + // Insert favorite frames *after* collecting them all + if (!favoriteFrames.empty()) { + fsi.positions.firstFavorite = numframes; + for (const auto &f : favoriteFrames) { + normalFrames[numframes++] = f; + indicatorIcons.push_back(icon_node); + } + fsi.positions.lastFavorite = numframes - 1; + } else { + fsi.positions.firstFavorite = 255; + fsi.positions.lastFavorite = 255; } - fsi.positions.lastFavorite = numframes - 1; - } else { - fsi.positions.firstFavorite = 255; - fsi.positions.lastFavorite = 255; } fsi.frameCount = numframes; // Total framecount is used to apply FOCUS_PRESERVE @@ -1122,6 +1124,9 @@ void Screen::toggleFrameVisibility(const std::string &frameName) if (frameName == "clock") { hiddenFrames.clock = !hiddenFrames.clock; } + if (frameName == "show_favorites") { + hiddenFrames.show_favorites = !hiddenFrames.show_favorites; + } } bool Screen::isFrameHidden(const std::string &frameName) const @@ -1148,6 +1153,8 @@ bool Screen::isFrameHidden(const std::string &frameName) const return hiddenFrames.lora; if (frameName == "clock") return hiddenFrames.clock; + if (frameName == "show_favorites") + return hiddenFrames.show_favorites; return false; } diff --git a/src/graphics/Screen.h b/src/graphics/Screen.h index ea4ef7b70..2209fd3f4 100644 --- a/src/graphics/Screen.h +++ b/src/graphics/Screen.h @@ -695,6 +695,7 @@ class Screen : public concurrency::OSThread bool gps = false; #endif bool lora = false; + bool show_favorites = false; } hiddenFrames; /// Try to start drawing ASAP diff --git a/src/graphics/draw/MenuHandler.cpp b/src/graphics/draw/MenuHandler.cpp index d054c2c8c..74e268820 100644 --- a/src/graphics/draw/MenuHandler.cpp +++ b/src/graphics/draw/MenuHandler.cpp @@ -1103,6 +1103,7 @@ void menuHandler::FrameToggles_menu() gps, lora, clock, + show_favorites, enumEnd }; static const char *optionsArray[enumEnd] = {"Finish"}; @@ -1133,6 +1134,9 @@ void menuHandler::FrameToggles_menu() optionsArray[options] = screen->isFrameHidden("clock") ? "Show Clock" : "Hide Clock"; optionsEnumArray[options++] = clock; + + optionsArray[options] = screen->isFrameHidden("show_favorites") ? "Show Favorites" : "Hide Favorites"; + optionsEnumArray[options++] = show_favorites; #endif BannerOverlayOptions bannerOptions; @@ -1175,6 +1179,10 @@ void menuHandler::FrameToggles_menu() screen->toggleFrameVisibility("clock"); menuHandler::menuQueue = menuHandler::FrameToggles; screen->runNow(); + } else if (selected == show_favorites) { + screen->toggleFrameVisibility("show_favorites"); + menuHandler::menuQueue = menuHandler::FrameToggles; + screen->runNow(); } }; screen->showOverlayBanner(bannerOptions);