Skip to content

Commit 9934430

Browse files
committed
Bitmap_label Changes and doc corrections
1 parent 448ae32 commit 9934430

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

adafruit_display_text/bitmap_label.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Label(displayio.Group):
3434
Note: This ``bitmap_label.py`` library utilizes a bitmap to display the text.
3535
This method is memory-conserving relative to ``label.py``.
3636
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.
3838
3939
For further reduction in memory usage, set ``save_text=False`` (text string will not
4040
be stored and ``line_spacing`` and ``font`` are immutable with ``save_text``
@@ -54,19 +54,21 @@ class Label(displayio.Group):
5454
:param int background_color: Color of the background, use `None` for transparent
5555
:param double line_spacing: Line spacing of text to display
5656
: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.
5858
:param int padding_top: Additional pixels added to background bounding box at top
5959
:param int padding_bottom: Additional pixels added to background bounding box at bottom
6060
:param int padding_left: Additional pixels added to background bounding box at left
6161
: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.
6363
Tuple with decimal percentage of width and height.
6464
(E.g. (0,0) is top left, (1.0, 0.5): is middle right.)
6565
:param (int,int) anchored_position: Position relative to the anchor_point. Tuple
6666
containing x,y pixel coordinates.
6767
:param int scale: Integer value of the pixel scaling
6868
: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"""
7072

7173
# pylint: disable=unused-argument, too-many-instance-attributes, too-many-locals, too-many-arguments
7274
# pylint: disable=too-many-branches, no-self-use, too-many-statements
@@ -93,6 +95,7 @@ def __init__(
9395
anchored_position=None,
9496
save_text=True, # can reduce memory use if save_text = False
9597
scale=1,
98+
base_alignment=False,
9699
**kwargs,
97100
):
98101

@@ -128,6 +131,8 @@ def __init__(
128131
self._anchor_point = anchor_point
129132
self._anchored_position = anchored_position
130133

134+
self._base_alignment = base_alignment
135+
131136
# call the text updater with all the arguments.
132137
self._reset_text(
133138
font=font,
@@ -144,6 +149,7 @@ def __init__(
144149
anchored_position=anchored_position,
145150
save_text=save_text,
146151
scale=scale,
152+
base_alignment=base_alignment,
147153
)
148154

149155
def _reset_text(
@@ -162,6 +168,7 @@ def _reset_text(
162168
anchored_position=None,
163169
save_text=None,
164170
scale=None,
171+
base_alignment=None,
165172
):
166173

167174
# Store all the instance variables
@@ -189,6 +196,8 @@ def _reset_text(
189196
self._anchored_position = anchored_position
190197
if save_text is not None:
191198
self._save_text = save_text
199+
if base_alignment is not None:
200+
self._base_alignment = base_alignment
192201

193202
# if text is not provided as a parameter (text is None), use the previous value.
194203
if (text is None) and self._save_text:
@@ -260,8 +269,10 @@ def _reset_text(
260269
self._padding_top + y_offset,
261270
)
262271

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
265276

266277
self.tilegrid = displayio.TileGrid(
267278
self.bitmap,
@@ -303,6 +314,7 @@ def _reset_text(
303314
# x,y positions of the label
304315

305316
def _get_ascent_descent(self):
317+
""" Private function to calculate ascent and descent font values """
306318
if hasattr(self.font, "ascent"):
307319
return self.font.ascent, self.font.descent
308320

@@ -615,7 +627,7 @@ def background_color(self, new_color):
615627

616628
@property
617629
def text(self):
618-
"""Text to displayed."""
630+
"""Text to be displayed."""
619631
return self._text
620632

621633
@text.setter # Cannot set color or background color with text setter, use separate setter

0 commit comments

Comments
 (0)