multi-line doesnt seem bugged and joins still work, will work on the small gap in buffer at the bottom
This commit is contained in:
parent
8ff6e5811e
commit
711e8dee5b
54
src/main.ino
54
src/main.ino
@ -555,18 +555,31 @@ int calculateLinesRequired(String message) {
|
|||||||
int linesRequired = 1;
|
int linesRequired = 1;
|
||||||
int lineWidth = 0;
|
int lineWidth = 0;
|
||||||
|
|
||||||
for (char c : message) {
|
for (unsigned int i = 0; i < message.length(); i++) {
|
||||||
lineWidth += tft.textWidth(String(c));
|
char c = message[i];
|
||||||
if (lineWidth > SCREEN_WIDTH) {
|
if (c == '\x03') {
|
||||||
linesRequired++;
|
// Skip color code sequences from calculate instead of render to solve nick overlay issue
|
||||||
lineWidth = tft.textWidth(String(c));
|
while (i < message.length() && (isdigit(message[i + 1]) || message[i + 1] == ',')) {
|
||||||
|
i++;
|
||||||
|
if (isdigit(message[i + 1])) {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (message[i] == ',' && isdigit(message[i + 1])) {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (c != '\x02' && c != '\x0F' && c != '\x1F') { // Ignore other formatting codes as they are not as prevalent
|
||||||
|
lineWidth += tft.textWidth(String(c));
|
||||||
|
if (lineWidth > SCREEN_WIDTH) {
|
||||||
|
linesRequired++;
|
||||||
|
lineWidth = tft.textWidth(String(c));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return linesRequired;
|
return linesRequired;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void displayCenteredText(String text) {
|
void displayCenteredText(String text) {
|
||||||
tft.fillScreen(TFT_BLACK);
|
tft.fillScreen(TFT_BLACK);
|
||||||
tft.setTextDatum(MC_DATUM);
|
tft.setTextDatum(MC_DATUM);
|
||||||
@ -872,10 +885,29 @@ void displayLines() {
|
|||||||
tft.fillRect(0, STATUS_BAR_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT - STATUS_BAR_HEIGHT - INPUT_LINE_HEIGHT, TFT_BLACK);
|
tft.fillRect(0, STATUS_BAR_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT - STATUS_BAR_HEIGHT - INPUT_LINE_HEIGHT, TFT_BLACK);
|
||||||
|
|
||||||
int cursorY = STATUS_BAR_HEIGHT;
|
int cursorY = STATUS_BAR_HEIGHT;
|
||||||
|
int totalLinesHeight = 0;
|
||||||
|
std::vector<int> lineHeights;
|
||||||
|
|
||||||
|
// Calculate total height needed for all lines
|
||||||
|
for (const String& line : lines) {
|
||||||
|
int lineHeight = calculateLinesRequired(line) * CHAR_HEIGHT;
|
||||||
|
lineHeights.push_back(lineHeight);
|
||||||
|
totalLinesHeight += lineHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove lines from the top if they exceed the screen height
|
||||||
|
while (totalLinesHeight > SCREEN_HEIGHT - STATUS_BAR_HEIGHT - INPUT_LINE_HEIGHT) {
|
||||||
|
totalLinesHeight -= lineHeights.front();
|
||||||
|
lines.erase(lines.begin());
|
||||||
|
mentions.erase(mentions.begin());
|
||||||
|
lineHeights.erase(lineHeights.begin());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render each line
|
||||||
for (size_t i = 0; i < lines.size(); ++i) {
|
for (size_t i = 0; i < lines.size(); ++i) {
|
||||||
const String& line = lines[i];
|
const String& line = lines[i];
|
||||||
bool mention = mentions[i];
|
bool mention = mentions[i];
|
||||||
|
|
||||||
tft.setCursor(0, cursorY);
|
tft.setCursor(0, cursorY);
|
||||||
|
|
||||||
if (line.startsWith("JOIN ")) {
|
if (line.startsWith("JOIN ")) {
|
||||||
@ -940,7 +972,7 @@ void displayLines() {
|
|||||||
tft.print(kicker);
|
tft.print(kicker);
|
||||||
cursorY += CHAR_HEIGHT;
|
cursorY += CHAR_HEIGHT;
|
||||||
} else if (line.startsWith("MODE ")) {
|
} else if (line.startsWith("MODE ")) {
|
||||||
tft.setTextColor(TFT_BLUE);
|
tft.setTextColor(TFT_YELLOW);
|
||||||
tft.print("MODE ");
|
tft.print("MODE ");
|
||||||
String modeChange = line.substring(5);
|
String modeChange = line.substring(5);
|
||||||
tft.setTextColor(TFT_WHITE);
|
tft.setTextColor(TFT_WHITE);
|
||||||
@ -961,9 +993,9 @@ void displayLines() {
|
|||||||
String senderNick = line.substring(startIndex, endIndex);
|
String senderNick = line.substring(startIndex, endIndex);
|
||||||
String actionMessage = line.substring(endIndex + 1);
|
String actionMessage = line.substring(endIndex + 1);
|
||||||
tft.setTextColor(nickColors[senderNick]);
|
tft.setTextColor(nickColors[senderNick]);
|
||||||
tft.print(senderNick);
|
tft.print(senderNick + " ");
|
||||||
tft.setTextColor(TFT_MAGENTA);
|
tft.setTextColor(TFT_WHITE);
|
||||||
tft.print(" " + actionMessage);
|
tft.print(actionMessage);
|
||||||
cursorY += CHAR_HEIGHT;
|
cursorY += CHAR_HEIGHT;
|
||||||
} else {
|
} else {
|
||||||
int colonIndex = line.indexOf(':');
|
int colonIndex = line.indexOf(':');
|
||||||
|
Loading…
Reference in New Issue
Block a user