Skip to content

Commit 38af9c0

Browse files
committed
Introduce a _create_label_group method to reduce code duplication.
This method can be used to reduce code duplication in several areas of the library, and introduces common shared defaults such as black for the font color.
1 parent 445a0e4 commit 38af9c0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

adafruit_pybadger.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,21 @@ def __init__(self, i2c=None, *, pixels_brightness=1.0):
141141
self._sine_wave = None
142142
self._sine_wave_sample = None
143143

144+
def _create_label_group(self, text, font, scale, height_adjustment, color=0xFFFFFF, width_adjustment=2, line_spacing=0.75):
145+
"""Create a label group with the given text, font, scale, and spacing."""
146+
# If the given font is a string, treat it as a file path and try to load it
147+
if isinstance(font, str):
148+
font = load_font(font)
149+
150+
group = displayio.Group(scale=scale)
151+
label = Label(font, text=text, line_spacing=line_spacing)
152+
_, _, width, _ = label.bounding_box
153+
label.x = ((self.display.width // (width_adjustment * scale)) - width // 2)
154+
label.y = int(self.display.height * (height_adjustment / scale))
155+
label.color = color
156+
group.append(label)
157+
return group
158+
144159
def _check_for_movement(self, movement_threshold=10):
145160
"""Checks to see if board is moving. Used to auto-dim display when not moving."""
146161
current_accelerometer = self.acceleration

0 commit comments

Comments
 (0)