mirror of
https://github.com/meshtastic/firmware.git
synced 2025-08-11 16:07:13 +00:00
Degree sign fix
This commit is contained in:
parent
48dc44ea8f
commit
6542c7bb47
@ -1131,56 +1131,71 @@ void drawStringWithEmotes(OLEDDisplay* display, int x, int y, const std::string&
|
|||||||
const int fontHeight = FONT_HEIGHT_SMALL;
|
const int fontHeight = FONT_HEIGHT_SMALL;
|
||||||
|
|
||||||
// === Step 1: Find tallest emote in the line ===
|
// === Step 1: Find tallest emote in the line ===
|
||||||
int maxIconHeight = 0;
|
int maxIconHeight = fontHeight;
|
||||||
|
|
||||||
for (size_t i = 0; i < line.length();) {
|
for (size_t i = 0; i < line.length();) {
|
||||||
|
bool matched = false;
|
||||||
for (int e = 0; e < emoteCount; ++e) {
|
for (int e = 0; e < emoteCount; ++e) {
|
||||||
size_t emojiLen = strlen(emotes[e].code);
|
size_t emojiLen = strlen(emotes[e].code);
|
||||||
if (line.compare(i, emojiLen, emotes[e].code) == 0) {
|
if (line.compare(i, emojiLen, emotes[e].code) == 0) {
|
||||||
if (emotes[e].height > maxIconHeight)
|
if (emotes[e].height > maxIconHeight)
|
||||||
maxIconHeight = emotes[e].height;
|
maxIconHeight = emotes[e].height;
|
||||||
i += emojiLen;
|
i += emojiLen;
|
||||||
goto next_char;
|
matched = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i++; // move to next char if no emote match
|
if (!matched) {
|
||||||
next_char:;
|
uint8_t c = static_cast<uint8_t>(line[i]);
|
||||||
|
if ((c & 0xE0) == 0xC0) i += 2;
|
||||||
|
else if ((c & 0xF0) == 0xE0) i += 3;
|
||||||
|
else if ((c & 0xF8) == 0xF0) i += 4;
|
||||||
|
else i += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// === Step 2: Calculate vertical shift to center line ===
|
// === Step 2: Baseline alignment ===
|
||||||
int lineHeight = std::max(fontHeight, maxIconHeight);
|
int lineHeight = std::max(fontHeight, maxIconHeight);
|
||||||
int baselineOffset = (lineHeight - fontHeight) / 2;
|
int baselineOffset = (lineHeight - fontHeight) / 2;
|
||||||
int fontY = y + baselineOffset;
|
int fontY = y + baselineOffset;
|
||||||
int fontMidline = fontY + fontHeight / 2;
|
int fontMidline = fontY + fontHeight / 2;
|
||||||
|
|
||||||
// === Step 3: Render text and icons centered in line ===
|
// === Step 3: Render line in segments ===
|
||||||
for (size_t i = 0; i < line.length();) {
|
size_t i = 0;
|
||||||
bool matched = false;
|
while (i < line.length()) {
|
||||||
|
// Look ahead for the next emote match
|
||||||
|
size_t nextEmotePos = std::string::npos;
|
||||||
|
const Emote* matchedEmote = nullptr;
|
||||||
|
size_t emojiLen = 0;
|
||||||
|
|
||||||
for (int e = 0; e < emoteCount; ++e) {
|
for (int e = 0; e < emoteCount; ++e) {
|
||||||
size_t emojiLen = strlen(emotes[e].code);
|
size_t pos = line.find(emotes[e].code, i);
|
||||||
if (line.compare(i, emojiLen, emotes[e].code) == 0) {
|
if (pos != std::string::npos && (nextEmotePos == std::string::npos || pos < nextEmotePos)) {
|
||||||
int iconY = fontMidline - emotes[e].height / 2 - 1; // slight nudge up
|
nextEmotePos = pos;
|
||||||
display->drawXbm(cursorX, iconY, emotes[e].width, emotes[e].height, emotes[e].bitmap);
|
matchedEmote = &emotes[e];
|
||||||
cursorX += emotes[e].width + 1;
|
emojiLen = strlen(emotes[e].code);
|
||||||
i += emojiLen;
|
|
||||||
matched = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!matched) {
|
// Render normal text segment up to the emote
|
||||||
uint8_t c = static_cast<uint8_t>(line[i]);
|
if (nextEmotePos != std::string::npos && nextEmotePos > i) {
|
||||||
int charLen = 1;
|
std::string textChunk = line.substr(i, nextEmotePos - i);
|
||||||
|
display->drawString(cursorX, fontY, textChunk.c_str());
|
||||||
|
cursorX += display->getStringWidth(textChunk.c_str());
|
||||||
|
i = nextEmotePos;
|
||||||
|
}
|
||||||
|
|
||||||
if ((c & 0xE0) == 0xC0) charLen = 2; // 2-byte UTF-8
|
// Render the emote (if found)
|
||||||
else if ((c & 0xF0) == 0xE0) charLen = 3; // 3-byte UTF-8
|
if (matchedEmote) {
|
||||||
else if ((c & 0xF8) == 0xF0) charLen = 4; // 4-byte UTF-8
|
int iconY = fontMidline - matchedEmote->height / 2 - 1;
|
||||||
|
display->drawXbm(cursorX, iconY, matchedEmote->width, matchedEmote->height, matchedEmote->bitmap);
|
||||||
std::string utf8char = line.substr(i, charLen);
|
cursorX += matchedEmote->width + 1;
|
||||||
display->drawString(cursorX, fontY, utf8char.c_str());
|
i += emojiLen;
|
||||||
cursorX += display->getStringWidth(utf8char.c_str());
|
} else {
|
||||||
i += charLen;
|
// No more emotes — render the rest of the line
|
||||||
|
std::string remaining = line.substr(i);
|
||||||
|
display->drawString(cursorX, fontY, remaining.c_str());
|
||||||
|
cursorX += display->getStringWidth(remaining.c_str());
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1956,8 +1971,7 @@ struct NodeEntry {
|
|||||||
enum NodeListMode { MODE_LAST_HEARD = 0, MODE_HOP_SIGNAL = 1, MODE_DISTANCE = 2, MODE_COUNT = 3 };
|
enum NodeListMode { MODE_LAST_HEARD = 0, MODE_HOP_SIGNAL = 1, MODE_DISTANCE = 2, MODE_COUNT = 3 };
|
||||||
|
|
||||||
static NodeListMode currentMode = MODE_LAST_HEARD;
|
static NodeListMode currentMode = MODE_LAST_HEARD;
|
||||||
static unsigned long lastModeSwitchTime = 0;
|
static int scrollIndex = 0;
|
||||||
static int scrollIndex = 0;
|
|
||||||
|
|
||||||
// Use dynamic timing based on mode
|
// Use dynamic timing based on mode
|
||||||
unsigned long getModeCycleIntervalMs()
|
unsigned long getModeCycleIntervalMs()
|
||||||
|
Loading…
Reference in New Issue
Block a user