@@ -55,9 +55,9 @@ class TextArea(displayio.Group):
5555 def __init__ (self , font , * , text = None , width = None , height = 1 , color = 0xffffff ):
5656 if not width and not text :
5757 raise RuntimeError ("Please provide a width" )
58- super ().__init__ (max_size = width * height )
5958 if not width :
6059 width = len (text )
60+ super ().__init__ (max_size = width * height )
6161 self .width = width
6262 self .font = font
6363 self ._text = None
@@ -77,6 +77,7 @@ def _update_text(self, new_text):
7777 x = 0
7878 y = 0
7979 i = 0
80+ old_c = 0
8081 for character in new_text :
8182 if character == '\n ' :
8283 y += int (self .height * 1.25 )
@@ -85,19 +86,27 @@ def _update_text(self, new_text):
8586 glyph = self .font .get_glyph (ord (character ))
8687 if not glyph :
8788 continue
88- if not self ._text or i >= len (self ._text ) or character != self ._text [i ]:
89+ position_y = y + self .height - glyph .height - glyph .dy
90+ if not self ._text or old_c >= len (self ._text ) or character != self ._text [old_c ]:
8991 face = displayio .TileGrid (glyph .bitmap , pixel_shader = self .palette ,
9092 default_tile = glyph .tile_index ,
9193 tile_width = glyph .width , tile_height = glyph .height ,
92- position = (x , y + self . height - glyph . height - glyph . dy ))
94+ position = (x , position_y ))
9395 if i < len (self ):
9496 self [i ] = face
9597 else :
9698 self .append (face )
99+ elif self ._text and character == self ._text [old_c ]:
100+ self [i ].position = (x , position_y )
101+
97102 x += glyph .shift_x
98103
99104 # TODO skip this for control sequences or non-printables.
100105 i += 1
106+ old_c += 1
107+ # skip all non-prinables in the old string
108+ while self ._text and old_c < len (self ._text ) and (self ._text [old_c ] == '\n ' or not self .font .get_glyph (ord (self ._text [old_c ]))):
109+ old_c += 1
101110 # Remove the rest
102111 while len (self ) > i :
103112 self .pop ()
@@ -106,11 +115,11 @@ def _update_text(self, new_text):
106115 @property
107116 def color (self ):
108117 """Color of the text as an RGB hex number."""
109- return self .p [1 ]
118+ return self .palette [1 ]
110119
111120 @color .setter
112121 def color (self , new_color ):
113- self .p [1 ] = new_color
122+ self .palette [1 ] = new_color
114123
115124 @property
116125 def text (self ):
0 commit comments