@@ -97,17 +97,15 @@ def __init__(
9797 self .palette .make_transparent (0 )
9898 self .palette [1 ] = color
9999
100- self ._background_color = background_color
101-
102- # bounds = self._font.get_bounding_box()
103100 self .height = self ._font .get_bounding_box ()[1 ]
104101 self ._line_spacing = line_spacing
105102 self ._boundingbox = None
106103
107104 self ._background_tight = (
108- background_tight # sets padding status for text background
105+ background_tight # sets padding status for text background box
109106 )
110107
108+ self ._background_color = background_color
111109 self ._background_palette = displayio .Palette (1 )
112110 self .append (
113111 displayio .TileGrid (
@@ -146,9 +144,7 @@ def _create_background_box(self, lines, y_offset):
146144 ascender_max = max (ascender_max , this_glyph .height + this_glyph .dy )
147145 descender_max = max (descender_max , - this_glyph .dy )
148146
149- box_width = (
150- self ._boundingbox [2 ] + self ._padding_left + self ._padding_right
151- ) # left + right padding
147+ box_width = self ._boundingbox [2 ] + self ._padding_left + self ._padding_right
152148 x_box_offset = - self ._padding_left
153149 box_height = (
154150 (ascender_max + descender_max )
@@ -204,9 +200,7 @@ def _update_text(self, new_text): # pylint: disable=too-many-locals
204200 glyph = self ._font .get_glyph (ord (character ))
205201 if not glyph :
206202 continue
207- right = max (
208- right , x + glyph .shift_x
209- ) # studied the docs! This is the correct spacing
203+ right = max (right , x + glyph .shift_x )
210204 if y == 0 : # first line, find the Ascender height
211205 top = min (top , - glyph .height - glyph .dy + y_offset )
212206 bottom = max (bottom , y - glyph .dy + y_offset )
@@ -267,49 +261,6 @@ def _update_text(self, new_text): # pylint: disable=too-many-locals
267261 self .pop ()
268262 self ._text = new_text
269263 self ._boundingbox = (left , top , left + right , bottom - top )
270-
271- # if self._background_tight: # draw a tight bounding box
272- # box_width = self._boundingbox[2]
273- # box_height = self._boundingbox[3]
274- # x_box_offset = 0
275- # y_box_offset = top
276-
277- # else: # draw a "loose" bounding box to include any ascenders/descenders.
278-
279- # # check a few glyphs for maximum ascender and descender height
280- # # Enhancement: it would be preferred to access the font "FONT_ASCENT" and
281- # # "FONT_DESCENT" in the imported BDF file
282- # glyphs = "M j'" # choose glyphs with highest ascender and lowest
283- # # descender, will depend upon font used
284- # ascender_max = descender_max = 0
285- # for char in glyphs:
286- # this_glyph = self._font.get_glyph(ord(char))
287- # ascender_max = max(ascender_max, this_glyph.height + this_glyph.dy)
288- # descender_max = max(descender_max, -this_glyph.dy)
289-
290- # box_width = self._boundingbox[2] + self._padding_left + self._padding_right
291- # x_box_offset = -self._padding_left
292- # box_height = (
293- # (ascender_max + descender_max)
294- # + int((lines - 1) * self.height * self._line_spacing)
295- # + self._padding_top
296- # + self._padding_bottom
297- # )
298- # y_box_offset = -ascender_max + y_offset - self._padding_top
299-
300- # self._update_background_color(self._background_color)
301- # box_width = max(0, box_width) # remove any negative values
302- # box_height = max(0, box_height) # remove any negative values
303-
304- # background_bitmap = displayio.Bitmap(box_width, box_height, 1)
305- # tile_grid = displayio.TileGrid(
306- # background_bitmap,
307- # pixel_shader=self._background_palette,
308- # x=left + x_box_offset,
309- # y=y_box_offset,
310- # )
311- # self[0] = tile_grid # update the background bitmap in first item of the group
312-
313264 self [0 ] = self ._create_background_box (lines , y_offset )
314265
315266 @property
0 commit comments