Skip to content

Commit 6842af4

Browse files
committed
use extended Group instead of property
1 parent 4f49de1 commit 6842af4

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

adafruit_button.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,13 @@ def __init__(
100100
selected_outline=None,
101101
selected_label=None
102102
):
103-
super().__init__()
103+
super().__init__(x=x, y=y)
104104
self.x = x
105105
self.y = y
106106
self.width = width
107107
self.height = height
108108
self._font = label_font
109109
self._selected = False
110-
self.group = displayio.Group()
111110
self.name = name
112111
self._label = label
113112
self.body = self.fill = self.shadow = None
@@ -129,17 +128,17 @@ def __init__(
129128
if (outline_color is not None) or (fill_color is not None):
130129
if style == Button.RECT:
131130
self.body = Rect(
132-
x,
133-
y,
131+
0,
132+
0,
134133
width,
135134
height,
136135
fill=self.fill_color,
137136
outline=self.outline_color,
138137
)
139138
elif style == Button.ROUNDRECT:
140139
self.body = RoundRect(
141-
x,
142-
y,
140+
0,
141+
0,
143142
width,
144143
height,
145144
r=10,
@@ -148,32 +147,32 @@ def __init__(
148147
)
149148
elif style == Button.SHADOWRECT:
150149
self.shadow = Rect(
151-
x + 2, y + 2, width - 2, height - 2, fill=outline_color
150+
0 + 2, 0 + 2, width - 2, height - 2, fill=outline_color
152151
)
153152
self.body = Rect(
154-
x,
155-
y,
153+
0,
154+
0,
156155
width - 2,
157156
height - 2,
158157
fill=self.fill_color,
159158
outline=self.outline_color,
160159
)
161160
elif style == Button.SHADOWROUNDRECT:
162161
self.shadow = RoundRect(
163-
x + 2, y + 2, width - 2, height - 2, r=10, fill=self.outline_color
162+
0 + 2, 0 + 2, width - 2, height - 2, r=10, fill=self.outline_color
164163
)
165164
self.body = RoundRect(
166-
x,
167-
y,
165+
0,
166+
0,
168167
width - 2,
169168
height - 2,
170169
r=10,
171170
fill=self.fill_color,
172171
outline=self.outline_color,
173172
)
174173
if self.shadow:
175-
self.group.append(self.shadow)
176-
self.group.append(self.body)
174+
self.append(self.shadow)
175+
self.append(self.body)
177176

178177
self.label = label
179178

@@ -184,8 +183,8 @@ def label(self):
184183

185184
@label.setter
186185
def label(self, newtext):
187-
if self._label and self.group and (self.group[-1] == self._label):
188-
self.group.pop()
186+
if self._label and self and (self[-1] == self._label):
187+
self.pop()
189188

190189
self._label = None
191190
if not newtext or (self._label_color is None): # no new text
@@ -197,10 +196,10 @@ def label(self, newtext):
197196
dims = self._label.bounding_box
198197
if dims[2] >= self.width or dims[3] >= self.height:
199198
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
199+
self._label.x = 0 + (self.width - dims[2]) // 2
200+
self._label.y = 0 + self.height // 2
202201
self._label.color = self._label_color
203-
self.group.append(self._label)
202+
self.append(self._label)
204203

205204
if (self.selected_label is None) and (self._label_color is not None):
206205
self.selected_label = (~self._label_color) & 0xFFFFFF

0 commit comments

Comments
 (0)