|
5 | 5 | #include "MeshService.h" |
6 | 6 | #include "NodeDB.h" |
7 | 7 | #include "NodeListRenderer.h" |
| 8 | +#if !MESHTASTIC_EXCLUDE_STATUS |
| 9 | +#include "modules/StatusMessageModule.h" |
| 10 | +#endif |
8 | 11 | #include "UIRenderer.h" |
9 | 12 | #include "airtime.h" |
10 | 13 | #include "gps/GeoCoord.h" |
@@ -290,7 +293,7 @@ void UIRenderer::drawNodes(OLEDDisplay *display, int16_t x, int16_t y, const mes |
290 | 293 | // * Favorite Node Info * |
291 | 294 | // ********************** |
292 | 295 | // cppcheck-suppress constParameterPointer; signature must match FrameCallback typedef from OLEDDisplayUi library |
293 | | -void UIRenderer::drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) |
| 296 | +void UIRenderer::drawFavoriteNode(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) |
294 | 297 | { |
295 | 298 | if (favoritedNodes.empty()) |
296 | 299 | return; |
@@ -342,6 +345,57 @@ void UIRenderer::drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, i |
342 | 345 | UIRenderer::drawStringWithEmotes(display, x, getTextPositions(display)[line++], username, FONT_HEIGHT_SMALL, 1, false); |
343 | 346 | } |
344 | 347 |
|
| 348 | +#if !MESHTASTIC_EXCLUDE_STATUS |
| 349 | + // === Optional: Last received StatusMessage line for this node === |
| 350 | + // Display it directly under the username line (if we have one). |
| 351 | + if (statusMessageModule) { |
| 352 | + const auto &recent = statusMessageModule->getRecentReceived(); |
| 353 | + const StatusMessageModule::RecentStatus *found = nullptr; |
| 354 | + |
| 355 | + // Search newest-to-oldest |
| 356 | + for (auto it = recent.rbegin(); it != recent.rend(); ++it) { |
| 357 | + if (it->fromNodeId == node->num && !it->statusText.empty()) { |
| 358 | + found = &(*it); |
| 359 | + break; |
| 360 | + } |
| 361 | + } |
| 362 | + |
| 363 | + if (found) { |
| 364 | + std::string statusLine = std::string(" Status: ") + found->statusText; |
| 365 | + { |
| 366 | + const int screenW = display->getWidth(); |
| 367 | + const int ellipseW = display->getStringWidth("..."); |
| 368 | + int w = display->getStringWidth(statusLine.c_str()); |
| 369 | + |
| 370 | + // Only do work if it overflows |
| 371 | + if (w > screenW) { |
| 372 | + bool truncated = false; |
| 373 | + if (ellipseW > screenW) { |
| 374 | + statusLine.clear(); |
| 375 | + } else { |
| 376 | + while (!statusLine.empty()) { |
| 377 | + // remove one char (byte) at a time |
| 378 | + statusLine.pop_back(); |
| 379 | + truncated = true; |
| 380 | + |
| 381 | + // Measure candidate with ellipsis appended |
| 382 | + std::string candidate = statusLine + "..."; |
| 383 | + if (display->getStringWidth(candidate.c_str()) <= screenW) { |
| 384 | + statusLine = std::move(candidate); |
| 385 | + break; |
| 386 | + } |
| 387 | + } |
| 388 | + if (statusLine.empty() && ellipseW <= screenW) { |
| 389 | + statusLine = "..."; |
| 390 | + } |
| 391 | + } |
| 392 | + } |
| 393 | + } |
| 394 | + display->drawString(x, getTextPositions(display)[line++], statusLine.c_str()); |
| 395 | + } |
| 396 | + } |
| 397 | +#endif |
| 398 | + |
345 | 399 | // === 2. Signal and Hops (combined on one line, if available) === |
346 | 400 | char signalHopsStr[32] = ""; |
347 | 401 | bool haveSignal = false; |
|
0 commit comments