Skip to content

Fix scroll trail clearing bugs #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

per1234
Copy link
Contributor

@per1234 per1234 commented Feb 12, 2025

The endText function has the capability to scroll the printed text. In order to ensure artifacts are not left behind on the display while scrolling, the library must clear the pixels at the previous location of the text after each frame of the scrolling animation (#36).

Multiple bugs were found in the code that performs scroll trail clearing, which could cause a trail of artifacts to be left behind on the display when text was scrolled under certain conditions (#50). These bugs may not be immediately apparent to users because pixels are not populated at the edges of some character bitmaps, and thus such characters provide incidental self scroll trail clearing.

The following fixes are proposed by this pull request:

Correct text scroll trail clearing coordinates calculation for left and up directions

Previously, the code to handle this clearing incorrectly calculated the clearing coordinates for the leftwards (SCROLL_LEFT) and upwards (SCROLL_UP) scroll directions, having two separate problems:

  • The offset was subtracted rather than added.
  • An offset of 1 was used, which did not consider the width/height of the text.

Clear trail for full string width when scrolling text vertically

Previously, the code to handle this clearing for vertical scrolling only cleared a single character's width. This meant that scroll trail clearing was only done for the first character in the string.

Previously the ArduinoGraphics::bitmap function was used by the clearing code. That approach was reasonable for clearing the scroll trail of a single character, but due to the function's eight pixel width limitation, it is not suitable to use with strings. In this application where a line of arbitrary length, but only one pixel thick is needed, the ArduinoGraphics::line function is the suitable tool. So the code is ported to using ArduinoGraphics::line.

NOTE: The calculations of the length of the clearing line will still be incorrect for multi-line strings. However, this is not a regression because it was also incorrect before this change. The scroll trail clearing code has never had any provisions for handling multi-line strings so adding such support is out of scope for this commit. In addition, the text scrolling code (not the scroll trail clearing code) has never correctly handled horizontal scrolling of multi-line strings, so until that is fixed it is only the lack of correct scroll trail clearing for vertical scrolling that is impactful to users.

Outstanding defects

Multi-line strings

As was the case before the changes proposed by this PR, scroll trail clearing is not done correctly for multi-line strings. Since this is not a regression, and since the required changes to handle multi-line strings are not trivial, fixing this is considered out of scope for this PR.

The text scrolling code (not the scroll trail clearing code) has never correctly handled horizontal scrolling of multi-line strings, so until that is fixed it is only the lack of correct scroll trail clearing for vertical scrolling that is impactful to users.

Incorrect coordinates

Since it only considers the basic string length, the scroll trail clearing coordinates are incorrect for the leftwards (SCROLL_LEFT) and upwards (SCROLL_UP) scroll directions with multi-line strings.

Incorrect clearing line length

The clearing line length calculation for vertical scrolling is based on the basic string length and so will result in an overly long length for multi-line strings.

The clearing line length calculation for horizontal scrolling assumes the text will only be one character high so will result in a too short length for multi-line strings.

Incomplete scrolling

The calculation for the distance of leftward and upward scrolling is off by one, which results in the text bitmap not being scrolled completely off the display.

This is a defect in the text scrolling code, not in scroll trail clearing. However, it results in what might appear to be an artifact during testing of this proposal, so I thought it worth mentioning here.

A fix has been proposed in #52.


Fixes #50

…nd up directions

The `endText` function has the capability to scroll the printed text. In order to ensure artifacts are not left behind
on the display while scrolling, the library must clear the pixels at the previous location of the text after each frame
of the scrolling animation.

Previously, the code to handle this clearing incorrectly calculated the clearing coordinates for the leftwards
(`SCROLL_LEFT`) and upwards (`SCROLL_UP`) scroll directions, having two separate problems:

* The offset was subtracted rather than added.
* An offset of 1 was used, which did not consider the width/height of the text.

This bug might not be immediately apparent to the user because many character bitmaps do not populate any pixels on the
rightmost column or bottom row of the grid, and thus those characters provide incidental self scroll trail clearing.
However, this is not the case for all characters and those would cause a trail of artifacts to be left behind on the
display when scrolled.

The clearing coordinates calculation code is hereby corrected.

NOTE: The coordinates calculation will still be incorrect for multi-line strings. However, this is not a regression
because it was also incorrect before this change. The scroll trail clearing code has never had any provisions for
handling multi-line strings so addition of such support is out of scope for this commit. In addition, the text scrolling
code (not the scroll trail clearing code) has never correctly handled horizontal scrolling of multi-line strings, so
until that is fixed it is only the lack of correct scroll trail clearing for vertical scrolling that is impactful to
users.
The `endText` function has the capability to scroll the printed text. In order to ensure artifacts are not left behind
on the display while scrolling, the library must clear the pixels at the previous location of the text after each frame
of the scrolling animation.

Previously, the code to handle this clearing for vertical scrolling only cleared a single character's width. This meant
that scroll trail clearing was only done for the first character in the string.

This bug might not be immediately apparent to the user because many character bitmaps do not populate any pixels on the
top or bottom row of the grid, and thus those characters provide incidental self scroll trail clearing. However, this is
not the case for all characters and those would cause a trail of artifacts to be left behind on the display when
scrolled.

The vertical scroll trail clearing code is hereby corrected to cover the full width of the string.

Previously the `ArduinoGraphics::bitmap` function was used by the clearing code. That approach was reasonable for
clearing the scroll trail of a single character, but due to the function's eight pixel width limitation, it is not
suitable to use with strings. In this application where a line of arbitrary length, but only one pixel thick is needed,
the `ArduinoGraphics::line` function is the suitable tool. So the code is ported to using `ArduinoGraphics::line`.

NOTE: The calculations of the length of the clearing line will still be incorrect for multi-line strings. However, this
is not a regression because it was also incorrect before this change. The scroll trail clearing code has never had any
provisions for handling multi-line strings so adding such support is out of scope for this commit. In addition, the text
scrolling code (not the scroll trail clearing code) has never correctly handled horizontal scrolling of multi-line
strings, so until that is fixed it is only the lack of correct scroll trail clearing for vertical scrolling that is
impactful to users.
@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Feb 12, 2025
@per1234 per1234 self-assigned this Feb 12, 2025
Copy link

Memory usage change @ 83d6df0

Board flash % RAM for global variables %
arduino:samd:arduino_zero_edbg 🔺 +180 - +180 +0.07 - +0.07 0 - 0 0.0 - 0.0
arduino:samd:mkrzero 🔺 +180 - +180 +0.07 - +0.07 0 - 0 0.0 - 0.0
arduino:samd:nano_33_iot 🔺 +180 - +180 +0.07 - +0.07 0 - 0 0.0 - 0.0
Click for full report table
Board examples/ASCIIDraw
flash
% examples/ASCIIDraw
RAM for global variables
%
arduino:samd:arduino_zero_edbg 180 0.07 0 0.0
arduino:samd:mkrzero 180 0.07 0 0.0
arduino:samd:nano_33_iot 180 0.07 0 0.0
Click for full report CSV
Board,examples/ASCIIDraw<br>flash,%,examples/ASCIIDraw<br>RAM for global variables,%
arduino:samd:arduino_zero_edbg,180,0.07,0,0.0
arduino:samd:mkrzero,180,0.07,0,0.0
arduino:samd:nano_33_iot,180,0.07,0,0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Scrolling text may leave artifacts when a pixel is populated at trailing edge of graphic
1 participant