@@ -34,7 +34,7 @@ class Label(displayio.Group):
34
34
Note: This ``bitmap_label.py`` library utilizes a bitmap to display the text.
35
35
This method is memory-conserving relative to ``label.py``.
36
36
The ``max_glyphs`` parameter is ignored and is present
37
- only for direct compatability with label.py.
37
+ only for direct compatibility with label.py.
38
38
39
39
For further reduction in memory usage, set ``save_text=False`` (text string will not
40
40
be stored and ``line_spacing`` and ``font`` are immutable with ``save_text``
@@ -54,19 +54,21 @@ class Label(displayio.Group):
54
54
:param int background_color: Color of the background, use `None` for transparent
55
55
:param double line_spacing: Line spacing of text to display
56
56
:param boolean background_tight: Set `True` only if you want background box to tightly
57
- surround text
57
+ surround text. When set to 'True' Padding parameters will be ignored.
58
58
:param int padding_top: Additional pixels added to background bounding box at top
59
59
:param int padding_bottom: Additional pixels added to background bounding box at bottom
60
60
:param int padding_left: Additional pixels added to background bounding box at left
61
61
:param int padding_right: Additional pixels added to background bounding box at right
62
- :param (double,double ) anchor_point: Point that anchored_position moves relative to.
62
+ :param (float,float ) anchor_point: Point that anchored_position moves relative to.
63
63
Tuple with decimal percentage of width and height.
64
64
(E.g. (0,0) is top left, (1.0, 0.5): is middle right.)
65
65
:param (int,int) anchored_position: Position relative to the anchor_point. Tuple
66
66
containing x,y pixel coordinates.
67
67
:param int scale: Integer value of the pixel scaling
68
68
:param bool save_text: Set True to save the text string as a constant in the
69
- label structure. Set False to reduce memory use."""
69
+ label structure. Set False to reduce memory use.
70
+ :param: bool base_alignment: when True allows to align text label to the baseline.
71
+ This is helpful when two or more labels need to be aligned to the same baseline"""
70
72
71
73
# pylint: disable=unused-argument, too-many-instance-attributes, too-many-locals, too-many-arguments
72
74
# pylint: disable=too-many-branches, no-self-use, too-many-statements
@@ -93,6 +95,7 @@ def __init__(
93
95
anchored_position = None ,
94
96
save_text = True , # can reduce memory use if save_text = False
95
97
scale = 1 ,
98
+ base_alignment = False ,
96
99
** kwargs ,
97
100
):
98
101
@@ -128,6 +131,8 @@ def __init__(
128
131
self ._anchor_point = anchor_point
129
132
self ._anchored_position = anchored_position
130
133
134
+ self ._base_alignment = base_alignment
135
+
131
136
# call the text updater with all the arguments.
132
137
self ._reset_text (
133
138
font = font ,
@@ -144,6 +149,7 @@ def __init__(
144
149
anchored_position = anchored_position ,
145
150
save_text = save_text ,
146
151
scale = scale ,
152
+ base_alignment = base_alignment ,
147
153
)
148
154
149
155
def _reset_text (
@@ -162,6 +168,7 @@ def _reset_text(
162
168
anchored_position = None ,
163
169
save_text = None ,
164
170
scale = None ,
171
+ base_alignment = None ,
165
172
):
166
173
167
174
# Store all the instance variables
@@ -189,6 +196,8 @@ def _reset_text(
189
196
self ._anchored_position = anchored_position
190
197
if save_text is not None :
191
198
self ._save_text = save_text
199
+ if base_alignment is not None :
200
+ self ._base_alignment = base_alignment
192
201
193
202
# if text is not provided as a parameter (text is None), use the previous value.
194
203
if (text is None ) and self ._save_text :
@@ -260,8 +269,10 @@ def _reset_text(
260
269
self ._padding_top + y_offset ,
261
270
)
262
271
263
- # To calibrate with label.py positioning
264
- label_position_yoffset = self ._get_ascent () // 2
272
+ if self ._base_alignment :
273
+ label_position_yoffset = 0
274
+ else :
275
+ label_position_yoffset = self ._get_ascent () // 2
265
276
266
277
self .tilegrid = displayio .TileGrid (
267
278
self .bitmap ,
@@ -303,6 +314,7 @@ def _reset_text(
303
314
# x,y positions of the label
304
315
305
316
def _get_ascent_descent (self ):
317
+ """ Private function to calculate ascent and descent font values """
306
318
if hasattr (self .font , "ascent" ):
307
319
return self .font .ascent , self .font .descent
308
320
@@ -615,7 +627,7 @@ def background_color(self, new_color):
615
627
616
628
@property
617
629
def text (self ):
618
- """Text to displayed."""
630
+ """Text to be displayed."""
619
631
return self ._text
620
632
621
633
@text .setter # Cannot set color or background color with text setter, use separate setter
0 commit comments