@@ -60,10 +60,50 @@ def on_change(event: UIOnChangeEvent):
60
60
height: Height of each of the option.
61
61
default: The default value shown.
62
62
options: The options displayed when the layout is clicked.
63
+ primary_style: The style of the primary button.
64
+ dropdown_style: The style of the buttons in the dropdown.
65
+ active_style: The style of the dropdown button, which represents the active option.
63
66
"""
64
67
65
68
DIVIDER = None
66
69
70
+ DEFAULT_BUTTON_STYLE = {
71
+ "normal" : UIFlatButton .UIStyle (
72
+ font_color = uicolor .GREEN_NEPHRITIS ,
73
+ ),
74
+ "hover" : UIFlatButton .UIStyle (
75
+ font_color = uicolor .WHITE ,
76
+ bg = uicolor .DARK_BLUE_WET_ASPHALT ,
77
+ border = uicolor .GRAY_CONCRETE ,
78
+ ),
79
+ "press" : UIFlatButton .UIStyle (
80
+ font_color = uicolor .DARK_BLUE_MIDNIGHT_BLUE ,
81
+ bg = uicolor .WHITE_CLOUDS ,
82
+ border = uicolor .GRAY_CONCRETE ,
83
+ ),
84
+ "disabled" : UIFlatButton .UIStyle (
85
+ font_color = uicolor .WHITE_SILVER ,
86
+ bg = uicolor .GRAY_ASBESTOS ,
87
+ ),
88
+ }
89
+ DEFAULT_DROPDOWN_STYLE = {
90
+ "normal" : UIFlatButton .UIStyle (),
91
+ "hover" : UIFlatButton .UIStyle (
92
+ font_color = uicolor .WHITE ,
93
+ bg = uicolor .DARK_BLUE_WET_ASPHALT ,
94
+ border = uicolor .GRAY_CONCRETE ,
95
+ ),
96
+ "press" : UIFlatButton .UIStyle (
97
+ font_color = uicolor .DARK_BLUE_MIDNIGHT_BLUE ,
98
+ bg = uicolor .WHITE_CLOUDS ,
99
+ border = uicolor .GRAY_CONCRETE ,
100
+ ),
101
+ "disabled" : UIFlatButton .UIStyle (
102
+ font_color = uicolor .WHITE_SILVER ,
103
+ bg = uicolor .GRAY_ASBESTOS ,
104
+ ),
105
+ }
106
+
67
107
def __init__ (
68
108
self ,
69
109
* ,
@@ -73,8 +113,18 @@ def __init__(
73
113
height : float = 30 ,
74
114
default : Optional [str ] = None ,
75
115
options : Optional [list [Union [str , None ]]] = None ,
116
+ primary_style = None ,
117
+ dropdown_style = None ,
118
+ active_style = None ,
76
119
** kwargs ,
77
120
):
121
+ if primary_style is None :
122
+ primary_style = self .DEFAULT_BUTTON_STYLE
123
+ if dropdown_style is None :
124
+ dropdown_style = self .DEFAULT_DROPDOWN_STYLE
125
+ if active_style is None :
126
+ active_style = self .DEFAULT_BUTTON_STYLE
127
+
78
128
# TODO handle if default value not in options or options empty
79
129
if options is None :
80
130
options = []
@@ -83,13 +133,14 @@ def __init__(
83
133
84
134
super ().__init__ (x = x , y = y , width = width , height = height , ** kwargs )
85
135
136
+ self ._default_style = deepcopy (primary_style )
137
+ self ._dropdown_style = deepcopy (dropdown_style )
138
+ self ._active_style = deepcopy (active_style )
139
+
86
140
# Setup button showing value
87
- style = deepcopy (UIFlatButton .DEFAULT_STYLE )
88
- style ["hover" ].font_color = uicolor .GREEN_NEPHRITIS
89
141
self ._default_button = UIFlatButton (
90
- text = self ._value or "" , width = self .width , height = self .height , style = style
142
+ text = self ._value or "" , width = self .width , height = self .height , style = self . _default_style
91
143
)
92
-
93
144
self ._default_button .on_click = self ._on_button_click # type: ignore
94
145
95
146
self ._overlay = _UIDropdownOverlay ()
@@ -100,8 +151,6 @@ def __init__(
100
151
101
152
self .register_event_type ("on_change" )
102
153
103
- self .with_border (color = arcade .color .RED )
104
-
105
154
@property
106
155
def value (self ) -> Optional [str ]:
107
156
"""Current selected option."""
@@ -122,11 +171,6 @@ def _update_options(self):
122
171
# generate options
123
172
self ._overlay .clear ()
124
173
125
- # is there another way then deepcopy, does it matter?
126
- # ("premature optimization is the root of all evil")
127
- active_style = deepcopy (UIFlatButton .DEFAULT_STYLE )
128
- active_style ["normal" ]["bg" ] = uicolor .GREEN_NEPHRITIS
129
-
130
174
for option in self ._options :
131
175
if option is None : # None = UIDropdown.DIVIDER, required by pyright
132
176
self ._overlay .add (
@@ -139,7 +183,7 @@ def _update_options(self):
139
183
text = option ,
140
184
width = self .width ,
141
185
height = self .height ,
142
- style = active_style if self .value == option else UIFlatButton . DEFAULT_STYLE ,
186
+ style = self . _active_style if self .value == option else self . _dropdown_style ,
143
187
)
144
188
)
145
189
button .on_click = self ._on_option_click
0 commit comments