@@ -125,12 +125,7 @@ fn setup(
125
125
// Create the root UI element.
126
126
let font = asset_server. load ( FONT_PATH ) ;
127
127
let color_grading = ColorGrading :: default ( ) ;
128
- add_buttons (
129
- & mut commands,
130
- & currently_selected_option,
131
- & font,
132
- & color_grading,
133
- ) ;
128
+ add_buttons ( & mut commands, & font, & color_grading) ;
134
129
135
130
// Spawn help text.
136
131
add_help_text ( & mut commands, & font, & currently_selected_option) ;
@@ -140,12 +135,7 @@ fn setup(
140
135
}
141
136
142
137
/// Adds all the buttons on the bottom of the scene.
143
- fn add_buttons (
144
- commands : & mut Commands ,
145
- currently_selected_option : & SelectedColorGradingOption ,
146
- font : & Handle < Font > ,
147
- color_grading : & ColorGrading ,
148
- ) {
138
+ fn add_buttons ( commands : & mut Commands , font : & Handle < Font > , color_grading : & ColorGrading ) {
149
139
// Spawn the parent node that contains all the buttons.
150
140
commands
151
141
. spawn ( NodeBundle {
@@ -161,26 +151,15 @@ fn add_buttons(
161
151
} )
162
152
. with_children ( |parent| {
163
153
// Create the first row, which contains the global controls.
164
- add_buttons_for_global_controls (
165
- parent,
166
- * currently_selected_option,
167
- color_grading,
168
- font,
169
- ) ;
154
+ add_buttons_for_global_controls ( parent, color_grading, font) ;
170
155
171
156
// Create the rows for individual controls.
172
157
for section in [
173
158
SelectedColorGradingSection :: Highlights ,
174
159
SelectedColorGradingSection :: Midtones ,
175
160
SelectedColorGradingSection :: Shadows ,
176
161
] {
177
- add_buttons_for_section (
178
- parent,
179
- section,
180
- * currently_selected_option,
181
- color_grading,
182
- font,
183
- ) ;
162
+ add_buttons_for_section ( parent, section, color_grading, font) ;
184
163
}
185
164
} ) ;
186
165
}
@@ -189,7 +168,6 @@ fn add_buttons(
189
168
/// whole as opposed to shadows, midtones, or highlights).
190
169
fn add_buttons_for_global_controls (
191
170
parent : & mut ChildBuilder ,
192
- currently_selected_option : SelectedColorGradingOption ,
193
171
color_grading : & ColorGrading ,
194
172
font : & Handle < Font > ,
195
173
) {
@@ -219,7 +197,6 @@ fn add_buttons_for_global_controls(
219
197
add_button_for_value (
220
198
parent,
221
199
SelectedColorGradingOption :: Global ( option) ,
222
- currently_selected_option,
223
200
color_grading,
224
201
font,
225
202
) ;
@@ -232,7 +209,6 @@ fn add_buttons_for_global_controls(
232
209
fn add_buttons_for_section (
233
210
parent : & mut ChildBuilder ,
234
211
section : SelectedColorGradingSection ,
235
- currently_selected_option : SelectedColorGradingOption ,
236
212
color_grading : & ColorGrading ,
237
213
font : & Handle < Font > ,
238
214
) {
@@ -263,7 +239,6 @@ fn add_buttons_for_section(
263
239
add_button_for_value (
264
240
parent,
265
241
SelectedColorGradingOption :: Section ( section, option) ,
266
- currently_selected_option,
267
242
color_grading,
268
243
font,
269
244
) ;
@@ -275,18 +250,9 @@ fn add_buttons_for_section(
275
250
fn add_button_for_value (
276
251
parent : & mut ChildBuilder ,
277
252
option : SelectedColorGradingOption ,
278
- currently_selected_option : SelectedColorGradingOption ,
279
253
color_grading : & ColorGrading ,
280
254
font : & Handle < Font > ,
281
255
) {
282
- let is_selected = currently_selected_option == option;
283
-
284
- let ( bg_color, fg_color) = if is_selected {
285
- ( Color :: WHITE , Color :: BLACK )
286
- } else {
287
- ( Color :: BLACK , Color :: WHITE )
288
- } ;
289
-
290
256
// Add the button node.
291
257
parent
292
258
. spawn ( ButtonBundle {
@@ -301,7 +267,7 @@ fn add_button_for_value(
301
267
} ,
302
268
border_color : BorderColor ( Color :: WHITE ) ,
303
269
border_radius : BorderRadius :: MAX ,
304
- image : UiImage :: default ( ) . with_color ( bg_color ) ,
270
+ image : UiImage :: default ( ) . with_color ( Color :: BLACK ) ,
305
271
..default ( )
306
272
} )
307
273
. insert ( ColorGradingOptionWidget {
@@ -314,7 +280,7 @@ fn add_button_for_value(
314
280
SelectedColorGradingOption :: Global ( option) => option. to_string ( ) ,
315
281
SelectedColorGradingOption :: Section ( _, option) => option. to_string ( ) ,
316
282
} ;
317
- add_text ( parent, & label, font, fg_color ) . insert ( ColorGradingOptionWidget {
283
+ add_text ( parent, & label, font, Color :: WHITE ) . insert ( ColorGradingOptionWidget {
318
284
widget_type : ColorGradingOptionWidgetType :: Label ,
319
285
option,
320
286
} ) ;
@@ -333,7 +299,7 @@ fn add_button_for_value(
333
299
parent,
334
300
& format ! ( "{:.3}" , option. get( color_grading) ) ,
335
301
font,
336
- fg_color ,
302
+ Color :: WHITE ,
337
303
)
338
304
. insert ( ColorGradingOptionWidget {
339
305
widget_type : ColorGradingOptionWidgetType :: Value ,
@@ -599,19 +565,26 @@ fn handle_button_presses(
599
565
600
566
/// Updates the state of the UI based on the current state.
601
567
fn update_ui_state (
602
- mut buttons : Query < ( & mut UiImage , & ColorGradingOptionWidget ) > ,
568
+ mut buttons : Query < ( & mut UiImage , & mut BorderColor , & ColorGradingOptionWidget ) > ,
603
569
mut button_text : Query < ( & mut Text , & ColorGradingOptionWidget ) , Without < HelpText > > ,
604
570
mut help_text : Query < & mut Text , With < HelpText > > ,
605
571
cameras : Query < & ColorGrading > ,
606
572
currently_selected_option : Res < SelectedColorGradingOption > ,
607
573
) {
574
+ // Exit early if the UI didn't change
575
+ if !currently_selected_option. is_changed ( ) {
576
+ return ;
577
+ }
578
+
608
579
// The currently-selected option is drawn with inverted colors.
609
- for ( mut image, widget) in buttons. iter_mut ( ) {
610
- image. color = if * currently_selected_option == widget. option {
611
- Color :: WHITE
580
+ for ( mut image, mut border_color, widget) in buttons. iter_mut ( ) {
581
+ if * currently_selected_option == widget. option {
582
+ image. color = Color :: WHITE ;
583
+ * border_color = Color :: BLACK . into ( ) ;
612
584
} else {
613
- Color :: BLACK
614
- } ;
585
+ image. color = Color :: BLACK ;
586
+ * border_color = Color :: WHITE . into ( ) ;
587
+ }
615
588
}
616
589
617
590
let value_label = cameras
@@ -646,11 +619,7 @@ fn update_ui_state(
646
619
}
647
620
648
621
// Update the help text.
649
- for mut help_text in help_text. iter_mut ( ) {
650
- for section in & mut help_text. sections {
651
- section. value = create_help_text ( & currently_selected_option) ;
652
- }
653
- }
622
+ help_text. single_mut ( ) . sections [ 0 ] . value = create_help_text ( & currently_selected_option) ;
654
623
}
655
624
656
625
/// Creates the help text at the top left of the window.
0 commit comments