From 580fa292ac68b272b76271a9a11c625c459be4a9 Mon Sep 17 00:00:00 2001 From: Jason P Date: Sat, 25 Oct 2025 07:12:59 -0500 Subject: [PATCH] Address longName wrapping (#8441) * Address longName wrapping * Update src/graphics/draw/NodeListRenderer.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Ben Meadors Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/graphics/draw/MenuHandler.cpp | 1 + src/graphics/draw/NodeListRenderer.cpp | 34 +++++++++++++++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/graphics/draw/MenuHandler.cpp b/src/graphics/draw/MenuHandler.cpp index 701062e08..803fb87ea 100644 --- a/src/graphics/draw/MenuHandler.cpp +++ b/src/graphics/draw/MenuHandler.cpp @@ -784,6 +784,7 @@ void menuHandler::nodeNameLengthMenu() screen->runNow(); } }; + bannerOptions.InitialSelected = config.display.use_long_node_name == true ? 1 : 2; screen->showOverlayBanner(bannerOptions); } diff --git a/src/graphics/draw/NodeListRenderer.cpp b/src/graphics/draw/NodeListRenderer.cpp index 07577db8c..16bfa7066 100644 --- a/src/graphics/draw/NodeListRenderer.cpp +++ b/src/graphics/draw/NodeListRenderer.cpp @@ -53,7 +53,7 @@ static int scrollIndex = 0; // Utility Functions // ============================= -const char *getSafeNodeName(meshtastic_NodeInfoLite *node) +const char *getSafeNodeName(OLEDDisplay *display, meshtastic_NodeInfoLite *node) { const char *name = NULL; static char nodeName[16] = "?"; @@ -81,6 +81,28 @@ const char *getSafeNodeName(meshtastic_NodeInfoLite *node) snprintf(nodeName, sizeof(nodeName), "(%04X)", (uint16_t)(node->num & 0xFFFF)); } + if (config.display.use_long_node_name == true) { + int availWidth = (SCREEN_WIDTH / 2) - 65; + if (availWidth < 0) + availWidth = 0; + + size_t origLen = strlen(nodeName); + while (nodeName[0] && display->getStringWidth(nodeName) > availWidth) { + nodeName[strlen(nodeName) - 1] = '\0'; + } + + // If we actually truncated, append "..." (ensure space remains in buffer) + if (strlen(nodeName) < origLen) { + size_t len = strlen(nodeName); + size_t maxLen = sizeof(nodeName) - 4; // 3 for "..." and 1 for '\0' + if (len > maxLen) { + nodeName[maxLen] = '\0'; + len = maxLen; + } + strcat(nodeName, "..."); + } + } + return nodeName; } @@ -147,7 +169,7 @@ void drawEntryLastHeard(OLEDDisplay *display, meshtastic_NodeInfoLite *node, int bool isLeftCol = (x < SCREEN_WIDTH / 2); int timeOffset = (isHighResolution) ? (isLeftCol ? 7 : 10) : (isLeftCol ? 3 : 7); - const char *nodeName = getSafeNodeName(node); + const char *nodeName = getSafeNodeName(display, node); char timeStr[10]; uint32_t seconds = sinceLastSeen(node); @@ -192,7 +214,7 @@ void drawEntryHopSignal(OLEDDisplay *display, meshtastic_NodeInfoLite *node, int int barsXOffset = columnWidth - barsOffset; - const char *nodeName = getSafeNodeName(node); + const char *nodeName = getSafeNodeName(display, node); display->setTextAlignment(TEXT_ALIGN_LEFT); display->setFont(FONT_SMALL); @@ -236,7 +258,7 @@ void drawNodeDistance(OLEDDisplay *display, meshtastic_NodeInfoLite *node, int16 bool isLeftCol = (x < SCREEN_WIDTH / 2); int nameMaxWidth = columnWidth - (isHighResolution ? (isLeftCol ? 25 : 28) : (isLeftCol ? 20 : 22)); - const char *nodeName = getSafeNodeName(node); + const char *nodeName = getSafeNodeName(display, node); char distStr[10] = ""; meshtastic_NodeInfoLite *ourNode = nodeDB->getMeshNode(nodeDB->getNodeNum()); @@ -331,7 +353,7 @@ void drawEntryCompass(OLEDDisplay *display, meshtastic_NodeInfoLite *node, int16 // Adjust max text width depending on column and screen width int nameMaxWidth = columnWidth - (isHighResolution ? (isLeftCol ? 25 : 28) : (isLeftCol ? 20 : 22)); - const char *nodeName = getSafeNodeName(node); + const char *nodeName = getSafeNodeName(display, node); display->setTextAlignment(TEXT_ALIGN_LEFT); display->setFont(FONT_SMALL); @@ -362,11 +384,11 @@ void drawCompassArrow(OLEDDisplay *display, meshtastic_NodeInfoLite *node, int16 float bearing = GeoCoord::bearing(userLat, userLon, nodeLat, nodeLon); float bearingToNode = RAD_TO_DEG * bearing; float relativeBearing = fmod((bearingToNode - myHeading + 360), 360); - float angle = relativeBearing * DEG_TO_RAD; // Shrink size by 2px int size = FONT_HEIGHT_SMALL - 5; CompassRenderer::drawArrowToNode(display, centerX, centerY, size, relativeBearing); /* + float angle = relativeBearing * DEG_TO_RAD; float halfSize = size / 2.0; // Point of the arrow