2828
2929
3030try :
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
3235except ImportError :
3336 pass
3437
@@ -51,8 +54,9 @@ class Label(LabelBase):
5154 glyph (if its one line), or the (number of lines * linespacing + M)/2. That is,
5255 it will try to have it be center-left as close as possible.
5356
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``.
5558 Must include a capital M for measuring character size.
59+ :type font: ~BuiltinFont, ~BDF, or ~PCF
5660 :param str text: Text to display
5761 :param int color: Color of all text in RGB hex
5862 :param int background_color: Color of the background, use `None` for transparent
@@ -80,7 +84,9 @@ class Label(LabelBase):
8084 configurations possibles ``LTR``-Left-To-Right ``RTL``-Right-To-Left
8185 ``UPD``-Upside Down ``UPR``-Upwards ``DWR``-Downwards. It defaults to ``LTR``"""
8286
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 :
8490
8591 self ._bitmap = None
8692
@@ -102,10 +108,10 @@ def __init__(self, font, save_text=True, **kwargs) -> None:
102108
103109 def _reset_text (
104110 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 ,
109115 ) -> None :
110116 # pylint: disable=too-many-branches, too-many-statements
111117
@@ -247,13 +253,15 @@ def _reset_text(
247253 self .anchored_position = self ._anchored_position
248254
249255 @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 :
251259 # Note: Scaling is provided at the Group level
252260 return_value = int (line_spacing * font .get_bounding_box ()[1 ])
253261 return return_value
254262
255263 def _text_bounding_box (
256- self , text : str , font
264+ self , text : str , font : Union [ BuiltinFont , BDF , PCF ]
257265 ) -> Tuple [int , int , int , int , int , int ]:
258266 # pylint: disable=too-many-locals
259267
@@ -333,9 +341,9 @@ def _text_bounding_box(
333341
334342 def _place_text (
335343 self ,
336- bitmap ,
344+ bitmap : displayio . Bitmap ,
337345 text : str ,
338- font ,
346+ font : Union [ BuiltinFont , BDF , PCF ] ,
339347 xposition : int ,
340348 yposition : int ,
341349 skip_index : int = 0 , # set to None to write all pixels, other wise skip this palette index
@@ -432,10 +440,10 @@ def _place_text(
432440
433441 def _blit (
434442 self ,
435- bitmap , # target bitmap
443+ bitmap : displayio . Bitmap , # target bitmap
436444 x : int , # target x upper left corner
437445 y : int , # target y upper left corner
438- source_bitmap , # source bitmap
446+ source_bitmap : displayio . Bitmap , # source bitmap
439447 x_1 : int = 0 , # source x start
440448 y_1 : int = 0 , # source y start
441449 x_2 : int = None , # source x end
@@ -509,7 +517,7 @@ def _set_line_spacing(self, new_line_spacing: float) -> None:
509517 else :
510518 raise RuntimeError ("line_spacing is immutable when save_text is False" )
511519
512- def _set_font (self , new_font ) -> None :
520+ def _set_font (self , new_font : Union [ BuiltinFont , BDF , PCF ] ) -> None :
513521 self ._font = new_font
514522 if self ._save_text :
515523 self ._reset_text (font = new_font , scale = self .scale )
@@ -519,7 +527,7 @@ def _set_font(self, new_font) -> None:
519527 def _set_text (self , new_text : str , scale : int ) -> None :
520528 self ._reset_text (text = self ._replace_tabs (new_text ), scale = self .scale )
521529
522- def _set_background_color (self , new_color ):
530+ def _set_background_color (self , new_color : Optional [ int ] ):
523531 self ._background_color = new_color
524532 if new_color is not None :
525533 self ._palette [0 ] = new_color
@@ -536,7 +544,7 @@ def _get_valid_label_directions(self) -> Tuple[str, ...]:
536544 return "LTR" , "RTL" , "UPD" , "UPR" , "DWR"
537545
538546 @property
539- def bitmap (self ):
547+ def bitmap (self ) -> displayio . Bitmap :
540548 """
541549 The Bitmap object that the text and background are drawn into.
542550
0 commit comments