@@ -100,14 +100,13 @@ def __init__(
100
100
selected_outline = None ,
101
101
selected_label = None
102
102
):
103
- super ().__init__ ()
103
+ super ().__init__ (x = x , y = y )
104
104
self .x = x
105
105
self .y = y
106
106
self .width = width
107
107
self .height = height
108
108
self ._font = label_font
109
109
self ._selected = False
110
- self .group = displayio .Group ()
111
110
self .name = name
112
111
self ._label = label
113
112
self .body = self .fill = self .shadow = None
@@ -129,51 +128,49 @@ def __init__(
129
128
if (outline_color is not None ) or (fill_color is not None ):
130
129
if style == Button .RECT :
131
130
self .body = Rect (
132
- x ,
133
- y ,
131
+ 0 ,
132
+ 0 ,
134
133
width ,
135
134
height ,
136
135
fill = self .fill_color ,
137
136
outline = self .outline_color ,
138
137
)
139
138
elif style == Button .ROUNDRECT :
140
139
self .body = RoundRect (
141
- x ,
142
- y ,
140
+ 0 ,
141
+ 0 ,
143
142
width ,
144
143
height ,
145
144
r = 10 ,
146
145
fill = self .fill_color ,
147
146
outline = self .outline_color ,
148
147
)
149
148
elif style == Button .SHADOWRECT :
150
- self .shadow = Rect (
151
- x + 2 , y + 2 , width - 2 , height - 2 , fill = outline_color
152
- )
149
+ self .shadow = Rect (2 , 2 , width - 2 , height - 2 , fill = outline_color )
153
150
self .body = Rect (
154
- x ,
155
- y ,
151
+ 0 ,
152
+ 0 ,
156
153
width - 2 ,
157
154
height - 2 ,
158
155
fill = self .fill_color ,
159
156
outline = self .outline_color ,
160
157
)
161
158
elif style == Button .SHADOWROUNDRECT :
162
159
self .shadow = RoundRect (
163
- x + 2 , y + 2 , width - 2 , height - 2 , r = 10 , fill = self .outline_color
160
+ 2 , 2 , width - 2 , height - 2 , r = 10 , fill = self .outline_color
164
161
)
165
162
self .body = RoundRect (
166
- x ,
167
- y ,
163
+ 0 ,
164
+ 0 ,
168
165
width - 2 ,
169
166
height - 2 ,
170
167
r = 10 ,
171
168
fill = self .fill_color ,
172
169
outline = self .outline_color ,
173
170
)
174
171
if self .shadow :
175
- self .group . append (self .shadow )
176
- self .group . append (self .body )
172
+ self .append (self .shadow )
173
+ self .append (self .body )
177
174
178
175
self .label = label
179
176
@@ -184,8 +181,8 @@ def label(self):
184
181
185
182
@label .setter
186
183
def label (self , newtext ):
187
- if self ._label and self . group and (self . group [- 1 ] == self ._label ):
188
- self .group . pop ()
184
+ if self ._label and self and (self [- 1 ] == self ._label ):
185
+ self .pop ()
189
186
190
187
self ._label = None
191
188
if not newtext or (self ._label_color is None ): # no new text
@@ -197,10 +194,10 @@ def label(self, newtext):
197
194
dims = self ._label .bounding_box
198
195
if dims [2 ] >= self .width or dims [3 ] >= self .height :
199
196
raise RuntimeError ("Button not large enough for label" )
200
- self ._label .x = self . x + (self .width - dims [2 ]) // 2
201
- self ._label .y = self .y + self . height // 2
197
+ self ._label .x = (self .width - dims [2 ]) // 2
198
+ self ._label .y = self .height // 2
202
199
self ._label .color = self ._label_color
203
- self .group . append (self ._label )
200
+ self .append (self ._label )
204
201
205
202
if (self .selected_label is None ) and (self ._label_color is not None ):
206
203
self .selected_label = (~ self ._label_color ) & 0xFFFFFF
@@ -230,6 +227,16 @@ def selected(self, value):
230
227
if self ._label is not None :
231
228
self ._label .color = new_label
232
229
230
+ @property
231
+ def group (self ):
232
+ """Return self for compatibility with old API."""
233
+ print (
234
+ "Warning: The group property is being deprecated. "
235
+ "User code should be updated to add the Button directly to the "
236
+ "Display or other Groups."
237
+ )
238
+ return self
239
+
233
240
def contains (self , point ):
234
241
"""Used to determine if a point is contained within a button. For example,
235
242
``button.contains(touch)`` where ``touch`` is the touch point on the screen will allow for
0 commit comments