The adafruit_display_text library currently has two different types of label functionss in it. This page will go over those label functions and the differences between them. If you are less concerned about the details and just want to know which to use for your new project, go with BitmapLabel.

Label

There are changes in progress internally within displayio.Group that change this behavior and remove the max_size requirement. In the absolute newest builds, Group no longer has this restriction.

This is the original Label class. Each glyph within the text is stored in its own Bitmap and TileGrid objects, and those all get put into a single Group object. Because Group has a max_size that determines how many things can be added to it, Label must choose a max_size to use for the underlying Group. This is why you must pass either the text or max_glyphs parameter when you initialize the Label. It needs to know how many things to make room for in its Group. If you don't pass in one or the other, you'll get an error.

If you set a background_color, then the background will get its own TileGrid and Bitmap as well. The diagram above depicts a Label with no background Bitmap in it.

BitmapLabel

This is a newer class that was introduced more recently after many features were added into the original Label class. In the BitmapLabel, all of the glyphs are stored inside of a single Bitmap and TileGrid. This tends to result in lower memory usage, especially for long strings.

There are changes in progress internally within displayio.Group that change this behavior and remove the max_size requirement. In the absolute newest builds, Group no longer has this restriction.

Since all of the glyphs are inside of a single Bitmap, it does not need to base the Group's max_size on the number of characters in the string. Any BitmapLabel can hold any number of characters; there is no specific maximum other than RAM and screen real estate. BitmapLabel does accept a max_glyphs parameter, but its value is ignored. This parameter is provided only for compatibility with the Label class so that code can be very easily swapped from one to the other without generating errors. BitmapLabel typically will use a little bit less RAM -- it can be helpful sometimes in larger projects to switch from Label to BitmapLabel to save more RAM for your projects other needs.

Advanced Color Masking 

BitmapLabel can be used with None value for color and any opaque value for background_color to produce a transparent "cutout" of the text in the label. You can put rainbows or other interesting things in the background, and layer the BitmapLabel on top to produce fancy text graphics. See the example here.

This guide was first published on Mar 09, 2021. It was last updated on 2021-03-09 10:58:42 -0500.

This page (Types of Labels) was last updated on Apr 22, 2021.

Text editor powered by tinymce.