@@ -114,12 +114,21 @@ def __init__(
114
114
** kwargs
115
115
):
116
116
117
+
118
+ # Scale will be passed to Group using kwargs.
119
+ if "scale" in kwargs .keys ():
120
+ scale = kwargs ["scale" ]
121
+ kwargs .pop ("scale" ) # Do not change scale of self Group, use this value to set scale of local_group
122
+
117
123
# instance the Group
118
- # this Group will contain just one TileGrid with one contained bitmap
124
+ # self Group will contain a single local_group which contains one TileGrid which contains the text bitmap
119
125
super ().__init__ (
120
126
max_size = 1 , x = x , y = y , ** kwargs
121
127
) # this will include any arguments, including scale
122
128
129
+ self .local_group = displayio .Group (max_size = 1 , ** kwargs ) # local_group holds the tileGrid and sets the scaling
130
+ self .append (self .local_group ) # the local_group will always stay in the self Group
131
+
123
132
self ._font = font
124
133
125
134
# Create the two-color palette
@@ -130,8 +139,6 @@ def __init__(
130
139
self ._anchor_point = anchor_point
131
140
self ._anchored_position = anchored_position
132
141
133
- self ._scale = 1 # initialize to the default scale of 1
134
-
135
142
# call the text updater with all the arguments.
136
143
self ._reset_text (font = font ,
137
144
x = x ,
@@ -146,6 +153,7 @@ def __init__(
146
153
anchor_point = anchor_point ,
147
154
anchored_position = anchored_position ,
148
155
save_text = save_text ,
156
+ scale = scale ,
149
157
** kwargs ,
150
158
)
151
159
@@ -164,7 +172,8 @@ def _reset_text(
164
172
padding_right = None ,
165
173
anchor_point = None ,
166
174
anchored_position = None ,
167
- save_text = None ,
175
+ save_text = None ,
176
+ scale = None ,
168
177
** kwargs
169
178
):
170
179
@@ -193,6 +202,8 @@ def _reset_text(
193
202
self ._anchored_position = anchored_position
194
203
if save_text is not None :
195
204
self ._save_text = save_text
205
+ if scale is not None : # Scale will be defined in local_group (Note: self should have scale=1)
206
+ self .scale = scale # call the setter
196
207
197
208
# if text is not provided as a parameter (text is None), use the previous value.
198
209
if (text is None ) and self ._save_text :
@@ -203,10 +214,6 @@ def _reset_text(
203
214
else :
204
215
self ._text = None # save a None value since text string is not saved
205
216
206
- # Scale will be passed to Group using kwargs.
207
- if "scale" in kwargs .keys ():
208
- self ._scale = kwargs ["scale" ]
209
-
210
217
211
218
# Check for empty string
212
219
if (text == "" ) or (text is None ): # If empty string, just create a zero-sized bounding box and that's it.
@@ -280,10 +287,10 @@ def _reset_text(
280
287
y = label_position_yoffset - y_offset - self ._padding_top ,
281
288
)
282
289
283
- # Clear out any items in the self Group, in case this is an update to the bitmap_label
284
- for item in self :
285
- self .pop (0 )
286
- self .append (self .tilegrid ) # add the bitmap's tilegrid to the group
290
+ # Clear out any items in the local_group Group, in case this is an update to the bitmap_label
291
+ for item in self . local_group :
292
+ self .local_group . pop (0 )
293
+ self .local_group . append (self .tilegrid ) # add the bitmap's tilegrid to the group
287
294
288
295
# Update bounding_box values. Note: To be consistent with label.py,
289
296
# this is the bounding box for the text only, not including the background.
@@ -461,8 +468,8 @@ def _place_text(
461
468
my_glyph .bitmap ,
462
469
x1 = glyph_offset_x ,
463
470
y1 = 0 ,
464
- x2 = glyph_offset_x + my_glyph .width - 1 ,
465
- y2 = 0 + my_glyph .height - 1 ,
471
+ x2 = glyph_offset_x + my_glyph .width ,
472
+ y2 = 0 + my_glyph .height ,
466
473
skip_index = 0 , # do not copy over any 0 background pixels
467
474
)
468
475
@@ -502,38 +509,22 @@ def _place_text(
502
509
503
510
return (left , top , right - left , bottom - top ) # bounding_box
504
511
505
-
506
-
507
-
508
-
509
-
510
512
@property
511
513
def bounding_box (self ):
512
514
"""An (x, y, w, h) tuple that completely covers all glyphs. The
513
515
first two numbers are offset from the x, y origin of this group"""
514
516
return self ._bounding_box
515
517
516
- # @property
517
- # def scale(self):
518
- # return self._scale
519
-
520
- # @scale.setter
521
- # #@displayio.Group.scale.setter
522
- # def scale(self, new_scale):
523
- # self._scale=new_scale
524
- # #super(displayio.Group, self).scale.fset(self, new_scale)
525
- # self.anchored_position=self._anchored_position # update the anchored_position
526
- # #displayio.Group.scale.__set__(self, new_scale)
527
- # #displayio.Group.scale=new_scale
528
- # #setattr(super(), "scale", new_scale)
529
- # #setattr(self, "scale", new_scale)
530
- # super(displayio.Group, self).scale.__set__(self, new_scale)
531
-
532
- def set_scale (self , new_scale ):
518
+ @property
519
+ def scale (self ):
533
520
"""Set the scaling of the label"""
534
- self ._scale = int (round (new_scale ))
535
- self .scale = self ._scale
536
- self .anchored_position = self ._anchored_position
521
+ return self ._scale
522
+
523
+ @scale .setter
524
+ def scale (self , new_scale ):
525
+ self .local_group .scale = new_scale
526
+ self ._scale = new_scale
527
+ self .anchored_position = self ._anchored_position # update the anchored_position
537
528
538
529
@property
539
530
def line_spacing (self ):
@@ -543,7 +534,10 @@ def line_spacing(self):
543
534
544
535
@line_spacing .setter
545
536
def line_spacing (self , new_line_spacing ):
546
- self ._reset_text (line_spacing = new_line_spacing )
537
+ if self ._save_text :
538
+ self ._reset_text (line_spacing = new_line_spacing )
539
+ else :
540
+ raise RuntimeError ("line_spacing is immutable when save_text is False" )
547
541
548
542
549
543
@property
@@ -592,7 +586,10 @@ def font(self):
592
586
593
587
@font .setter
594
588
def font (self , new_font ):
595
- self ._reset_text (font = new_font )
589
+ if self ._save_text :
590
+ self ._reset_text (font = new_font )
591
+ else :
592
+ raise RuntimeError ("font is immutable when save_text is False" )
596
593
597
594
@property
598
595
def anchor_point (self ):
@@ -617,16 +614,15 @@ def anchored_position(self):
617
614
@anchored_position .setter
618
615
def anchored_position (self , new_position ):
619
616
self ._anchored_position = new_position
620
-
621
617
# Set anchored_position
622
618
if (self ._anchor_point is not None ) and (self ._anchored_position is not None ):
623
619
self .x = int (
624
620
new_position [0 ]
625
- - (self ._bounding_box [0 ] * self ._scale )
626
- - round (self ._anchor_point [0 ] * (self ._bounding_box [2 ] * self ._scale ))
621
+ - (self ._bounding_box [0 ] * self .scale )
622
+ - round (self ._anchor_point [0 ] * (self ._bounding_box [2 ] * self .scale ))
627
623
)
628
624
self .y = int (
629
625
new_position [1 ]
630
- - (self ._bounding_box [1 ] * self ._scale )
631
- - round (self ._anchor_point [1 ] * self ._bounding_box [3 ] * self ._scale )
626
+ - (self ._bounding_box [1 ] * self .scale )
627
+ - round (self ._anchor_point [1 ] * self ._bounding_box [3 ] * self .scale )
632
628
)
0 commit comments