2020# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121# THE SOFTWARE.
2222"""
23- `adafruit_display_text`
23+ `adafruit_display_text.text_area `
2424====================================================
2525
2626Displays text using CircuitPython's displayio.
4444__version__ = "0.0.0-auto.0"
4545__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Text.git"
4646
47-
4847class TextArea (displayio .Group ):
49- def __init__ (self , font , * , text = None , width = None , color = 0xffffff , height = 1 ):
48+ """An area displaying a string of textself.
49+
50+ :param Font font: A font class that has ``get_bounding_box`` and ``get_glyph``
51+ :param str text: Text to display
52+ :param int width: Area width in characters
53+ :param int height: Area height in characters
54+ :param int color: Color of all text in RGB hex"""
55+ def __init__ (self , font , * , text = None , width = None , height = 1 , color = 0xffffff ):
5056 if not width and not text :
5157 raise RuntimeError ("Please provide a width" )
5258 super ().__init__ (max_size = width * height )
@@ -56,9 +62,9 @@ def __init__(self, font, *, text=None, width=None, color=0xffffff, height=1):
5662 self .font = font
5763 self ._text = None
5864
59- self .p = displayio .Palette (2 )
60- self .p .make_transparent (0 )
61- self .p [1 ] = color
65+ self .palette = displayio .Palette (2 )
66+ self .palette .make_transparent (0 )
67+ self .palette [1 ] = color
6268
6369 bounds = self .font .get_bounding_box ()
6470 self .height = bounds [1 ]
@@ -71,17 +77,17 @@ def _update_text(self, new_text):
7177 x = 0
7278 y = 0
7379 i = 0
74- first_different = self ._text is not None
75- for c in new_text :
76- if chr (ord (c )) == '\n ' :
80+ for character in new_text :
81+ if character == '\n ' :
7782 y += int (self .height * 1.25 )
7883 x = 0
7984 continue
80- glyph = self .font .get_glyph (ord (c ))
85+ glyph = self .font .get_glyph (ord (character ))
8186 if not glyph :
8287 continue
83- if not self ._text or i >= len (self ._text ) or c != self ._text [i ]:
84- face = displayio .TileGrid (glyph .bitmap , pixel_shader = self .p , default_tile = glyph .tile_index ,
88+ if not self ._text or i >= len (self ._text ) or character != self ._text [i ]:
89+ face = displayio .TileGrid (glyph .bitmap , pixel_shader = self .palette ,
90+ default_tile = glyph .tile_index ,
8591 tile_width = glyph .width , tile_height = glyph .height ,
8692 position = (x , y + self .height - glyph .height - glyph .dy ))
8793 if i < len (self ):
@@ -99,16 +105,18 @@ def _update_text(self, new_text):
99105
100106 @property
101107 def color (self ):
108+ """Color of the text as an RGB hex number."""
102109 return self .p [1 ]
103110
104111 @color .setter
105- def color (self , c ):
106- self .p [1 ] = c
112+ def color (self , new_color ):
113+ self .p [1 ] = new_color
107114
108115 @property
109- def text (self , t ):
110- self ._text = t
116+ def text (self ):
117+ """Text to display."""
118+ return self ._text
111119
112120 @text .setter
113- def text (self , t ):
114- self ._update_text (t )
121+ def text (self , new_text ):
122+ self ._update_text (new_text )
0 commit comments