mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-14 14:52:32 +00:00
Shorten longNames to not exceed message popups
This commit is contained in:
@@ -785,7 +785,7 @@ std::vector<int> calculateLineHeights(const std::vector<std::string> &lines, con
|
|||||||
return rowHeights;
|
return rowHeights;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleNewMessage(const StoredMessage &sm, const meshtastic_MeshPacket &packet)
|
void handleNewMessage(OLEDDisplay *display, const StoredMessage &sm, const meshtastic_MeshPacket &packet)
|
||||||
{
|
{
|
||||||
if (packet.from != 0) {
|
if (packet.from != 0) {
|
||||||
hasUnreadMessage = true;
|
hasUnreadMessage = true;
|
||||||
@@ -800,7 +800,22 @@ void handleNewMessage(const StoredMessage &sm, const meshtastic_MeshPacket &pack
|
|||||||
|
|
||||||
// Banner logic
|
// Banner logic
|
||||||
const meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(packet.from);
|
const meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(packet.from);
|
||||||
const char *longName = (node && node->has_user) ? node->user.long_name : nullptr;
|
char longName[48] = "???";
|
||||||
|
if (node && node->user.long_name) {
|
||||||
|
strncpy(longName, node->user.long_name, sizeof(longName) - 1);
|
||||||
|
longName[sizeof(longName) - 1] = '\0';
|
||||||
|
}
|
||||||
|
int availWidth = display->getWidth() - (isHighResolution ? 40 : 20);
|
||||||
|
if (availWidth < 0)
|
||||||
|
availWidth = 0;
|
||||||
|
|
||||||
|
size_t origLen = strlen(longName);
|
||||||
|
while (longName[0] && display->getStringWidth(longName) > availWidth) {
|
||||||
|
longName[strlen(longName) - 1] = '\0';
|
||||||
|
}
|
||||||
|
if (strlen(longName) < origLen) {
|
||||||
|
strcat(longName, "...");
|
||||||
|
}
|
||||||
const char *msgRaw = reinterpret_cast<const char *>(packet.decoded.payload.bytes);
|
const char *msgRaw = reinterpret_cast<const char *>(packet.decoded.payload.bytes);
|
||||||
|
|
||||||
char banner[256];
|
char banner[256];
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ void resetScrollState();
|
|||||||
void setThreadFor(const StoredMessage &sm, const meshtastic_MeshPacket &packet);
|
void setThreadFor(const StoredMessage &sm, const meshtastic_MeshPacket &packet);
|
||||||
|
|
||||||
// Handles a new incoming/outgoing message: banner, wake, thread select, scroll reset
|
// Handles a new incoming/outgoing message: banner, wake, thread select, scroll reset
|
||||||
void handleNewMessage(const StoredMessage &sm, const meshtastic_MeshPacket &packet);
|
void handleNewMessage(OLEDDisplay *display, const StoredMessage &sm, const meshtastic_MeshPacket &packet);
|
||||||
|
|
||||||
// Clear Message Line Cache from Message Renderer
|
// Clear Message Line Cache from Message Renderer
|
||||||
void clearMessageCache();
|
void clearMessageCache();
|
||||||
|
|||||||
@@ -2199,11 +2199,27 @@ ProcessMessage CannedMessageModule::handleReceived(const meshtastic_MeshPacket &
|
|||||||
|
|
||||||
// Show overlay banner
|
// Show overlay banner
|
||||||
if (screen) {
|
if (screen) {
|
||||||
|
auto *display = screen->getDisplayDevice();
|
||||||
graphics::BannerOverlayOptions opts;
|
graphics::BannerOverlayOptions opts;
|
||||||
static char buf[128];
|
static char buf[128];
|
||||||
|
|
||||||
const char *channelName = channels.getName(this->channel);
|
const char *channelName = channels.getName(this->channel);
|
||||||
const char *nodeName = getNodeName(this->incoming);
|
const char *src = getNodeName(this->incoming);
|
||||||
|
char nodeName[48];
|
||||||
|
strncpy(nodeName, src, sizeof(nodeName) - 1);
|
||||||
|
nodeName[sizeof(nodeName) - 1] = '\0';
|
||||||
|
|
||||||
|
int availWidth = display->getWidth() - (graphics::isHighResolution ? 60 : 30);
|
||||||
|
if (availWidth < 0)
|
||||||
|
availWidth = 0;
|
||||||
|
|
||||||
|
size_t origLen = strlen(nodeName);
|
||||||
|
while (nodeName[0] && display->getStringWidth(nodeName) > availWidth) {
|
||||||
|
nodeName[strlen(nodeName) - 1] = '\0';
|
||||||
|
}
|
||||||
|
if (strlen(nodeName) < origLen) {
|
||||||
|
strcat(nodeName, "...");
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate signal quality and bars based on preset, SNR, and RSSI
|
// Calculate signal quality and bars based on preset, SNR, and RSSI
|
||||||
float snrLimit = getSnrLimit(config.lora.modem_preset);
|
float snrLimit = getSnrLimit(config.lora.modem_preset);
|
||||||
|
|||||||
@@ -6,7 +6,9 @@
|
|||||||
#include "buzz.h"
|
#include "buzz.h"
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include "graphics/Screen.h"
|
#include "graphics/Screen.h"
|
||||||
|
#include "graphics/SharedUIDisplay.h"
|
||||||
#include "graphics/draw/MessageRenderer.h"
|
#include "graphics/draw/MessageRenderer.h"
|
||||||
|
#include "main.h"
|
||||||
TextMessageModule *textMessageModule;
|
TextMessageModule *textMessageModule;
|
||||||
|
|
||||||
ProcessMessage TextMessageModule::handleReceived(const meshtastic_MeshPacket &mp)
|
ProcessMessage TextMessageModule::handleReceived(const meshtastic_MeshPacket &mp)
|
||||||
@@ -24,7 +26,9 @@ ProcessMessage TextMessageModule::handleReceived(const meshtastic_MeshPacket &mp
|
|||||||
const StoredMessage &sm = messageStore.addFromPacket(mp);
|
const StoredMessage &sm = messageStore.addFromPacket(mp);
|
||||||
|
|
||||||
// Pass message to renderer (banner + thread switching + scroll reset)
|
// Pass message to renderer (banner + thread switching + scroll reset)
|
||||||
graphics::MessageRenderer::handleNewMessage(sm, mp);
|
// Use the global Screen singleton to retrieve the current OLED display
|
||||||
|
auto *display = screen ? screen->getDisplayDevice() : nullptr;
|
||||||
|
graphics::MessageRenderer::handleNewMessage(display, sm, mp);
|
||||||
#endif
|
#endif
|
||||||
// Only trigger screen wake if configuration allows it
|
// Only trigger screen wake if configuration allows it
|
||||||
if (shouldWakeOnReceivedMessage()) {
|
if (shouldWakeOnReceivedMessage()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user