@@ -59,7 +59,9 @@ class Label(displayio.Group):
5959 (E.g. (0,0) is top left, (1.0, 0.5): is middle right.)
6060 :param (int,int) anchored_position: Position relative to the anchor_point. Tuple
6161 containing x,y pixel coordinates.
62- :param int scale: Integer value of the pixel scaling"""
62+ :param int scale: Integer value of the pixel scaling
63+ :param bool base_alignment: when True allows to align text label to the baseline.
64+ This is helpful when two or more labels need to be aligned to the same baseline"""
6365
6466 # pylint: disable=too-many-instance-attributes, too-many-locals
6567 # This has a lot of getters/setters, maybe it needs cleanup.
@@ -83,6 +85,7 @@ def __init__(
8385 anchor_point = None ,
8486 anchored_position = None ,
8587 scale = 1 ,
88+ base_alignment = False ,
8689 ** kwargs
8790 ):
8891 if not max_glyphs and not text :
@@ -129,6 +132,7 @@ def __init__(
129132 self ._padding_bottom = padding_bottom
130133 self ._padding_left = padding_left
131134 self ._padding_right = padding_right
135+ self .base_alignment = base_alignment
132136
133137 if text is not None :
134138 self ._update_text (str (text ))
@@ -159,7 +163,10 @@ def _create_background_box(self, lines, y_offset):
159163 + self ._padding_top
160164 + self ._padding_bottom
161165 )
162- y_box_offset = - ascent + y_offset - self ._padding_top
166+ if self .base_alignment :
167+ y_box_offset = - ascent - self ._padding_top
168+ else :
169+ y_box_offset = - ascent + y_offset - self ._padding_top
163170
164171 box_width = max (0 , box_width ) # remove any negative values
165172 box_height = max (0 , box_height ) # remove any negative values
@@ -263,8 +270,10 @@ def _update_text(
263270 else :
264271 i = 0
265272 tilegrid_count = i
266-
267- y_offset = self ._get_ascent () // 2
273+ if self .base_alignment :
274+ y_offset = 0
275+ else :
276+ y_offset = self ._get_ascent () // 2
268277
269278 right = top = bottom = 0
270279 left = None
0 commit comments