From 8f566732ed4dde44f4bf62373696c3197419a11c Mon Sep 17 00:00:00 2001 From: Jakub <106778416+MarekZegare4@users.noreply.github.com> Date: Mon, 18 May 2026 15:00:01 +0200 Subject: [PATCH] feat: show @recipient as 'To: nick' bar in fullscreen message view When a message starts with @nick, the fullscreen view expands the header to show a second row 'To: nick' below the sender name, and displays the message body without the @nick prefix. Co-Authored-By: Claude Sonnet 4.6 --- .../ui-new/FullscreenMsgView.h | 42 +++++++++++++++---- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/examples/companion_radio/ui-new/FullscreenMsgView.h b/examples/companion_radio/ui-new/FullscreenMsgView.h index a5bfe99f..969b801f 100644 --- a/examples/companion_radio/ui-new/FullscreenMsgView.h +++ b/examples/companion_radio/ui-new/FullscreenMsgView.h @@ -42,35 +42,59 @@ struct FullscreenMsgView { int render(DisplayDriver& display, const char* sender, const char* text, bool has_prev, bool has_next) { display.setTextSize(1); + + // detect @recipient at start of message + char to_nick[32] = ""; + const char* body = text; + if (text[0] == '@') { + const char* sp = strchr(text, ' '); + if (sp && sp[1]) { + int len = (int)(sp - text) - 1; + if (len >= (int)sizeof(to_nick)) len = sizeof(to_nick) - 1; + memcpy(to_nick, text + 1, len); + to_nick[len] = '\0'; + body = sp + 1; + } + } + + const int header_h = to_nick[0] ? 20 : 10; + const int startY = header_h + 2; + const int visible = (display.height() - startY - FS_LINE_H) / FS_LINE_H; + display.setColor(DisplayDriver::LIGHT); - display.fillRect(0, 0, display.width(), 10); + display.fillRect(0, 0, display.width(), header_h); display.setColor(DisplayDriver::DARK); display.drawTextEllipsized(2, 1, display.width() - 4, sender); + if (to_nick[0]) { + char to_label[36]; + snprintf(to_label, sizeof(to_label), "To: %s", to_nick); + display.drawTextEllipsized(2, 11, display.width() - 4, to_label); + } display.setColor(DisplayDriver::LIGHT); char trans_text[512]; - display.translateUTF8ToBlocks(trans_text, text, sizeof(trans_text)); + display.translateUTF8ToBlocks(trans_text, body, sizeof(trans_text)); char lines[12][FS_CHARS + 1]; int lcount = wrapLines(trans_text, lines, 12); - int max_scroll = lcount > FS_VISIBLE ? lcount - FS_VISIBLE : 0; + int max_scroll = lcount > visible ? lcount - visible : 0; if (scroll > max_scroll) scroll = max_scroll; - for (int i = 0; i < FS_VISIBLE && (scroll + i) < lcount; i++) { - display.setCursor(0, FS_START_Y + i * FS_LINE_H); + for (int i = 0; i < visible && (scroll + i) < lcount; i++) { + display.setCursor(0, startY + i * FS_LINE_H); display.print(lines[scroll + i]); } if (scroll > 0) { display.setColor(DisplayDriver::DARK); - display.fillRect(display.width() - 6, FS_START_Y, 6, FS_LINE_H); + display.fillRect(display.width() - 6, startY, 6, FS_LINE_H); display.setColor(DisplayDriver::LIGHT); - display.setCursor(display.width() - 6, FS_START_Y); + display.setCursor(display.width() - 6, startY); display.print("^"); } if (scroll < max_scroll) { display.setColor(DisplayDriver::DARK); - display.fillRect(display.width() - 6, FS_START_Y + (FS_VISIBLE - 1) * FS_LINE_H, 6, FS_LINE_H); + display.fillRect(display.width() - 6, startY + (visible - 1) * FS_LINE_H, 6, FS_LINE_H); display.setColor(DisplayDriver::LIGHT); - display.setCursor(display.width() - 6, FS_START_Y + (FS_VISIBLE - 1) * FS_LINE_H); + display.setCursor(display.width() - 6, startY + (visible - 1) * FS_LINE_H); display.print("v"); } if (has_next) {