@@ -39,7 +39,27 @@ class Label(displayio.Group):
39
39
:param str text: Text to display
40
40
:param int max_glyphs: The largest quantity of glyphs we will display
41
41
:param int color: Color of all text in RGB hex
42
- :param double line_spacing: Line spacing of text to display"""
42
+ :param float line_spacing: Line spacing of text to display
43
+ :param bool background_tight: Set `True` only if you want background box to tightly
44
+ surround text. When set to 'True' Padding parameters will be ignored.
45
+ :param int padding_top: Additional pixels added to background bounding box at top.
46
+ This parameter could be negative indicating additional pixels subtracted to background
47
+ bounding box.
48
+ :param int padding_bottom: Additional pixels added to background bounding box at bottom.
49
+ This parameter could be negative indicating additional pixels subtracted to background
50
+ bounding box.
51
+ :param int padding_left: Additional pixels added to background bounding box at left.
52
+ This parameter could be negative indicating additional pixels subtracted to background
53
+ bounding box.
54
+ :param int padding_right: Additional pixels added to background bounding box at right.
55
+ This parameter could be negative indicating additional pixels subtracted to background
56
+ bounding box.
57
+ :param (float,float) anchor_point: Point that anchored_position moves relative to.
58
+ Tuple with decimal percentage of width and height.
59
+ (E.g. (0,0) is top left, (1.0, 0.5): is middle right.)
60
+ :param (int,int) anchored_position: Position relative to the anchor_point. Tuple
61
+ containing x,y pixel coordinates.
62
+ :param int scale: Integer value of the pixel scaling"""
43
63
44
64
# pylint: disable=too-many-instance-attributes, too-many-locals
45
65
# This has a lot of getters/setters, maybe it needs cleanup.
@@ -74,12 +94,10 @@ def __init__(
74
94
# instance the Group
75
95
# self Group will contain a single local_group which contains a Group (self.local_group)
76
96
# which contains a TileGrid
77
- super ().__init__ (
78
- max_size = 1 , scale = 1 , ** kwargs
79
- ) # The self scale should always be 1
80
- self .local_group = displayio .Group (
81
- max_size = max_glyphs + 1 , scale = scale
82
- ) # local_group will set the scale
97
+ # The self scale should always be 1
98
+ super ().__init__ (max_size = 1 , scale = 1 , ** kwargs )
99
+ # local_group will set the scale
100
+ self .local_group = displayio .Group (max_size = max_glyphs + 1 , scale = scale )
83
101
self .append (self .local_group )
84
102
85
103
self .width = max_glyphs
@@ -120,6 +138,9 @@ def __init__(
120
138
self .anchored_position = anchored_position
121
139
122
140
def _create_background_box (self , lines , y_offset ):
141
+ """Private Class function to create a background_box
142
+ :param lines: int number of lines
143
+ :param y_offset: int y pixel bottom coordinate for the background_box"""
123
144
124
145
left = self ._boundingbox [0 ]
125
146
@@ -156,6 +177,7 @@ def _create_background_box(self, lines, y_offset):
156
177
return tile_grid
157
178
158
179
def _get_ascent_descent (self ):
180
+ """ Private function to calculate ascent and descent font values """
159
181
if hasattr (self .font , "ascent" ):
160
182
return self .font .ascent , self .font .descent
161
183
@@ -179,6 +201,8 @@ def _get_ascent(self):
179
201
return self ._get_ascent_descent ()[0 ]
180
202
181
203
def _update_background_color (self , new_color ):
204
+ """Private class function that allows updating the font box background color
205
+ :param new_color: int color as an RGB hex number."""
182
206
183
207
if new_color is None :
184
208
self ._background_palette .make_transparent (0 )
@@ -204,9 +228,8 @@ def _update_background_color(self, new_color):
204
228
self ._boundingbox [3 ] + self ._padding_top + self ._padding_bottom > 0
205
229
)
206
230
):
207
- if (
208
- len (self .local_group ) > 0
209
- ): # This can be simplified in CP v6.0, when group.append(0) bug is corrected
231
+ # This can be simplified in CP v6.0, when group.append(0) bug is corrected
232
+ if len (self .local_group ) > 0 :
210
233
self .local_group .insert (
211
234
0 , self ._create_background_box (lines , y_offset )
212
235
)
0 commit comments