mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-08 22:22:05 +00:00
Bold effect on text in ** Like this **
This commit is contained in:
parent
6542c7bb47
commit
9fc208df5f
@ -1161,7 +1161,16 @@ void drawStringWithEmotes(OLEDDisplay* display, int x, int y, const std::string&
|
|||||||
|
|
||||||
// === Step 3: Render line in segments ===
|
// === Step 3: Render line in segments ===
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
bool inBold = false;
|
||||||
|
|
||||||
while (i < line.length()) {
|
while (i < line.length()) {
|
||||||
|
// Check for ** start/end for faux bold
|
||||||
|
if (line.compare(i, 2, "**") == 0) {
|
||||||
|
inBold = !inBold;
|
||||||
|
i += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Look ahead for the next emote match
|
// Look ahead for the next emote match
|
||||||
size_t nextEmotePos = std::string::npos;
|
size_t nextEmotePos = std::string::npos;
|
||||||
const Emote* matchedEmote = nullptr;
|
const Emote* matchedEmote = nullptr;
|
||||||
@ -1176,16 +1185,24 @@ void drawStringWithEmotes(OLEDDisplay* display, int x, int y, const std::string&
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render normal text segment up to the emote
|
// Render normal text segment up to the emote or bold toggle
|
||||||
if (nextEmotePos != std::string::npos && nextEmotePos > i) {
|
size_t nextControl = std::min(nextEmotePos, line.find("**", i));
|
||||||
std::string textChunk = line.substr(i, nextEmotePos - i);
|
if (nextControl == std::string::npos) nextControl = line.length();
|
||||||
|
|
||||||
|
if (nextControl > i) {
|
||||||
|
std::string textChunk = line.substr(i, nextControl - i);
|
||||||
|
if (inBold) {
|
||||||
|
// Faux bold: draw twice, offset by 1px
|
||||||
|
display->drawString(cursorX + 1, fontY, textChunk.c_str());
|
||||||
|
}
|
||||||
display->drawString(cursorX, fontY, textChunk.c_str());
|
display->drawString(cursorX, fontY, textChunk.c_str());
|
||||||
cursorX += display->getStringWidth(textChunk.c_str());
|
cursorX += display->getStringWidth(textChunk.c_str());
|
||||||
i = nextEmotePos;
|
i = nextControl;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the emote (if found)
|
// Render the emote (if found)
|
||||||
if (matchedEmote) {
|
if (matchedEmote && i == nextEmotePos) {
|
||||||
int iconY = fontMidline - matchedEmote->height / 2 - 1;
|
int iconY = fontMidline - matchedEmote->height / 2 - 1;
|
||||||
display->drawXbm(cursorX, iconY, matchedEmote->width, matchedEmote->height, matchedEmote->bitmap);
|
display->drawXbm(cursorX, iconY, matchedEmote->width, matchedEmote->height, matchedEmote->bitmap);
|
||||||
cursorX += matchedEmote->width + 1;
|
cursorX += matchedEmote->width + 1;
|
||||||
@ -1193,6 +1210,9 @@ void drawStringWithEmotes(OLEDDisplay* display, int x, int y, const std::string&
|
|||||||
} else {
|
} else {
|
||||||
// No more emotes — render the rest of the line
|
// No more emotes — render the rest of the line
|
||||||
std::string remaining = line.substr(i);
|
std::string remaining = line.substr(i);
|
||||||
|
if (inBold) {
|
||||||
|
display->drawString(cursorX + 1, fontY, remaining.c_str());
|
||||||
|
}
|
||||||
display->drawString(cursorX, fontY, remaining.c_str());
|
display->drawString(cursorX, fontY, remaining.c_str());
|
||||||
cursorX += display->getStringWidth(remaining.c_str());
|
cursorX += display->getStringWidth(remaining.c_str());
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user