44
44
__version__ = "0.0.0-auto.0"
45
45
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Text.git"
46
46
47
-
48
47
class Label (displayio .Group ):
49
48
"""A label displaying a string of text. The origin point set by ``x`` and ``y``
50
49
properties will be the left edge of the bounding box, and in the center of a M
@@ -57,7 +56,6 @@ class Label(displayio.Group):
57
56
:param int max_glyphs: The largest quantity of glyphs we will display
58
57
:param int color: Color of all text in RGB hex
59
58
:param double line_spacing: Line spacing of text to display"""
60
-
61
59
def __init__ (self , font , * , x = 0 , y = 0 , text = None , max_glyphs = None , color = 0xffffff ,
62
60
backgroud_color = False , line_spacing = 1.25 , ** kwargs ):
63
61
if not max_glyphs and not text :
@@ -87,14 +85,15 @@ def __init__(self, font, *, x=0, y=0, text=None, max_glyphs=None, color=0xffffff
87
85
if text is not None :
88
86
self ._update_text (str (text ))
89
87
90
- def _update_text (self , new_text ): # pylint: disable=too-many-locals
88
+
89
+ def _update_text (self , new_text ): # pylint: disable=too-many-locals
91
90
x = 0
92
91
y = 0
93
92
i = 0
94
93
old_c = 0
95
94
y_offset = int ((self .font .get_glyph (ord ('M' )).height -
96
95
new_text .count ('\n ' ) * self .height * self .line_spacing ) / 2 )
97
- # print("y offset from baseline", y_offset)
96
+ #print("y offset from baseline", y_offset)
98
97
left = right = top = bottom = 0
99
98
for character in new_text :
100
99
if character == '\n ' :
@@ -104,10 +103,10 @@ def _update_text(self, new_text): # pylint: disable=too-many-locals
104
103
glyph = self .font .get_glyph (ord (character ))
105
104
if not glyph :
106
105
continue
107
- right = max (right , x + glyph .width )
108
- if y == 0 : # first line, find the Ascender height
109
- top = min (top , - glyph .height + y_offset )
110
- bottom = max (bottom , y - glyph .dy + y_offset )
106
+ right = max (right , x + glyph .width )
107
+ if y == 0 : # first line, find the Ascender height
108
+ top = min (top , - glyph .height + y_offset )
109
+ bottom = max (bottom , y - glyph .dy + y_offset )
111
110
position_y = y - glyph .height - glyph .dy + y_offset
112
111
position_x = x + glyph .dx
113
112
if not self ._text or old_c >= len (self ._text ) or character != self ._text [old_c ]:
@@ -145,7 +144,7 @@ def _update_text(self, new_text): # pylint: disable=too-many-locals
145
144
while len (self ) > i :
146
145
self .pop ()
147
146
self ._text = new_text
148
- self ._boundingbox = (left , top , left + right , bottom - top )
147
+ self ._boundingbox = (left , top , left + right , bottom - top )
149
148
150
149
@property
151
150
def bounding_box (self ):
@@ -196,10 +195,10 @@ def anchor_point(self, new_anchor_point):
196
195
def anchored_position (self ):
197
196
"""Position relative to the anchor_point. Tuple containing x,y
198
197
pixel coordinates."""
199
- return (self .x - self ._boundingbox [2 ] * self ._anchor_point [0 ],
200
- self .y - self ._boundingbox [3 ] * self ._anchor_point [1 ])
198
+ return (self .x - self ._boundingbox [2 ]* self ._anchor_point [0 ],
199
+ self .y - self ._boundingbox [3 ]* self ._anchor_point [1 ])
201
200
202
201
@anchored_position .setter
203
202
def anchored_position (self , new_position ):
204
- self .x = int (new_position [0 ] - (self ._boundingbox [2 ] * self ._anchor_point [0 ]))
205
- self .y = int (new_position [1 ] - (self ._boundingbox [3 ] * self ._anchor_point [1 ]))
203
+ self .x = int (new_position [0 ]- (self ._boundingbox [2 ]* self ._anchor_point [0 ]))
204
+ self .y = int (new_position [1 ]- (self ._boundingbox [3 ]* self ._anchor_point [1 ]))
0 commit comments