@@ -62,22 +62,22 @@ class Label(displayio.Group):
62
62
# This has a lot of getters/setters, maybe it needs cleanup.
63
63
64
64
def __init__ (
65
- self ,
66
- font ,
67
- * ,
68
- x = 0 ,
69
- y = 0 ,
70
- text = "" ,
71
- max_glyphs = None ,
72
- color = 0xFFFFFF ,
73
- background_color = None ,
74
- line_spacing = 1.25 ,
75
- background_tight = False ,
76
- padding_top = 0 ,
77
- padding_bottom = 0 ,
78
- padding_left = 0 ,
79
- padding_right = 0 ,
80
- ** kwargs
65
+ self ,
66
+ font ,
67
+ * ,
68
+ x = 0 ,
69
+ y = 0 ,
70
+ text = "" ,
71
+ max_glyphs = None ,
72
+ color = 0xFFFFFF ,
73
+ background_color = None ,
74
+ line_spacing = 1.25 ,
75
+ background_tight = False ,
76
+ padding_top = 0 ,
77
+ padding_bottom = 0 ,
78
+ padding_left = 0 ,
79
+ padding_right = 0 ,
80
+ ** kwargs
81
81
):
82
82
if "scale" in kwargs .keys ():
83
83
self ._scale = kwargs ["scale" ]
@@ -89,7 +89,6 @@ def __init__(
89
89
max_glyphs = len (text )
90
90
# add one to max_size for the background bitmap tileGrid
91
91
super ().__init__ (max_size = max_glyphs + 1 , ** kwargs )
92
- print ("max_size={}" .format (max_glyphs + 1 ))
93
92
94
93
self .width = max_glyphs
95
94
self ._font = font
@@ -115,7 +114,6 @@ def __init__(
115
114
self ._background_palette = displayio .Palette (1 )
116
115
self ._added_background_tilegrid = False
117
116
if self ._background_color :
118
- print ("adding background tilegrid from init" )
119
117
self .append (
120
118
displayio .TileGrid (
121
119
displayio .Bitmap (1 , 1 , 1 ), pixel_shader = self ._background_palette
@@ -158,14 +156,13 @@ def _create_background_box(self, lines, y_offset):
158
156
box_width = self ._boundingbox [2 ] + self ._padding_left + self ._padding_right
159
157
x_box_offset = - self ._padding_left
160
158
box_height = (
161
- (ascender_max + descender_max )
162
- + int ((lines - 1 ) * self .height * self ._line_spacing )
163
- + self ._padding_top
164
- + self ._padding_bottom
159
+ (ascender_max + descender_max )
160
+ + int ((lines - 1 ) * self .height * self ._line_spacing )
161
+ + self ._padding_top
162
+ + self ._padding_bottom
165
163
)
166
164
y_box_offset = - ascender_max + y_offset - self ._padding_top
167
165
168
- # self._update_background_color(self._background_color)
169
166
box_width = max (0 , box_width ) # remove any negative values
170
167
box_height = max (0 , box_height ) # remove any negative values
171
168
@@ -176,12 +173,12 @@ def _create_background_box(self, lines, y_offset):
176
173
x = left + x_box_offset ,
177
174
y = y_box_offset ,
178
175
)
176
+
179
177
return tile_grid
180
178
181
179
def _update_background_color (self , new_color ):
182
180
183
181
if new_color is None :
184
- print ("setting {} transparent" .format (self ._background_palette [0 ]))
185
182
self ._background_palette .make_transparent (0 )
186
183
else :
187
184
self ._background_palette .make_opaque (0 )
@@ -190,22 +187,20 @@ def _update_background_color(self, new_color):
190
187
191
188
y_offset = int (
192
189
(
193
- self ._font .get_glyph (ord ("M" )).height
194
- - self .text .count ("\n " ) * self .height * self .line_spacing
190
+ self ._font .get_glyph (ord ("M" )).height
191
+ - self .text .count ("\n " ) * self .height * self .line_spacing
195
192
)
196
193
/ 2
197
194
)
198
195
lines = self .text .count ("\n " ) + 1
199
196
if not self ._added_background_tilegrid :
200
197
201
198
self ._added_background_tilegrid = True
202
- print ("adding background tilegrid in update background color" )
203
- print ("len self = {}" .format (len (self )))
204
199
self .insert (0 , self ._create_background_box (lines , y_offset ))
205
200
else :
206
201
self [0 ] = self ._create_background_box (lines , y_offset )
207
202
208
- def _update_text (self , new_text ): # pylint: disable=too-many-locals
203
+ def _update_text (self , new_text ): # pylint: disable=too-many-locals ,too-many-branches, too-many-statements
209
204
x = 0
210
205
y = 0
211
206
if self ._added_background_tilegrid :
@@ -215,8 +210,8 @@ def _update_text(self, new_text): # pylint: disable=too-many-locals
215
210
old_c = 0
216
211
y_offset = int (
217
212
(
218
- self ._font .get_glyph (ord ("M" )).height
219
- - new_text .count ("\n " ) * self .height * self .line_spacing
213
+ self ._font .get_glyph (ord ("M" )).height
214
+ - new_text .count ("\n " ) * self .height * self .line_spacing
220
215
)
221
216
/ 2
222
217
)
@@ -238,9 +233,9 @@ def _update_text(self, new_text): # pylint: disable=too-many-locals
238
233
position_y = y - glyph .height - glyph .dy + y_offset
239
234
position_x = x + glyph .dx
240
235
if (
241
- not self ._text
242
- or old_c >= len (self ._text )
243
- or character != self ._text [old_c ]
236
+ not self ._text
237
+ or old_c >= len (self ._text )
238
+ or character != self ._text [old_c ]
244
239
):
245
240
try :
246
241
# pylint: disable=unexpected-keyword-arg
@@ -265,7 +260,6 @@ def _update_text(self, new_text): # pylint: disable=too-many-locals
265
260
if i < len (self ):
266
261
self [i ] = face
267
262
else :
268
- print ("appending face" )
269
263
self .append (face )
270
264
elif self ._text and character == self ._text [old_c ]:
271
265
@@ -281,26 +275,26 @@ def _update_text(self, new_text): # pylint: disable=too-many-locals
281
275
old_c += 1
282
276
# skip all non-printables in the old string
283
277
while (
284
- self ._text
285
- and old_c < len (self ._text )
286
- and (
287
- self ._text [old_c ] == "\n "
288
- or not self ._font .get_glyph (ord (self ._text [old_c ]))
289
- )
278
+ self ._text
279
+ and old_c < len (self ._text )
280
+ and (
281
+ self ._text [old_c ] == "\n "
282
+ or not self ._font .get_glyph (ord (self ._text [old_c ]))
283
+ )
290
284
):
291
285
old_c += 1
292
286
# Remove the rest
293
287
while len (self ) > i :
294
288
self .pop ()
295
289
self ._text = new_text
296
290
self ._boundingbox = (left , top , left + right , bottom - top )
297
- print ("bg color: {}" .format (self ._background_color ))
298
- if self ._background_color and len (new_text ) + self ._padding_left + self ._padding_right > 0 :
291
+ if (
292
+ self ._background_color
293
+ and len (new_text ) + self ._padding_left + self ._padding_right > 0
294
+ ):
299
295
if not self ._added_background_tilegrid :
300
296
301
297
self ._added_background_tilegrid = True
302
- print ("adding background tilegrid" )
303
- print ("len self = {}" .format (len (self )))
304
298
self .insert (0 , self ._create_background_box (lines , y_offset ))
305
299
else :
306
300
self [0 ] = self ._create_background_box (lines , y_offset )
@@ -405,6 +399,5 @@ def anchored_position(self, new_position):
405
399
- (self ._anchor_point [1 ] * self ._boundingbox [3 ] * self ._scale )
406
400
+ round ((self ._boundingbox [3 ] * self ._scale ) / 2.0 )
407
401
)
408
- self ._boundingbox = (new_x , new_y , self ._boundingbox [2 ], self ._boundingbox [3 ])
409
402
self .x = new_x
410
403
self .y = new_y
0 commit comments