@@ -63,9 +63,22 @@ def __init__(self, *, x, y, width, height, style=RECT,
63
63
self .width = width
64
64
self .height = height
65
65
self ._font = label_font
66
-
66
+ self . _selected = False
67
67
self .group = displayio .Group ()
68
68
69
+ self .fill_color = fill_color
70
+ self .outline_color = outline_color
71
+ self .label_color = label_color
72
+ # Selecting inverts the button colors!
73
+ self .selected_fill = selected_fill
74
+ self .selected_outline = selected_outline
75
+ self .selected_label = selected_label
76
+
77
+ if self .selected_fill is None and fill_color is not None :
78
+ self .selected_fill = (~ fill_color ) & 0xFFFFFF
79
+ if self .selected_outline is None and outline_color is not None :
80
+ self .selected_outline = (~ outline_color ) & 0xFFFFFF
81
+
69
82
if outline_color or fill_color :
70
83
self .body = self .shadow = None
71
84
if style == RECT :
@@ -99,7 +112,10 @@ def __init__(self, *, x, y, width, height, style=RECT,
99
112
self .label .y = y + (height - dims [3 ])
100
113
self .label .color = label_color
101
114
self .group .append (self .label )
102
- print (dims )
115
+
116
+ if self .selected_label is None and label_color is not None :
117
+ self .selected_label = (~ label_color ) & 0xFFFFFF
118
+ #print(dims)
103
119
104
120
"""
105
121
#else: # ok just a bounding box
@@ -108,12 +124,21 @@ def __init__(self, *, x, y, width, height, style=RECT,
108
124
"""
109
125
110
126
@property
111
- def select (self ):
127
+ def selected (self ):
112
128
return self ._selected
113
129
114
- @select .setter
115
- def select (self , value ):
116
- self ._selected = not self ._selected
130
+ @selected .setter
131
+ def selected (self , value ):
132
+ if value != self ._selected :
133
+ self ._selected = value
134
+ if self ._selected :
135
+ self .body .fill = self .selected_fill
136
+ self .body .outline = self .selected_outline
137
+ self .label .color = self .selected_label
138
+ else :
139
+ self .body .fill = self .fill_color
140
+ self .body .outline = self .outline_color
141
+ self .label .color = self .label_color
117
142
118
143
def contains (self , point ):
119
144
return (self .x <= point [0 ] <= self .x + self .width ) and (self .y <= point [1 ] <= self .y + self .height )
0 commit comments