@@ -56,17 +56,18 @@ class SimpleTextDisplay:
56
56
VIOLET = (255 , 0 , 255 )
57
57
SKY = (0 , 180 , 255 )
58
58
59
- def __init__ ( # pylint: disable=too-many-arguments
59
+ def __init__ (
60
60
self ,
61
61
title = None ,
62
62
title_color = (255 , 255 , 255 ),
63
63
title_scale : int = 1 ,
64
- title_length : int = 80 ,
64
+ title_length : int = 0 , # Ignored - will be removed in a future version
65
65
text_scale : int = 1 ,
66
66
font = None ,
67
67
colors = None ,
68
68
display = None ,
69
69
):
70
+ # pylint: disable=too-many-arguments, unused-argument
70
71
"""Display lines of text on a display using displayio. Lines of text are created in order as
71
72
shown in the example below. If you skip a number, the line will be shown blank on the
72
73
display, e.g. if you include ``[0]`` and ``[2]``, the second line on the display will be
@@ -85,8 +86,7 @@ def __init__( # pylint: disable=too-many-arguments
85
86
title is provided. Defaults to white (255, 255, 255).
86
87
:param int title_scale: Scale the size of the title. Not necessary if no title is provided.
87
88
Defaults to 1.
88
- :param int title_length: The maximum number of characters allowed in the title. Only
89
- necessary if the title is longer than the default 80 characters. Defaults to 80.
89
+ :param int title_length: DEPRECATED/IGNORED - This will be removed in a future version.
90
90
:param int text_scale: Scale the size of the data lines. Scales the title as well.
91
91
Defaults to 1.
92
92
:param ~fontio.BuiltinFont,~adafruit_bitmap_font.bdf.BDF,~adafruit_bitmap_font.pcf.PCF font:
@@ -141,56 +141,55 @@ def __init__( # pylint: disable=too-many-arguments
141
141
)
142
142
143
143
self ._colors = colors
144
- self ._label = label
145
144
if display is None :
146
145
display = board .DISPLAY
147
146
self ._display = display
148
147
self ._font = font if font else terminalio .FONT
148
+ self ._text_scale = text_scale
149
149
150
- self .text_group = displayio .Group (scale = text_scale )
150
+ self .text_group = displayio .Group ()
151
151
152
152
if title :
153
- # Fail gracefully if title is longer than title_length characters. Defaults to 80.
154
- if len (title ) > title_length :
155
- raise ValueError (
156
- "Title character count must be less than or equal to title_length."
157
- " Default is 80."
158
- )
159
-
160
- title = label .Label (
153
+ title_label = label .Label (
161
154
self ._font ,
162
155
text = title ,
163
- max_glyphs = title_length ,
164
156
color = title_color ,
165
157
scale = title_scale ,
158
+ anchor_point = (0 , 0 ),
159
+ anchored_position = (0 , 0 ),
166
160
)
167
- title .x = 0
168
- title .y = 8
169
- self ._y = title .y + 18
161
+ self ._next_y = title_label .bounding_box [3 ] * title_scale
170
162
171
- self .text_group .append (title )
163
+ self .text_group .append (title_label )
172
164
else :
173
- self ._y = 3
165
+ self ._next_y = 0
174
166
175
167
self ._lines = []
176
- for num in range ( 1 ):
177
- self ._lines .append (self .add_text_line (color = colors [num % len ( colors ) ]))
168
+ # Add first line
169
+ self ._lines .append (self .add_text_line (color = colors [0 ]))
178
170
179
171
def __getitem__ (self , item ):
180
172
"""Fetch the Nth text line Group"""
181
173
if len (self ._lines ) - 1 < item :
182
- for _ in range (item - ( len (self ._lines ) - 1 ) ):
174
+ for i in range (len (self ._lines ), item + 1 ):
183
175
self ._lines .append (
184
- self .add_text_line (color = self ._colors [item % len (self ._colors )])
176
+ self .add_text_line (color = self ._colors [i % len (self ._colors )])
185
177
)
186
178
return self ._lines [item ]
187
179
188
180
def add_text_line (self , color = (255 , 255 , 255 )):
189
181
"""Adds a line on the display of the specified color and returns the label object."""
190
- text_label = self ._label .Label (self ._font , text = "" , color = color )
191
- text_label .x = 0
192
- text_label .y = self ._y
193
- self ._y = text_label .y + 13
182
+
183
+ text_label = label .Label (
184
+ self ._font ,
185
+ text = "Myj" , # Dummy value to allow bounding_box to calculate
186
+ color = color ,
187
+ scale = self ._text_scale ,
188
+ anchor_point = (0 , 0 ),
189
+ anchored_position = (0 , self ._next_y ),
190
+ )
191
+ self ._next_y += text_label .bounding_box [3 ] * text_label .scale
192
+ text_label .text = "" # Erase the dummy value after using bounding_box
194
193
self .text_group .append (text_label )
195
194
196
195
return text_label
0 commit comments