@@ -55,9 +55,9 @@ class TextArea(displayio.Group):
55
55
def __init__ (self , font , * , text = None , width = None , height = 1 , color = 0xffffff ):
56
56
if not width and not text :
57
57
raise RuntimeError ("Please provide a width" )
58
- super ().__init__ (max_size = width * height )
59
58
if not width :
60
59
width = len (text )
60
+ super ().__init__ (max_size = width * height )
61
61
self .width = width
62
62
self .font = font
63
63
self ._text = None
@@ -77,6 +77,7 @@ def _update_text(self, new_text):
77
77
x = 0
78
78
y = 0
79
79
i = 0
80
+ old_c = 0
80
81
for character in new_text :
81
82
if character == '\n ' :
82
83
y += int (self .height * 1.25 )
@@ -85,19 +86,27 @@ def _update_text(self, new_text):
85
86
glyph = self .font .get_glyph (ord (character ))
86
87
if not glyph :
87
88
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 ]:
89
91
face = displayio .TileGrid (glyph .bitmap , pixel_shader = self .palette ,
90
92
default_tile = glyph .tile_index ,
91
93
tile_width = glyph .width , tile_height = glyph .height ,
92
- position = (x , y + self . height - glyph . height - glyph . dy ))
94
+ position = (x , position_y ))
93
95
if i < len (self ):
94
96
self [i ] = face
95
97
else :
96
98
self .append (face )
99
+ elif self ._text and character == self ._text [old_c ]:
100
+ self [i ].position = (x , position_y )
101
+
97
102
x += glyph .shift_x
98
103
99
104
# TODO skip this for control sequences or non-printables.
100
105
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
101
110
# Remove the rest
102
111
while len (self ) > i :
103
112
self .pop ()
@@ -106,11 +115,11 @@ def _update_text(self, new_text):
106
115
@property
107
116
def color (self ):
108
117
"""Color of the text as an RGB hex number."""
109
- return self .p [1 ]
118
+ return self .palette [1 ]
110
119
111
120
@color .setter
112
121
def color (self , new_color ):
113
- self .p [1 ] = new_color
122
+ self .palette [1 ] = new_color
114
123
115
124
@property
116
125
def text (self ):
0 commit comments