Skip to content

ssd1306, uc8151: clear the display only when FillRectangle covers it - #920

Open
hervenicol wants to merge 1 commit into
tinygo-org:devfrom
hervenicol:fillrectangle-clear-origin
Open

hervenicol wants to merge 1 commit into
tinygo-org:devfrom
hervenicol:fillrectangle-clear-origin

Conversation

@hervenicol

@hervenicol hervenicol commented Oct 18, 2026 •

Copy link
Copy Markdown

FillRectangle in ssd1306 and uc8151 has a shortcut: it calls ClearDisplay() for a black rectangle that covers the display.
The check is x+width == dw && y+height == dh, so it only looks at where the rectangle ends. Any black rectangle that ends at the bottom-right corner clears the whole display.
For example, on a 128x64 ssd1306, FillRectangle(100, 63, 28, 1, black) clears all 8192 pixels, not 28.

This change adds x == 0 && y == 0 to the check.
A full-screen black fill still uses ClearDisplay().

I added unit tests for both drivers:

  • A black line at the bottom-right corner changes only its own pixels. This test fails without the fix.
  • A full-screen black fill clears all pixels.

FillRectangle calls ClearDisplay for a black rectangle that ends at the
bottom-right corner of the display. The check does not look at the start
of the rectangle. Thus a black line or a small black rectangle at the
bottom-right corner clears the whole display.

The full-screen shortcut now also requires the rectangle to start at 0,0.

Add tests for FillRectangle in both drivers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant