Added scrolling input text so we can type beyond the width of the screen

This commit is contained in:
Dionysus 2024-05-27 16:49:03 -04:00
parent 07474dcd0d
commit c1eedf3183
Signed by: acidvegas
GPG Key ID: EF4B922DB85DC9DE

View File

@ -209,13 +209,13 @@ void turnOffScreen() {
Serial.println("Screen turned off"); Serial.println("Screen turned off");
tft.writecommand(TFT_DISPOFF); // Turn off display tft.writecommand(TFT_DISPOFF); // Turn off display
tft.writecommand(TFT_SLPIN); // Put display into sleep mode tft.writecommand(TFT_SLPIN); // Put display into sleep mode
digitalWrite(TFT_BL, LOW); // Turn off the backlight (Assuming TFT_BL is the backlight pin) digitalWrite(TFT_BL, LOW); // Turn off the backlight
screenOn = false; screenOn = false;
} }
void turnOnScreen() { void turnOnScreen() {
Serial.println("Screen turned on"); Serial.println("Screen turned on");
digitalWrite(TFT_BL, HIGH); // Turn on the backlight (Assuming TFT_BL is the backlight pin) digitalWrite(TFT_BL, HIGH); // Turn on the backlight
tft.writecommand(TFT_SLPOUT); // Wake up display from sleep mode tft.writecommand(TFT_SLPOUT); // Wake up display from sleep mode
tft.writecommand(TFT_DISPON); // Turn on display tft.writecommand(TFT_DISPON); // Turn on display
screenOn = true; screenOn = true;
@ -665,9 +665,21 @@ void displayInputLine() {
tft.setCursor(0, SCREEN_HEIGHT - INPUT_LINE_HEIGHT); tft.setCursor(0, SCREEN_HEIGHT - INPUT_LINE_HEIGHT);
tft.setTextColor(TFT_WHITE); tft.setTextColor(TFT_WHITE);
tft.setTextSize(1); tft.setTextSize(1);
tft.print("> " + inputBuffer);
int inputWidth = SCREEN_WIDTH - tft.textWidth("> ");
String displayInput = inputBuffer;
int displayWidth = tft.textWidth(displayInput);
// Scrolling input text
while (displayWidth > inputWidth) {
displayInput = displayInput.substring(1);
displayWidth = tft.textWidth(displayInput);
} }
tft.print("> " + displayInput);
}
void displayCenteredText(String text) { void displayCenteredText(String text) {
tft.fillScreen(TFT_BLACK); tft.fillScreen(TFT_BLACK);
tft.setTextDatum(MC_DATUM); tft.setTextDatum(MC_DATUM);