7
7
class Button ():
8
8
RECT = const (0 )
9
9
ROUNDRECT = const (1 )
10
+ SHADOWRECT = const (2 )
11
+ SHADOWROUNDRECT = const (3 )
10
12
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 ):
13
17
self .x = x
14
18
self .y = y
15
19
self .width = width
@@ -19,8 +23,25 @@ def __init__(self, *, x, y, width, height, style=RECT,
19
23
self .group = displayio .Group ()
20
24
21
25
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 )
24
45
self .group .append (self .body )
25
46
26
47
if label : # button with text label
@@ -41,5 +62,14 @@ def __init__(self, *, x, y, width, height, style=RECT,
41
62
#self.bodyshape = displayio.Shape(width, height)
42
63
#self.group.append(self.bodyshape)
43
64
"""
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
+
44
74
def contains (self , point ):
45
75
return (self .x <= point [0 ] <= self .x + self .width ) and (self .y <= point [1 ] <= self .y + self .height )
0 commit comments