@@ -164,15 +164,17 @@ def _create_background_box(self, lines, y_offset):
164
164
box_width = max (0 , box_width ) # remove any negative values
165
165
box_height = max (0 , box_height ) # remove any negative values
166
166
167
- background_bitmap = displayio .Bitmap (box_width , box_height , 1 )
168
- tile_grid = displayio .TileGrid (
169
- background_bitmap ,
170
- pixel_shader = self ._background_palette ,
171
- x = left + x_box_offset ,
172
- y = y_box_offset ,
173
- )
174
-
175
- return tile_grid
167
+ if box_width > 0 and box_height > 0 :
168
+ background_bitmap = displayio .Bitmap (box_width , box_height , 1 )
169
+ tile_grid = displayio .TileGrid (
170
+ background_bitmap ,
171
+ pixel_shader = self ._background_palette ,
172
+ x = left + x_box_offset ,
173
+ y = y_box_offset ,
174
+ )
175
+ return tile_grid
176
+ else :
177
+ return None
176
178
177
179
def _update_background_color (self , new_color ):
178
180
@@ -270,6 +272,7 @@ def _update_text(self, new_text): # pylint: disable=too-many-locals
270
272
self ._boundingbox = (left , top , left + right , bottom - top )
271
273
self [0 ] = self ._create_background_box (lines , y_offset )
272
274
275
+
273
276
@property
274
277
def bounding_box (self ):
275
278
"""An (x, y, w, h) tuple that completely covers all glyphs. The
@@ -313,8 +316,11 @@ def text(self):
313
316
def text (self , new_text ):
314
317
try :
315
318
current_anchored_position = self .anchored_position
319
+ print ('start anchored_position: {}' .format (self .anchored_position ))
320
+ print ('self.y: {}, self._scale: {}' .format (self .y , self ._scale ))
316
321
self ._update_text (str (new_text ))
317
322
self .anchored_position = current_anchored_position
323
+ print ('end anchored_position: {}' .format (self .anchored_position ))
318
324
except RuntimeError :
319
325
raise RuntimeError ("Text length exceeds max_glyphs" )
320
326
@@ -351,22 +357,25 @@ def anchored_position(self):
351
357
"""Position relative to the anchor_point. Tuple containing x,y
352
358
pixel coordinates."""
353
359
return (
354
- int (self .x + self ._anchor_point [0 ] * self ._boundingbox [2 ] * self ._scale ),
355
- int (self .y + self ._anchor_point [1 ] * self ._boundingbox [3 ] * self ._scale
356
- - ( self ._boundingbox [3 ] * self ._scale )/ 2 )
357
- )
360
+ int (self .x + ( self ._anchor_point [0 ] * self ._boundingbox [2 ] * self ._scale ) ),
361
+ int (self .y + ( self ._anchor_point [1 ] * self ._boundingbox [3 ] * self ._scale )
362
+ - round ( ( self ._boundingbox [3 ] * self ._scale )/ 2.0 ) )
363
+ )
358
364
359
365
@anchored_position .setter
360
366
def anchored_position (self , new_position ):
361
367
new_x = int (
362
368
new_position [0 ]
363
369
- self ._anchor_point [0 ] * (self ._boundingbox [2 ] * self ._scale )
364
370
)
365
- new_y = self . y = int (
371
+ new_y = int (
366
372
new_position [1 ]
367
- - self ._anchor_point [1 ] * ( self ._boundingbox [3 ] * self ._scale )
368
- + ( self ._boundingbox [3 ] * self ._scale )/ 2
373
+ - ( self ._anchor_point [1 ] * self ._boundingbox [3 ] * self ._scale )
374
+ + round ( ( self ._boundingbox [3 ] * self ._scale )/ 2.0 )
369
375
)
376
+
377
+ print ('new_y: {}, new_position[1]: {}, self._anchor_point[1]: {}, self._boundingbox[3]: {}' .format (new_y , new_position [1 ], self ._anchor_point [1 ], self ._boundingbox [3 ]))
378
+
370
379
self ._boundingbox = (new_x , new_y , self ._boundingbox [2 ], self ._boundingbox [3 ])
371
380
self .x = new_x
372
381
self .y = new_y
0 commit comments