From cab650c4ade313cc7858883a6a4182030c891cc2 Mon Sep 17 00:00:00 2001 From: Sebastian Romero Date: Mon, 7 Sep 2026 14:09:48 +0200 Subject: [PATCH] Fix scrolling text smearing at text sizes above 1 endText() moves the text one pixel per frame and, rather than repainting the screen, erases only the single line the text just vacated. That erase has to land exactly on the trailing edge, because nothing else will cover it. It did not. The travel distance came from textFontWidth() and textFontHeight(), which scale with textSize(), but the erase was positioned from _font->width and _font->height, which do not. The two agree only at textSize(1). Above that the erase fell short of the trailing edge and left a line of pixels behind on every frame, so glyphs smeared in the scroll direction. Use the scaled accessors for the erase as well. SCROLL_RIGHT was the least affected because the space-glyph bitmap drawn just after the erase already covers the full scaled height, which is why horizontal scrolling could look correct while vertical scrolling did not. Modelling the painted and erased regions frame by frame, stale pixels per frame before and after, for Font_5x7: size LEFT RIGHT UP DOWN LEFT RIGHT UP DOWN 1x1 0 0 0 0 0 0 0 0 2x2 14 0 20 20 -> 0 0 0 0 3x1 7 0 20 40 0 0 0 0 1x3 14 0 10 0 0 0 0 0 The two bitmap() calls are left alone: they take unscaled source dimensions plus separate scale factors, so passing _font->width and _font->height there is correct. Co-Authored-By: Claude Opus 5 --- src/ArduinoGraphics.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ArduinoGraphics.cpp b/src/ArduinoGraphics.cpp index 2a62a3a..0116c58 100644 --- a/src/ArduinoGraphics.cpp +++ b/src/ArduinoGraphics.cpp @@ -445,9 +445,9 @@ void ArduinoGraphics::endText(int scrollDirection) text(_textBuffer, text_x, _textY); // clear previous position - const int clearX = text_x + _textBuffer.length() * _font->width; + const int clearX = text_x + _textBuffer.length() * textFontWidth(); stroke(_backgroundR, _backgroundG, _backgroundB); - line(clearX, _textY, clearX, _textY + _font->height - 1); + line(clearX, _textY, clearX, _textY + textFontHeight() - 1); endDraw(); @@ -466,7 +466,7 @@ void ArduinoGraphics::endText(int scrollDirection) // clear previous position const int clearX = text_x - 1; stroke(_backgroundR, _backgroundG, _backgroundB); - line(clearX, _textY, clearX, _textY + _font->height - 1); + line(clearX, _textY, clearX, _textY + textFontHeight() - 1); bitmap(_font->data[0x20], text_x - 1, _textY, 1, _font->height, _textSizeX, _textSizeY); @@ -485,9 +485,9 @@ void ArduinoGraphics::endText(int scrollDirection) text(_textBuffer, _textX, text_y); // clear previous position - const int clearY = text_y + _font->height; + const int clearY = text_y + textFontHeight(); stroke(_backgroundR, _backgroundG, _backgroundB); - line(_textX, clearY, _textX + (_font->width * _textBuffer.length()) - 1, clearY); + line(_textX, clearY, _textX + (textFontWidth() * _textBuffer.length()) - 1, clearY); endDraw(); @@ -506,7 +506,7 @@ void ArduinoGraphics::endText(int scrollDirection) // clear previous position const int clearY = text_y - 1; stroke(_backgroundR, _backgroundG, _backgroundB); - line(_textX, clearY, _textX + (_font->width * _textBuffer.length()) - 1, clearY); + line(_textX, clearY, _textX + (textFontWidth() * _textBuffer.length()) - 1, clearY); bitmap(_font->data[0x20], _textX, text_y - 1, _font->width, 1, _textSizeX, _textSizeY); endDraw();