28
28
29
29
30
30
try :
31
- from typing import Tuple
31
+ from typing import Union , Optional , Tuple
32
+ from fontio import BuiltinFont
33
+ from adafruit_bitmap_font .bdf import BDF
34
+ from adafruit_bitmap_font .pcf import PCF
32
35
except ImportError :
33
36
pass
34
37
@@ -51,8 +54,9 @@ class Label(LabelBase):
51
54
glyph (if its one line), or the (number of lines * linespacing + M)/2. That is,
52
55
it will try to have it be center-left as close as possible.
53
56
54
- :param Font font: A font class that has ``get_bounding_box`` and ``get_glyph``.
57
+ :param font: A font class that has ``get_bounding_box`` and ``get_glyph``.
55
58
Must include a capital M for measuring character size.
59
+ :type font: ~BuiltinFont, ~BDF, or ~PCF
56
60
:param str text: Text to display
57
61
:param int color: Color of all text in RGB hex
58
62
:param int background_color: Color of the background, use `None` for transparent
@@ -80,7 +84,9 @@ class Label(LabelBase):
80
84
configurations possibles ``LTR``-Left-To-Right ``RTL``-Right-To-Left
81
85
``UPD``-Upside Down ``UPR``-Upwards ``DWR``-Downwards. It defaults to ``LTR``"""
82
86
83
- def __init__ (self , font , save_text = True , ** kwargs ) -> None :
87
+ def __init__ (
88
+ self , font : Union [BuiltinFont , BDF , PCF ], save_text : bool = True , ** kwargs
89
+ ) -> None :
84
90
85
91
self ._bitmap = None
86
92
@@ -102,10 +108,10 @@ def __init__(self, font, save_text=True, **kwargs) -> None:
102
108
103
109
def _reset_text (
104
110
self ,
105
- font = None ,
106
- text : str = None ,
107
- line_spacing : float = None ,
108
- scale : int = None ,
111
+ font : Optional [ Union [ BuiltinFont , BDF , PCF ]] = None ,
112
+ text : Optional [ str ] = None ,
113
+ line_spacing : Optional [ float ] = None ,
114
+ scale : Optional [ int ] = None ,
109
115
) -> None :
110
116
# pylint: disable=too-many-branches, too-many-statements
111
117
@@ -247,13 +253,15 @@ def _reset_text(
247
253
self .anchored_position = self ._anchored_position
248
254
249
255
@staticmethod
250
- def _line_spacing_ypixels (font , line_spacing : float ) -> int :
256
+ def _line_spacing_ypixels (
257
+ font : Union [BuiltinFont , BDF , PCF ], line_spacing : float
258
+ ) -> int :
251
259
# Note: Scaling is provided at the Group level
252
260
return_value = int (line_spacing * font .get_bounding_box ()[1 ])
253
261
return return_value
254
262
255
263
def _text_bounding_box (
256
- self , text : str , font
264
+ self , text : str , font : Union [ BuiltinFont , BDF , PCF ]
257
265
) -> Tuple [int , int , int , int , int , int ]:
258
266
# pylint: disable=too-many-locals
259
267
@@ -333,9 +341,9 @@ def _text_bounding_box(
333
341
334
342
def _place_text (
335
343
self ,
336
- bitmap ,
344
+ bitmap : displayio . Bitmap ,
337
345
text : str ,
338
- font ,
346
+ font : Union [ BuiltinFont , BDF , PCF ] ,
339
347
xposition : int ,
340
348
yposition : int ,
341
349
skip_index : int = 0 , # set to None to write all pixels, other wise skip this palette index
@@ -432,10 +440,10 @@ def _place_text(
432
440
433
441
def _blit (
434
442
self ,
435
- bitmap , # target bitmap
443
+ bitmap : displayio . Bitmap , # target bitmap
436
444
x : int , # target x upper left corner
437
445
y : int , # target y upper left corner
438
- source_bitmap , # source bitmap
446
+ source_bitmap : displayio . Bitmap , # source bitmap
439
447
x_1 : int = 0 , # source x start
440
448
y_1 : int = 0 , # source y start
441
449
x_2 : int = None , # source x end
@@ -509,7 +517,7 @@ def _set_line_spacing(self, new_line_spacing: float) -> None:
509
517
else :
510
518
raise RuntimeError ("line_spacing is immutable when save_text is False" )
511
519
512
- def _set_font (self , new_font ) -> None :
520
+ def _set_font (self , new_font : Union [ BuiltinFont , BDF , PCF ] ) -> None :
513
521
self ._font = new_font
514
522
if self ._save_text :
515
523
self ._reset_text (font = new_font , scale = self .scale )
@@ -519,7 +527,7 @@ def _set_font(self, new_font) -> None:
519
527
def _set_text (self , new_text : str , scale : int ) -> None :
520
528
self ._reset_text (text = self ._replace_tabs (new_text ), scale = self .scale )
521
529
522
- def _set_background_color (self , new_color ):
530
+ def _set_background_color (self , new_color : Optional [ int ] ):
523
531
self ._background_color = new_color
524
532
if new_color is not None :
525
533
self ._palette [0 ] = new_color
@@ -536,7 +544,7 @@ def _get_valid_label_directions(self) -> Tuple[str, ...]:
536
544
return "LTR" , "RTL" , "UPD" , "UPR" , "DWR"
537
545
538
546
@property
539
- def bitmap (self ):
547
+ def bitmap (self ) -> displayio . Bitmap :
540
548
"""
541
549
The Bitmap object that the text and background are drawn into.
542
550
0 commit comments