diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index dbd0445f7..b9c9e2fbf 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -864,6 +864,8 @@ void Screen::setFrames(FrameFocus focus) uint8_t previousFrameCount = framesetInfo.frameCount; FramesetInfo fsi; // Location of specific frames, for applying focus parameter + graphics::UIRenderer::rebuildFavoritedNodes(); + LOG_DEBUG("Show standard frames"); showingNormalScreen = true; diff --git a/src/graphics/draw/UIRenderer.cpp b/src/graphics/draw/UIRenderer.cpp index d9db1fa37..71d92616f 100644 --- a/src/graphics/draw/UIRenderer.cpp +++ b/src/graphics/draw/UIRenderer.cpp @@ -24,6 +24,23 @@ extern graphics::Screen *screen; namespace graphics { NodeNum UIRenderer::currentFavoriteNodeNum = 0; +std::vector graphics::UIRenderer::favoritedNodes; + +void graphics::UIRenderer::rebuildFavoritedNodes() +{ + favoritedNodes.clear(); + size_t total = nodeDB->getNumMeshNodes(); + for (size_t i = 0; i < total; i++) { + meshtastic_NodeInfoLite *n = nodeDB->getMeshNodeByIndex(i); + if (!n || n->num == nodeDB->getNodeNum()) + continue; + if (n->is_favorite) + favoritedNodes.push_back(n); + } + + std::sort(favoritedNodes.begin(), favoritedNodes.end(), + [](const meshtastic_NodeInfoLite *a, const meshtastic_NodeInfoLite *b) { return a->num < b->num; }); +} #if !MESHTASTIC_EXCLUDE_GPS // GeoCoord object for coordinate conversions @@ -201,27 +218,7 @@ void UIRenderer::drawNodes(OLEDDisplay *display, int16_t x, int16_t y, const mes // ********************** void UIRenderer::drawNodeInfo(OLEDDisplay *display, const OLEDDisplayUiState *state, int16_t x, int16_t y) { - // --- Cache favorite nodes for the current frame only, to save computation --- - static std::vector favoritedNodes; - static int prevFrame = -1; - // --- Only rebuild favorites list if we're on a new frame --- - if (state->currentFrame != prevFrame) { - prevFrame = state->currentFrame; - favoritedNodes.clear(); - size_t total = nodeDB->getNumMeshNodes(); - for (size_t i = 0; i < total; i++) { - meshtastic_NodeInfoLite *n = nodeDB->getMeshNodeByIndex(i); - // Skip nulls and ourself - if (!n || n->num == nodeDB->getNodeNum()) - continue; - if (n->is_favorite) - favoritedNodes.push_back(n); - } - // Keep a stable, consistent display order - std::sort(favoritedNodes.begin(), favoritedNodes.end(), - [](const meshtastic_NodeInfoLite *a, const meshtastic_NodeInfoLite *b) { return a->num < b->num; }); - } if (favoritedNodes.empty()) return; diff --git a/src/graphics/draw/UIRenderer.h b/src/graphics/draw/UIRenderer.h index 9e5e8c4b4..3c8e1dd9d 100644 --- a/src/graphics/draw/UIRenderer.h +++ b/src/graphics/draw/UIRenderer.h @@ -61,6 +61,8 @@ class UIRenderer static void drawCompassAndLocationScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y); static NodeNum currentFavoriteNodeNum; + static std::vector favoritedNodes; + static void rebuildFavoritedNodes(); // OEM screens #ifdef USERPREFS_OEM_TEXT