@@ -79,18 +79,16 @@ def __init__(
79
79
padding_right = 0 ,
80
80
anchor_point = None ,
81
81
anchored_position = None ,
82
- ** kwargs
82
+ scale = 1 ,
83
83
):
84
- if "scale" in kwargs .keys ():
85
- self ._scale = kwargs ["scale" ]
86
- else :
87
- self ._scale = 1
88
84
if not max_glyphs and not text :
89
85
raise RuntimeError ("Please provide a max size, or initial text" )
90
86
if not max_glyphs :
91
87
max_glyphs = len (text )
92
88
# 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 )
94
92
95
93
self .width = max_glyphs
96
94
self ._font = font
@@ -121,12 +119,15 @@ def __init__(
121
119
self ._padding_bottom = padding_bottom
122
120
self ._padding_left = padding_left
123
121
self ._padding_right = padding_right
122
+
123
+ self ._scale = scale
124
124
125
125
if text is not None :
126
126
self ._update_text (str (text ))
127
127
if (anchored_position is not None ) and (anchor_point is not None ):
128
128
self .anchored_position = anchored_position
129
129
130
+
130
131
def _create_background_box (self , lines , y_offset ):
131
132
132
133
left = self ._boundingbox [0 ]
@@ -172,14 +173,16 @@ def _create_background_box(self, lines, y_offset):
172
173
y = y_box_offset ,
173
174
)
174
175
176
+
177
+
175
178
return tile_grid
176
179
177
180
def _update_background_color (self , new_color ):
178
181
179
182
if new_color is None :
180
183
self ._background_palette .make_transparent (0 )
181
184
if self ._added_background_tilegrid :
182
- self .pop (0 )
185
+ self .local_group . pop (0 )
183
186
self ._added_background_tilegrid = False
184
187
else :
185
188
self ._background_palette .make_opaque (0 )
@@ -200,10 +203,10 @@ def _update_background_color(self, new_color):
200
203
self ._boundingbox [3 ] + self ._padding_top + self ._padding_bottom > 0
201
204
)
202
205
):
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 ))
205
208
else :
206
- self .append (self ._create_background_box (lines , y_offset ))
209
+ self .local_group . append (self ._create_background_box (lines , y_offset ))
207
210
self ._added_background_tilegrid = True
208
211
209
212
else : # a bitmap is present in the self Group
@@ -217,9 +220,9 @@ def _update_background_color(self, new_color):
217
220
self ._boundingbox [3 ] + self ._padding_top + self ._padding_bottom > 0
218
221
)
219
222
):
220
- self [0 ] = self ._create_background_box (lines , y_offset )
223
+ self . local_group [0 ] = self ._create_background_box (lines , y_offset )
221
224
else : # delete the existing bitmap
222
- self .pop (0 )
225
+ self .local_group . pop (0 )
223
226
self ._added_background_tilegrid = False
224
227
225
228
def _update_text (
@@ -284,10 +287,10 @@ def _update_text(
284
287
x = position_x ,
285
288
y = position_y ,
286
289
)
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
289
292
else :
290
- self .append (face )
293
+ self .local_group . append (face )
291
294
tilegrid_count += 1
292
295
x += glyph .shift_x
293
296
i += 1
@@ -296,8 +299,8 @@ def _update_text(
296
299
if left is None :
297
300
left = 0
298
301
299
- while len (self ) > tilegrid_count : # i:
300
- self .pop ()
302
+ while len (self . local_group ) > tilegrid_count : # i:
303
+ self .local_group . pop ()
301
304
self ._text = new_text
302
305
self ._boundingbox = (left , top , right - left , bottom - top )
303
306
@@ -319,6 +322,7 @@ def line_spacing(self):
319
322
@line_spacing .setter
320
323
def line_spacing (self , spacing ):
321
324
self ._line_spacing = spacing
325
+ self .text = self ._text # redraw the box
322
326
323
327
@property
324
328
def color (self ):
@@ -358,6 +362,19 @@ def text(self, new_text):
358
362
except RuntimeError as run_error :
359
363
raise RuntimeError ("Text length exceeds max_glyphs" ) from run_error
360
364
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
+
361
378
@property
362
379
def font (self ):
363
380
"""Font to use for text display."""
0 commit comments