@@ -12,7 +12,7 @@ use crate::components::microphone::*;
12
12
use crate :: components:: source:: * ;
13
13
use crate :: components:: states:: { MenuSelected , Selected } ;
14
14
use crate :: components:: wall:: { CircWall , RectWall , Wall } ;
15
- use crate :: events:: UpdateWalls ;
15
+ use crate :: events:: { ResetEvent , UpdateWalls } ;
16
16
use crate :: grid:: grid:: Grid ;
17
17
use crate :: math:: constants:: * ;
18
18
use crate :: math:: fft:: calc_mic_spectrum;
@@ -29,6 +29,7 @@ pub fn draw_egui(
29
29
mut grid : ResMut < Grid > ,
30
30
mut gradient : ResMut < GradientResource > ,
31
31
mut wall_update_ev : EventWriter < UpdateWalls > ,
32
+ mut reset_ev : EventWriter < ResetEvent > ,
32
33
mut rect_wall_set : ParamSet < (
33
34
Query < ( Entity , & mut RectWall ) > ,
34
35
Query < ( Entity , & mut RectWall ) , With < Selected > > ,
@@ -236,34 +237,54 @@ pub fn draw_egui(
236
237
let collapse = ui. collapsing ( format ! ( "Source {}" , source. id) , |ui| {
237
238
ui. horizontal ( |ui| {
238
239
ui. label ( "x:" ) ;
239
- ui. add (
240
- egui:: DragValue :: new ( & mut source. x )
241
- . speed ( 1 )
242
- . clamp_range ( 0.0 ..=SIMULATION_WIDTH as f32 - 1. ) ,
243
- ) ;
240
+ if ui
241
+ . add (
242
+ egui:: DragValue :: new ( & mut source. x )
243
+ . speed ( 1 )
244
+ . clamp_range ( 0.0 ..=SIMULATION_WIDTH as f32 - 1. ) ,
245
+ )
246
+ . changed ( )
247
+ {
248
+ reset_ev. send ( ResetEvent ) ;
249
+ }
244
250
ui. add_space ( 10. ) ;
245
251
ui. label ( "y:" ) ;
246
- ui. add (
247
- egui:: DragValue :: new ( & mut source. y )
248
- . speed ( 1 )
249
- . clamp_range ( 0.0 ..=SIMULATION_HEIGHT as f32 - 1. ) ,
250
- ) ;
252
+ if ui
253
+ . add (
254
+ egui:: DragValue :: new ( & mut source. y )
255
+ . speed ( 1 )
256
+ . clamp_range ( 0.0 ..=SIMULATION_HEIGHT as f32 - 1. ) ,
257
+ )
258
+ . changed ( )
259
+ {
260
+ reset_ev. send ( ResetEvent ) ;
261
+ }
251
262
} ) ;
252
263
if source. source_type != SourceType :: WhiteNoise {
253
- ui. add (
254
- egui:: Slider :: new ( & mut source. frequency , 0.0 ..=20000.0 )
255
- . text ( "Frequency (Hz)" ) ,
256
- ) ;
264
+ if ui
265
+ . add (
266
+ egui:: Slider :: new ( & mut source. frequency , 0.0 ..=20000.0 )
267
+ . text ( "Frequency (Hz)" ) ,
268
+ )
269
+ . changed ( )
270
+ {
271
+ reset_ev. send ( ResetEvent ) ;
272
+ }
257
273
}
258
274
ui. add (
259
275
egui:: Slider :: new ( & mut source. amplitude , 0.0 ..=25.0 )
260
276
. text ( "Amplitude" ) ,
261
277
) ;
262
278
if source. source_type == SourceType :: Sin {
263
- ui. add (
264
- egui:: Slider :: new ( & mut source. phase , 0.0 ..=360.0 )
265
- . text ( "Phase (°)" ) ,
266
- ) ;
279
+ if ui
280
+ . add (
281
+ egui:: Slider :: new ( & mut source. phase , 0.0 ..=360.0 )
282
+ . text ( "Phase (°)" ) ,
283
+ )
284
+ . changed ( )
285
+ {
286
+ reset_ev. send ( ResetEvent ) ;
287
+ }
267
288
}
268
289
269
290
egui:: ComboBox :: from_label ( "Waveform" )
@@ -374,6 +395,7 @@ pub fn draw_egui(
374
395
if wall. rect . min . x > wall. rect . max . x {
375
396
wall. rect . min . x = wall. rect . max . x ;
376
397
}
398
+ reset_ev. send ( ResetEvent ) ;
377
399
}
378
400
ui. add_space ( 10. ) ;
379
401
ui. label ( "Top Corner x:" ) ;
@@ -386,6 +408,7 @@ pub fn draw_egui(
386
408
. changed ( )
387
409
{
388
410
// wall.update_calc_rect(ui_state.boundary_width);
411
+ reset_ev. send ( ResetEvent ) ;
389
412
}
390
413
} ) ;
391
414
@@ -400,6 +423,7 @@ pub fn draw_egui(
400
423
. changed ( )
401
424
{
402
425
// wall.update_calc_rect(ui_state.boundary_width);
426
+ reset_ev. send ( ResetEvent ) ;
403
427
}
404
428
ui. add_space ( 10. ) ;
405
429
ui. label ( "Bottom Corner y:" ) ;
@@ -412,6 +436,7 @@ pub fn draw_egui(
412
436
. changed ( )
413
437
{
414
438
// wall.update_calc_rect(ui_state.boundary_width);
439
+ reset_ev. send ( ResetEvent ) ;
415
440
}
416
441
} ) ;
417
442
@@ -429,19 +454,26 @@ pub fn draw_egui(
429
454
) ) ;
430
455
} ) ;
431
456
432
- ui. add (
433
- // 0.01 because rendering then draws white
434
- egui:: Slider :: new ( & mut wall. reflection_factor , 0.01 ..=1.0 )
435
- . text ( "Wall Reflection Factor" ) ,
436
- ) ;
457
+ if ui
458
+ . add (
459
+ // 0.01 because rendering then draws white
460
+ egui:: Slider :: new ( & mut wall. reflection_factor , 0.01 ..=1.0 )
461
+ . text ( "Wall Reflection Factor" ) ,
462
+ )
463
+ . changed ( )
464
+ {
465
+ reset_ev. send ( ResetEvent ) ;
466
+ }
437
467
438
468
if ui. checkbox ( & mut wall. is_hollow , "Hollow Wall" ) . changed ( ) {
439
469
wall_update_ev. send ( UpdateWalls ) ;
470
+ reset_ev. send ( ResetEvent ) ;
440
471
} ;
441
472
442
473
if ui. add ( egui:: Button :: new ( "Delete" ) ) . clicked ( ) {
443
474
commands. entity ( * entity) . despawn ( ) ;
444
475
wall_update_ev. send ( UpdateWalls ) ;
476
+ reset_ev. send ( ResetEvent ) ;
445
477
}
446
478
} ) ;
447
479
@@ -478,18 +510,25 @@ pub fn draw_egui(
478
510
) ) ;
479
511
} ) ;
480
512
481
- ui. add (
482
- egui:: Slider :: new ( & mut wall. reflection_factor , 0.01 ..=1.0 )
483
- . text ( "Wall Reflection Factor" ) ,
484
- ) ;
513
+ if ui
514
+ . add (
515
+ egui:: Slider :: new ( & mut wall. reflection_factor , 0.01 ..=1.0 )
516
+ . text ( "Wall Reflection Factor" ) ,
517
+ )
518
+ . changed ( )
519
+ {
520
+ reset_ev. send ( ResetEvent ) ;
521
+ }
485
522
486
523
if ui. checkbox ( & mut wall. is_hollow , "Hollow Wall" ) . changed ( ) {
487
524
wall_update_ev. send ( UpdateWalls ) ;
525
+ reset_ev. send ( ResetEvent ) ;
488
526
} ;
489
527
490
528
if ui. add ( egui:: Button :: new ( "Delete" ) ) . clicked ( ) {
491
529
commands. entity ( * entity) . despawn ( ) ;
492
530
wall_update_ev. send ( UpdateWalls ) ;
531
+ reset_ev. send ( ResetEvent ) ;
493
532
}
494
533
} ) ;
495
534
@@ -508,12 +547,6 @@ pub fn draw_egui(
508
547
ui. heading ( "General Settings" ) ;
509
548
ui. separator ( ) ;
510
549
511
- ui. horizontal ( |ui| {
512
- ui. color_edit_button_srgba ( & mut gradient. 0 ) ;
513
- ui. color_edit_button_srgba ( & mut gradient. 1 ) ;
514
- } ) ;
515
- ui. separator ( ) ;
516
-
517
550
ui. horizontal ( |ui| {
518
551
if ui
519
552
. button ( if ui_state. is_running { "Stop" } else { "Start" } )
@@ -548,13 +581,25 @@ pub fn draw_egui(
548
581
grid. reset_cells ( ui_state. boundary_width ) ;
549
582
wall_update_ev. send ( UpdateWalls ) ;
550
583
}
584
+
585
+ ui. checkbox ( & mut ui_state. reset_on_change , "Reset on Change" )
551
586
} ) ;
552
587
553
- ui. add (
554
- egui:: Slider :: new ( & mut ui_state. delta_l , 0.0 ..=10.0 )
555
- . text ( "Delta L" )
556
- . logarithmic ( true ) ,
557
- ) ;
588
+ if ui
589
+ . add (
590
+ egui:: Slider :: new ( & mut ui_state. delta_l , 0.0 ..=10.0 )
591
+ . text ( "Delta L" )
592
+ . logarithmic ( true ) ,
593
+ )
594
+ . changed ( )
595
+ {
596
+ reset_ev. send ( ResetEvent ) ;
597
+ }
598
+
599
+ ui. horizontal ( |ui| {
600
+ ui. color_edit_button_srgba ( & mut gradient. 0 ) ;
601
+ ui. color_edit_button_srgba ( & mut gradient. 1 ) ;
602
+ } ) ;
558
603
559
604
if ui
560
605
. checkbox ( & mut ui_state. show_plots , "Show Plots" )
@@ -810,7 +855,9 @@ pub fn draw_egui(
810
855
. x_axis_label ( "Frequency (Hz)" )
811
856
. y_axis_label ( "Intensity (dB)" )
812
857
. x_grid_spacer ( |input| {
813
- let mut marks = Vec :: with_capacity ( input. bounds . 1 as usize - input. bounds . 0 as usize + 1 ) ;
858
+ let mut marks = Vec :: with_capacity (
859
+ input. bounds . 1 as usize - input. bounds . 0 as usize + 1 ,
860
+ ) ;
814
861
815
862
for i in input. bounds . 0 as u32 + 1 ..=input. bounds . 1 as u32 {
816
863
marks. push ( GridMark {
0 commit comments