@@ -79,18 +79,16 @@ def __init__(
7979 padding_right = 0 ,
8080 anchor_point = None ,
8181 anchored_position = None ,
82- ** kwargs
82+ scale = 1 ,
8383 ):
84- if "scale" in kwargs .keys ():
85- self ._scale = kwargs ["scale" ]
86- else :
87- self ._scale = 1
8884 if not max_glyphs and not text :
8985 raise RuntimeError ("Please provide a max size, or initial text" )
9086 if not max_glyphs :
9187 max_glyphs = len (text )
9288 # add one to max_size for the background bitmap tileGrid
93- super ().__init__ (max_size = max_glyphs + 1 , ** kwargs )
89+ super ().__init__ (max_size = 1 )
90+ self .local_group = displayio .Group (max_size = max_glyphs + 1 , scale = scale )
91+ self .append (self .local_group )
9492
9593 self .width = max_glyphs
9694 self ._font = font
@@ -121,12 +119,15 @@ def __init__(
121119 self ._padding_bottom = padding_bottom
122120 self ._padding_left = padding_left
123121 self ._padding_right = padding_right
122+
123+ self ._scale = scale
124124
125125 if text is not None :
126126 self ._update_text (str (text ))
127127 if (anchored_position is not None ) and (anchor_point is not None ):
128128 self .anchored_position = anchored_position
129129
130+
130131 def _create_background_box (self , lines , y_offset ):
131132
132133 left = self ._boundingbox [0 ]
@@ -172,14 +173,16 @@ def _create_background_box(self, lines, y_offset):
172173 y = y_box_offset ,
173174 )
174175
176+
177+
175178 return tile_grid
176179
177180 def _update_background_color (self , new_color ):
178181
179182 if new_color is None :
180183 self ._background_palette .make_transparent (0 )
181184 if self ._added_background_tilegrid :
182- self .pop (0 )
185+ self .local_group . pop (0 )
183186 self ._added_background_tilegrid = False
184187 else :
185188 self ._background_palette .make_opaque (0 )
@@ -200,10 +203,10 @@ def _update_background_color(self, new_color):
200203 self ._boundingbox [3 ] + self ._padding_top + self ._padding_bottom > 0
201204 )
202205 ):
203- if len (self ) > 0 :
204- self .insert (0 , self ._create_background_box (lines , y_offset ))
206+ if len (self . local_group ) > 0 : # This can be simplified in CP v6.0, when group.append(0) bug is corrected
207+ self .local_group . insert (0 , self ._create_background_box (lines , y_offset ))
205208 else :
206- self .append (self ._create_background_box (lines , y_offset ))
209+ self .local_group . append (self ._create_background_box (lines , y_offset ))
207210 self ._added_background_tilegrid = True
208211
209212 else : # a bitmap is present in the self Group
@@ -217,9 +220,9 @@ def _update_background_color(self, new_color):
217220 self ._boundingbox [3 ] + self ._padding_top + self ._padding_bottom > 0
218221 )
219222 ):
220- self [0 ] = self ._create_background_box (lines , y_offset )
223+ self . local_group [0 ] = self ._create_background_box (lines , y_offset )
221224 else : # delete the existing bitmap
222- self .pop (0 )
225+ self .local_group . pop (0 )
223226 self ._added_background_tilegrid = False
224227
225228 def _update_text (
@@ -284,10 +287,10 @@ def _update_text(
284287 x = position_x ,
285288 y = position_y ,
286289 )
287- if tilegrid_count < len (self ):
288- self [tilegrid_count ] = face
290+ if tilegrid_count < len (self . local_group ):
291+ self . local_group [tilegrid_count ] = face
289292 else :
290- self .append (face )
293+ self .local_group . append (face )
291294 tilegrid_count += 1
292295 x += glyph .shift_x
293296 i += 1
@@ -296,8 +299,8 @@ def _update_text(
296299 if left is None :
297300 left = 0
298301
299- while len (self ) > tilegrid_count : # i:
300- self .pop ()
302+ while len (self . local_group ) > tilegrid_count : # i:
303+ self .local_group . pop ()
301304 self ._text = new_text
302305 self ._boundingbox = (left , top , right - left , bottom - top )
303306
@@ -319,6 +322,7 @@ def line_spacing(self):
319322 @line_spacing .setter
320323 def line_spacing (self , spacing ):
321324 self ._line_spacing = spacing
325+ self .text = self ._text # redraw the box
322326
323327 @property
324328 def color (self ):
@@ -358,6 +362,19 @@ def text(self, new_text):
358362 except RuntimeError as run_error :
359363 raise RuntimeError ("Text length exceeds max_glyphs" ) from run_error
360364
365+ @property
366+ def scale (self ):
367+ return self ._scale
368+
369+ @scale .setter
370+ def scale (self , new_scale ):
371+ current_anchored_position = self .anchored_position
372+ self ._scale = new_scale
373+ self .local_group .scale = new_scale
374+ self .anchored_position = current_anchored_position
375+
376+
377+
361378 @property
362379 def font (self ):
363380 """Font to use for text display."""
0 commit comments