From c1eedf3183260e6c6c85c36dcd3beda62bdc1b16 Mon Sep 17 00:00:00 2001 From: acidvegas Date: Mon, 27 May 2024 16:49:03 -0400 Subject: [PATCH] Added scrolling input text so we can type beyond the width of the screen --- src/main.ino | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main.ino b/src/main.ino index 5e23065..a1b3f75 100644 --- a/src/main.ino +++ b/src/main.ino @@ -209,13 +209,13 @@ void turnOffScreen() { Serial.println("Screen turned off"); tft.writecommand(TFT_DISPOFF); // Turn off display 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; } void turnOnScreen() { 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_DISPON); // Turn on display screenOn = true; @@ -665,9 +665,21 @@ void displayInputLine() { tft.setCursor(0, SCREEN_HEIGHT - INPUT_LINE_HEIGHT); tft.setTextColor(TFT_WHITE); 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) { tft.fillScreen(TFT_BLACK); tft.setTextDatum(MC_DATUM);