adafruit / Adafruit_CircuitPython_Display_Text

Library to display text using displayio
MIT License
57 stars 38 forks source link

Improved memory efficiency for some text updates to bitmap_label.Label #167

Closed kevinjwalters closed 2 years ago

kevinjwalters commented 2 years ago
  1. bitmap_label.Label - the self._bitmap and self._tilegrid is no longer recreated all the time
    1. This makes it more efficient for updates for text have the same length particularly in terms of avoiding creating a new Bitmap (and TileGrid) using more memory briefly and potentially causing memory fragmentation.
    2. Adding a new self._prev_label_direction to support label_direction properly.
  2. Fixed an unrelated bug in label_direction for RTL which would toggle direction if the value was repeatedly set - text reversal is now performed as text is set and not stored.
  3. _replace_tabs() function also enhanced to only do split/join if tabs are present - this is probably a rare case and it's inefficient to be making new text strings all the time.

The most efficient updates are now if the text string is the same character length as the previous value. The bitmap is cleared with fill(0) and re-written and this can cause flicker. The cognoscenti will be controlling display refresh, of course.