@@ -63,9 +63,22 @@ def __init__(self, *, x, y, width, height, style=RECT,
6363 self .width = width
6464 self .height = height
6565 self ._font = label_font
66-
66+ self . _selected = False
6767 self .group = displayio .Group ()
6868
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+
6982 if outline_color or fill_color :
7083 self .body = self .shadow = None
7184 if style == RECT :
@@ -99,7 +112,10 @@ def __init__(self, *, x, y, width, height, style=RECT,
99112 self .label .y = y + (height - dims [3 ])
100113 self .label .color = label_color
101114 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)
103119
104120 """
105121 #else: # ok just a bounding box
@@ -108,12 +124,21 @@ def __init__(self, *, x, y, width, height, style=RECT,
108124 """
109125
110126 @property
111- def select (self ):
127+ def selected (self ):
112128 return self ._selected
113129
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
117142
118143 def contains (self , point ):
119144 return (self .x <= point [0 ] <= self .x + self .width ) and (self .y <= point [1 ] <= self .y + self .height )
0 commit comments