1
- # The MIT License (MIT)
1
+ # SPDX-FileCopyrightText: 2020 Kevin Matocha
2
2
#
3
- # Copyright (c) 2020 Kevin Matocha
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # SPDX-License-Identifier: MIT
4
+
22
5
"""
23
6
`bitmap_label`
24
7
================================================================================
48
31
49
32
class Label (displayio .Group ):
50
33
"""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
- """
34
+ Note: This ``bitmap_label.py`` library utilizes a bitmap to display the text.
35
+ This method is memory-conserving relative to ``label.py``.
36
+ The ``max_glyphs`` parameter is ignored and is present
37
+ only for direct compatability with label.py.
38
+
39
+ For further reduction in memory usage, set ``save_text=False`` (text string will not
40
+ be stored and ``line_spacing`` and ``font`` are immutable with ``save_text``
41
+ set to ``False``).
42
+
43
+ The origin point set by ``x`` and ``y``
44
+ properties will be the left edge of the bounding box, and in the center of a M
45
+ glyph (if its one line), or the (number of lines * linespacing + M)/2. That is,
46
+ it will try to have it be center-left as close as possible.
47
+
48
+ :param Font font: A font class that has ``get_bounding_box`` and ``get_glyph``.
49
+ Must include a capital M for measuring character size.
50
+ :param str text: Text to display
51
+ :param int max_glyphs: Unnecessary parameter (provided only for direct compability
52
+ with label.py)
53
+ :param int color: Color of all text in RGB hex
54
+ :param int background_color: Color of the background, use `None` for transparent
55
+ :param double line_spacing: Line spacing of text to display
56
+ :param boolean background_tight: Set `True` only if you want background box to tightly
57
+ surround text
58
+ :param int padding_top: Additional pixels added to background bounding box at top
59
+ :param int padding_bottom: Additional pixels added to background bounding box at bottom
60
+ :param int padding_left: Additional pixels added to background bounding box at left
61
+ :param int padding_right: Additional pixels added to background bounding box at right
62
+ :param (double,double) anchor_point: Point that anchored_position moves relative to.
63
+ Tuple with decimal percentage of width and height.
64
+ (E.g. (0,0) is top left, (1.0, 0.5): is middle right.)
65
+ :param (int,int) anchored_position: Position relative to the anchor_point. Tuple
66
+ containing x,y pixel coordinates.
67
+ :param int scale: Integer value of the pixel scaling
68
+ :param bool save_text: Set True to save the text string as a constant in the
69
+ label structure. Set False to reduce memory use.
70
+ """
88
71
89
72
# pylint: disable=unused-argument, too-many-instance-attributes, too-many-locals, too-many-arguments
90
73
# pylint: disable=too-many-branches, no-self-use, too-many-statements
@@ -118,7 +101,11 @@ def __init__(
118
101
# self Group will contain a single local_group which contains a Group (self.local_group)
119
102
# which contains a TileGrid (self.tilegrid) which contains the text bitmap (self.bitmap)
120
103
super ().__init__ (
121
- max_size = 1 , x = x , y = y , scale = 1 , ** kwargs ,
104
+ max_size = 1 ,
105
+ x = x ,
106
+ y = y ,
107
+ scale = 1 ,
108
+ ** kwargs ,
122
109
)
123
110
# the self group scale should always remain at 1, the self.local_group will
124
111
# be used to set the scale
@@ -248,7 +235,9 @@ def _reset_text(
248
235
loose_box_y ,
249
236
loose_y_offset ,
250
237
) = self ._text_bounding_box (
251
- text , self ._font , self ._line_spacing ,
238
+ text ,
239
+ self ._font ,
240
+ self ._line_spacing ,
252
241
) # calculate the box size for a tight and loose backgrounds
253
242
254
243
if self ._background_tight :
@@ -645,8 +634,8 @@ def font(self, new_font):
645
634
@property
646
635
def anchor_point (self ):
647
636
"""Point that anchored_position moves relative to.
648
- Tuple with decimal percentage of width and height.
649
- (E.g. (0,0) is top left, (1.0, 0.5): is middle right.)"""
637
+ Tuple with decimal percentage of width and height.
638
+ (E.g. (0,0) is top left, (1.0, 0.5): is middle right.)"""
650
639
return self ._anchor_point
651
640
652
641
@anchor_point .setter
@@ -659,7 +648,7 @@ def anchor_point(self, new_anchor_point):
659
648
@property
660
649
def anchored_position (self ):
661
650
"""Position relative to the anchor_point. Tuple containing x,y
662
- pixel coordinates."""
651
+ pixel coordinates."""
663
652
return self ._anchored_position
664
653
665
654
@anchored_position .setter
0 commit comments