mirror of
https://github.com/meshtastic/firmware.git
synced 2025-08-06 05:34:45 +00:00
Fix notification popup
This commit is contained in:
parent
a7b0cf3ac7
commit
d33303a038
@ -180,6 +180,7 @@ void NotificationRenderer::drawNotificationBox(OLEDDisplay *display, OLEDDisplay
|
|||||||
constexpr uint16_t vPadding = 2;
|
constexpr uint16_t vPadding = 2;
|
||||||
bool needs_bell = false;
|
bool needs_bell = false;
|
||||||
uint16_t lineWidths[totalLines] = {0};
|
uint16_t lineWidths[totalLines] = {0};
|
||||||
|
uint16_t lineLengths[totalLines] = {0};
|
||||||
|
|
||||||
if (maxWidth != 0)
|
if (maxWidth != 0)
|
||||||
is_picker = true;
|
is_picker = true;
|
||||||
@ -187,7 +188,12 @@ void NotificationRenderer::drawNotificationBox(OLEDDisplay *display, OLEDDisplay
|
|||||||
|
|
||||||
while (lineCount < totalLines) {
|
while (lineCount < totalLines) {
|
||||||
if (lines[lineCount] != nullptr) {
|
if (lines[lineCount] != nullptr) {
|
||||||
lineWidths[lineCount] = display->getStringWidth(lines[lineCount], strlen(lines[lineCount]), true);
|
auto newlinePointer = strchr(lines[lineCount], '\n');
|
||||||
|
if (newlinePointer)
|
||||||
|
lineLengths[lineCount] = (newlinePointer - lines[lineCount]); // Check for newlines first
|
||||||
|
else // if the newline wasn't found, then pull string length from strlen
|
||||||
|
lineLengths[lineCount] = strlen(lines[lineCount]);
|
||||||
|
lineWidths[lineCount] = display->getStringWidth(lines[lineCount], lineLengths[lineCount], true);
|
||||||
if (!is_picker) {
|
if (!is_picker) {
|
||||||
needs_bell |= (strstr(alertBannerMessage, "Alert Received") != nullptr);
|
needs_bell |= (strstr(alertBannerMessage, "Alert Received") != nullptr);
|
||||||
if (lineWidths[lineCount] > maxWidth)
|
if (lineWidths[lineCount] > maxWidth)
|
||||||
@ -242,26 +248,27 @@ void NotificationRenderer::drawNotificationBox(OLEDDisplay *display, OLEDDisplay
|
|||||||
display->drawXbm(textX - 10, bellY, 8, 8, bell_alert);
|
display->drawXbm(textX - 10, bellY, 8, 8, bell_alert);
|
||||||
display->drawXbm(textX + lineWidths[i] + 2, bellY, 8, 8, bell_alert);
|
display->drawXbm(textX + lineWidths[i] + 2, bellY, 8, 8, bell_alert);
|
||||||
}
|
}
|
||||||
|
char lineBuffer[lineLengths[i] + 1];
|
||||||
|
strncpy(lineBuffer, lines[i], lineLengths[i]);
|
||||||
|
lineBuffer[lineLengths[i]] = '\0';
|
||||||
// Determine if this is a pop-up or a pick list
|
// Determine if this is a pop-up or a pick list
|
||||||
if (alertBannerOptions > 0 && i == 0) {
|
if (alertBannerOptions > 0 && i == 0) {
|
||||||
// Pick List
|
// Pick List
|
||||||
display->setColor(WHITE);
|
display->setColor(WHITE);
|
||||||
int background_yOffset = 1;
|
int background_yOffset = 1;
|
||||||
// Determine if we have low hanging characters
|
// Determine if we have low hanging characters
|
||||||
if (strchr(lines[i], 'p') || strchr(lines[i], 'g') || strchr(lines[i], 'y') || strchr(lines[i], 'j')) {
|
if (strchr(lineBuffer, 'p') || strchr(lineBuffer, 'g') || strchr(lineBuffer, 'y') || strchr(lineBuffer, 'j')) {
|
||||||
background_yOffset = -1;
|
background_yOffset = -1;
|
||||||
}
|
}
|
||||||
display->fillRect(boxLeft, boxTop + 1, boxWidth, effectiveLineHeight - background_yOffset);
|
display->fillRect(boxLeft, boxTop + 1, boxWidth, effectiveLineHeight - background_yOffset);
|
||||||
display->setColor(BLACK);
|
display->setColor(BLACK);
|
||||||
int yOffset = 3;
|
int yOffset = 3;
|
||||||
display->drawString(textX, lineY - yOffset, lines[i]);
|
display->drawString(textX, lineY - yOffset, lineBuffer);
|
||||||
display->setColor(WHITE);
|
display->setColor(WHITE);
|
||||||
lineY += (effectiveLineHeight - 2 - background_yOffset);
|
lineY += (effectiveLineHeight - 2 - background_yOffset);
|
||||||
} else {
|
} else {
|
||||||
// Pop-up
|
// Pop-up
|
||||||
LOG_WARN("x%u y%u %s", textX, lineY, lines[i]);
|
display->drawString(textX, lineY, lineBuffer);
|
||||||
display->drawString(textX, lineY, lines[i]);
|
|
||||||
lineY += (effectiveLineHeight);
|
lineY += (effectiveLineHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user