77class Button ():
88 RECT = const (0 )
99 ROUNDRECT = const (1 )
10+ SHADOWRECT = const (2 )
11+ SHADOWROUNDRECT = const (3 )
1012 def __init__ (self , * , x , y , width , height , style = RECT ,
11- fill_color = None , outline_color = 0x808080 ,
12- label = None , label_font = None , label_color = 0x808080 ):
13+ fill_color = 0xFFFFFF , outline_color = 0x0 ,
14+ label = None , label_font = None , label_color = 0x0 ,
15+ selected_fill = None , selected_outline = None ,
16+ selected_label = None ):
1317 self .x = x
1418 self .y = y
1519 self .width = width
@@ -19,8 +23,25 @@ def __init__(self, *, x, y, width, height, style=RECT,
1923 self .group = displayio .Group ()
2024
2125 if outline_color or fill_color :
22- self .body = Rect (x , y , width , height ,
23- fill = fill_color , outline = outline_color )
26+ self .body = self .shadow = None
27+ if style == RECT :
28+ self .body = Rect (x , y , width , height ,
29+ fill = fill_color , outline = outline_color )
30+ elif style == ROUNDRECT :
31+ self .body = RoundRect (x , y , width , height , r = 10 ,
32+ fill = fill_color , outline = outline_color )
33+ elif style == SHADOWRECT :
34+ self .shadow = Rect (x + 2 , y + 2 , width - 2 , height - 2 ,
35+ fill = outline_color )
36+ self .body = Rect (x , y , width - 2 , height - 2 ,
37+ fill = fill_color , outline = outline_color )
38+ elif style == SHADOWROUNDRECT :
39+ self .shadow = RoundRect (x + 2 , y + 2 , width - 2 , height - 2 , r = 10 ,
40+ fill = outline_color )
41+ self .body = RoundRect (x , y , width - 2 , height - 2 , r = 10 ,
42+ fill = fill_color , outline = outline_color )
43+ if self .shadow :
44+ self .group .append (self .shadow )
2445 self .group .append (self .body )
2546
2647 if label : # button with text label
@@ -41,5 +62,14 @@ def __init__(self, *, x, y, width, height, style=RECT,
4162 #self.bodyshape = displayio.Shape(width, height)
4263 #self.group.append(self.bodyshape)
4364 """
65+
66+ @property
67+ def select (self ):
68+ return self ._selected
69+
70+ @select .setter
71+ def select (self , value ):
72+ self ._selected = not self ._selected
73+
4474 def contains (self , point ):
4575 return (self .x <= point [0 ] <= self .x + self .width ) and (self .y <= point [1 ] <= self .y + self .height )
0 commit comments