More code cleanup and comments

This commit is contained in:
Dionysus 2024-05-28 18:56:20 -04:00
parent f4dc64fd69
commit af93986495
Signed by: acidvegas
GPG Key ID: EF4B922DB85DC9DE
1 changed files with 5 additions and 7 deletions

View File

@ -740,13 +740,11 @@ int renderFormattedMessage(String message, int cursorY, int lineHeight, bool hig
cursorY += lineHeight; cursorY += lineHeight;
tft.setCursor(0, cursorY); tft.setCursor(0, cursorY);
} }
if (c == ' ') { if (c == ' ') { // Handle spaces separately to ensure background color is applied (do we need this anyhmore since .trim() was removed?)
// Draw background for spaces
int spaceWidth = tft.textWidth(" "); int spaceWidth = tft.textWidth(" ");
tft.fillRect(tft.getCursorX(), tft.getCursorY(), spaceWidth, lineHeight, bgColor); tft.fillRect(tft.getCursorX(), tft.getCursorY(), spaceWidth, lineHeight, bgColor);
tft.setCursor(tft.getCursorX() + spaceWidth, tft.getCursorY()); tft.setCursor(tft.getCursorX() + spaceWidth, tft.getCursorY());
} else { } else {
// Ensure that background color is applied to characters
tft.fillRect(tft.getCursorX(), tft.getCursorY(), tft.textWidth(String(c)), lineHeight, bgColor); tft.fillRect(tft.getCursorX(), tft.getCursorY(), tft.textWidth(String(c)), lineHeight, bgColor);
tft.setTextColor(fgColor, bgColor); tft.setTextColor(fgColor, bgColor);
tft.print(c); tft.print(c);
@ -755,7 +753,7 @@ int renderFormattedMessage(String message, int cursorY, int lineHeight, bool hig
} }
} }
// Ensure trailing spaces are displayed with background color // Ensure trailing spaces are displayed with background color (do we need this anymore since .trim() was removed?)
if (message.endsWith(" ")) { if (message.endsWith(" ")) {
int trailingSpaces = 0; int trailingSpaces = 0;
for (int i = message.length() - 1; i >= 0 && message[i] == ' '; i--) { for (int i = message.length() - 1; i >= 0 && message[i] == ' '; i--) {
@ -913,7 +911,7 @@ void addLine(String senderNick, String message, String type, uint16_t errorColor
formattedMessage = "* " + senderNick + " " + message; formattedMessage = "* " + senderNick + " " + message;
} else if (type == "error") { } else if (type == "error") {
formattedMessage = "ERROR " + message; formattedMessage = "ERROR " + message;
senderNick = "ERROR"; // Use ERROR as senderNick to highlight it in red senderNick = "ERROR"; // Probably a better way to handle this than emulating a NICK
} else { } else {
formattedMessage = senderNick + ": " + message; formattedMessage = senderNick + ": " + message;
} }
@ -1054,9 +1052,9 @@ void displayInputLine() {
tft.setTextColor(TFT_WHITE); tft.setTextColor(TFT_WHITE);
tft.setTextSize(1); tft.setTextSize(1);
int inputWidth = SCREEN_WIDTH - tft.textWidth("> ");
String displayInput = inputBuffer; String displayInput = inputBuffer;
int displayWidth = tft.textWidth(displayInput); int displayWidth = tft.textWidth(displayInput);
int inputWidth = SCREEN_WIDTH - tft.textWidth("> ");
// Allow the input to scroll if it exceeds the screen width // Allow the input to scroll if it exceeds the screen width
while (displayWidth > inputWidth) { while (displayWidth > inputWidth) {