48
48
49
49
class Label (displayio .Group ):
50
50
"""A label displaying a string of text that is stored in a bitmap.
51
- Note: This ``bitmap_label.py`` library utilizes a bitmap to display the text.
52
- This method is memory-conserving relative to ``label.py``.
53
- The ``max_glyphs`` parameter is ignored and is present
54
- only for direct compatability with label.py.
55
-
56
- For further reduction in memory usage, set ``save_text=False`` (text string will not
57
- be stored and ``line_spacing`` and ``font`` are immutable with ``save_text``
58
- set to ``False``).
59
-
60
- The origin point set by ``x`` and ``y``
61
- properties will be the left edge of the bounding box, and in the center of a M
62
- glyph (if its one line), or the (number of lines * linespacing + M)/2. That is,
63
- it will try to have it be center-left as close as possible.
64
-
65
- :param Font font: A font class that has ``get_bounding_box`` and ``get_glyph``.
66
- Must include a capital M for measuring character size.
67
- :param str text: Text to display
68
- :param int max_glyphs: Unnecessary parameter (provided only for direct compability
69
- with label.py)
70
- :param int color: Color of all text in RGB hex
71
- :param int background_color: Color of the background, use `None` for transparent
72
- :param double line_spacing: Line spacing of text to display
73
- :param boolean background_tight: Set `True` only if you want background box to tightly
74
- surround text
75
- :param int padding_top: Additional pixels added to background bounding box at top
76
- :param int padding_bottom: Additional pixels added to background bounding box at bottom
77
- :param int padding_left: Additional pixels added to background bounding box at left
78
- :param int padding_right: Additional pixels added to background bounding box at right
79
- :param (double,double) anchor_point: Point that anchored_position moves relative to.
80
- Tuple with decimal percentage of width and height.
81
- (E.g. (0,0) is top left, (1.0, 0.5): is middle right.)
82
- :param (int,int) anchored_position: Position relative to the anchor_point. Tuple
83
- containing x,y pixel coordinates.
84
- :param int scale: Integer value of the pixel scaling
85
- :param bool save_text: Set True to save the text string as a constant in the
86
- label structure. Set False to reduce memory use.
87
- """
51
+ Note: This ``bitmap_label.py`` library utilizes a bitmap to display the text.
52
+ This method is memory-conserving relative to ``label.py``.
53
+ The ``max_glyphs`` parameter is ignored and is present
54
+ only for direct compatability with label.py.
55
+
56
+ For further reduction in memory usage, set ``save_text=False`` (text string will not
57
+ be stored and ``line_spacing`` and ``font`` are immutable with ``save_text``
58
+ set to ``False``).
59
+
60
+ The origin point set by ``x`` and ``y``
61
+ properties will be the left edge of the bounding box, and in the center of a M
62
+ glyph (if its one line), or the (number of lines * linespacing + M)/2. That is,
63
+ it will try to have it be center-left as close as possible.
64
+
65
+ :param Font font: A font class that has ``get_bounding_box`` and ``get_glyph``.
66
+ Must include a capital M for measuring character size.
67
+ :param str text: Text to display
68
+ :param int max_glyphs: Unnecessary parameter (provided only for direct compability
69
+ with label.py)
70
+ :param int color: Color of all text in RGB hex
71
+ :param int background_color: Color of the background, use `None` for transparent
72
+ :param double line_spacing: Line spacing of text to display
73
+ :param boolean background_tight: Set `True` only if you want background box to tightly
74
+ surround text
75
+ :param int padding_top: Additional pixels added to background bounding box at top
76
+ :param int padding_bottom: Additional pixels added to background bounding box at bottom
77
+ :param int padding_left: Additional pixels added to background bounding box at left
78
+ :param int padding_right: Additional pixels added to background bounding box at right
79
+ :param (double,double) anchor_point: Point that anchored_position moves relative to.
80
+ Tuple with decimal percentage of width and height.
81
+ (E.g. (0,0) is top left, (1.0, 0.5): is middle right.)
82
+ :param (int,int) anchored_position: Position relative to the anchor_point. Tuple
83
+ containing x,y pixel coordinates.
84
+ :param int scale: Integer value of the pixel scaling
85
+ :param bool save_text: Set True to save the text string as a constant in the
86
+ label structure. Set False to reduce memory use.
87
+ """
88
88
89
89
# pylint: disable=unused-argument, too-many-instance-attributes, too-many-locals, too-many-arguments
90
90
# pylint: disable=too-many-branches, no-self-use, too-many-statements
@@ -118,7 +118,11 @@ def __init__(
118
118
# self Group will contain a single local_group which contains a Group (self.local_group)
119
119
# which contains a TileGrid (self.tilegrid) which contains the text bitmap (self.bitmap)
120
120
super ().__init__ (
121
- max_size = 1 , x = x , y = y , scale = 1 , ** kwargs ,
121
+ max_size = 1 ,
122
+ x = x ,
123
+ y = y ,
124
+ scale = 1 ,
125
+ ** kwargs ,
122
126
)
123
127
# the self group scale should always remain at 1, the self.local_group will
124
128
# be used to set the scale
@@ -204,7 +208,6 @@ def _reset_text(
204
208
if save_text is not None :
205
209
self ._save_text = save_text
206
210
207
-
208
211
# if text is not provided as a parameter (text is None), use the previous value.
209
212
if (text is None ) and self ._save_text :
210
213
text = self ._text
@@ -244,7 +247,9 @@ def _reset_text(
244
247
loose_box_y ,
245
248
loose_y_offset ,
246
249
) = self ._text_bounding_box (
247
- text , self ._font , self ._line_spacing ,
250
+ text ,
251
+ self ._font ,
252
+ self ._line_spacing ,
248
253
) # calculate the box size for a tight and loose backgrounds
249
254
250
255
if self ._background_tight :
@@ -305,7 +310,6 @@ def _reset_text(
305
310
tight_box_y ,
306
311
)
307
312
308
-
309
313
if (
310
314
scale is not None
311
315
): # Scale will be defined in local_group (Note: self should have scale=1)
@@ -316,8 +320,6 @@ def _reset_text(
316
320
) # set the anchored_position with setter after bitmap is created, sets the
317
321
# x,y positions of the label
318
322
319
-
320
-
321
323
@staticmethod
322
324
def _line_spacing_ypixels (font , line_spacing ):
323
325
# Note: Scaling is provided at the Group level
@@ -649,8 +651,8 @@ def font(self, new_font):
649
651
@property
650
652
def anchor_point (self ):
651
653
"""Point that anchored_position moves relative to.
652
- Tuple with decimal percentage of width and height.
653
- (E.g. (0,0) is top left, (1.0, 0.5): is middle right.)"""
654
+ Tuple with decimal percentage of width and height.
655
+ (E.g. (0,0) is top left, (1.0, 0.5): is middle right.)"""
654
656
return self ._anchor_point
655
657
656
658
@anchor_point .setter
@@ -663,7 +665,7 @@ def anchor_point(self, new_anchor_point):
663
665
@property
664
666
def anchored_position (self ):
665
667
"""Position relative to the anchor_point. Tuple containing x,y
666
- pixel coordinates."""
668
+ pixel coordinates."""
667
669
return self ._anchored_position
668
670
669
671
@anchored_position .setter
0 commit comments