@@ -376,27 +376,25 @@ mod menu {
376
376
377
377
fn main_menu_setup ( mut commands : Commands , asset_server : Res < AssetServer > ) {
378
378
let font = asset_server. load ( "fonts/FiraSans-Bold.ttf" ) ;
379
+
379
380
// Common style for all buttons on the screen
380
- let button_style = Style {
381
- size : Size :: new ( Val :: Px ( 250.0 ) , Val :: Px ( 65.0 ) ) ,
382
- margin : UiRect :: all ( Val :: Px ( 20.0 ) ) ,
381
+ let button_spacing = Spacing :: margin ( UiRect :: all ( Val :: Px ( 20.0 ) ) ) ;
382
+ let button_layout = FlexLayout {
383
383
justify_content : JustifyContent :: Center ,
384
- align_items : AlignItems :: Center ,
385
- ..default ( )
386
- } ;
387
- let button_icon_style = Style {
388
- size : Size :: new ( Val :: Px ( 30.0 ) , Val :: Auto ) ,
389
- // This takes the icons out of the flexbox flow, to be positioned exactly
390
- position_type : PositionType :: Absolute ,
391
- // The icon will be close to the left border of the button
392
- position : UiRect {
393
- left : Val :: Px ( 10.0 ) ,
394
- right : Val :: Auto ,
395
- top : Val :: Auto ,
396
- bottom : Val :: Auto ,
397
- } ,
384
+ align_items : AlignItems ,
398
385
..default ( )
399
386
} ;
387
+ let button_size_constraints = SizeConstraints :: suggested ( Val :: Px ( 250.0 ) , Val :: Px ( 250.0 ) ) ;
388
+
389
+ let button_icon_size_constraints = SizeConstraints :: suggested ( Val :: Px ( 30.0 ) , Val :: Auto ) ;
390
+ let button_icon_offset = Offset ( UiRect {
391
+ left : Val :: Px ( 10.0 ) ,
392
+ right : Val :: Auto ,
393
+ top : Val :: Auto ,
394
+ bottom : Val :: Auto ,
395
+ } ) ;
396
+ let button_icon_position_type = PositionType :: Absolute ;
397
+
400
398
let button_text_style = TextStyle {
401
399
font : font. clone ( ) ,
402
400
font_size : 40.0 ,
@@ -426,7 +424,7 @@ mod menu {
426
424
color : TEXT_COLOR ,
427
425
} ,
428
426
)
429
- . with_layout ( FlexLayout {
427
+ . with_spacing ( Spacing {
430
428
margin : UiRect :: all ( Val :: Px ( 50.0 ) ) ,
431
429
..default ( )
432
430
} ) ,
@@ -438,15 +436,19 @@ mod menu {
438
436
// - quit
439
437
parent
440
438
. spawn_bundle ( ButtonBundle {
441
- style : button_style. clone ( ) ,
439
+ size_constraints : button_size_constraints. clone ( ) ,
440
+ flex_layout : button_layout. clone ( ) ,
441
+ spacing : button_spacing. clone ( ) ,
442
442
color : NORMAL_BUTTON . into ( ) ,
443
443
..default ( )
444
444
} )
445
445
. insert ( MenuButtonAction :: Play )
446
446
. with_children ( |parent| {
447
447
let icon = asset_server. load ( "textures/Game Icons/right.png" ) ;
448
448
parent. spawn_bundle ( ImageBundle {
449
- style : button_icon_style. clone ( ) ,
449
+ size_constraints : button_icon_size_constraints. clone ( ) ,
450
+ offset : button_icon_offset. clone ( ) ,
451
+ position_type : button_icon_position_type. clone ( ) ,
450
452
image : UiImage ( icon) ,
451
453
..default ( )
452
454
} ) ;
@@ -457,15 +459,19 @@ mod menu {
457
459
} ) ;
458
460
parent
459
461
. spawn_bundle ( ButtonBundle {
460
- style : button_style. clone ( ) ,
462
+ size_constraints : button_size_constraints. clone ( ) ,
463
+ flex_layout : button_layout. clone ( ) ,
464
+ spacing : button_spacing. clone ( ) ,
461
465
color : NORMAL_BUTTON . into ( ) ,
462
466
..default ( )
463
467
} )
464
468
. insert ( MenuButtonAction :: Settings )
465
469
. with_children ( |parent| {
466
470
let icon = asset_server. load ( "textures/Game Icons/wrench.png" ) ;
467
471
parent. spawn_bundle ( ImageBundle {
468
- style : button_icon_style. clone ( ) ,
472
+ size_constraints : button_icon_size_constraints. clone ( ) ,
473
+ offset : button_icon_offset. clone ( ) ,
474
+ position_type : button_icon_position_type. clone ( ) ,
469
475
image : UiImage ( icon) ,
470
476
..default ( )
471
477
} ) ;
@@ -476,15 +482,19 @@ mod menu {
476
482
} ) ;
477
483
parent
478
484
. spawn_bundle ( ButtonBundle {
479
- style : button_style,
485
+ size_constraints : button_size_constraints. clone ( ) ,
486
+ flex_layout : button_layout. clone ( ) ,
487
+ spacing : button_spacing. clone ( ) ,
480
488
color : NORMAL_BUTTON . into ( ) ,
481
489
..default ( )
482
490
} )
483
491
. insert ( MenuButtonAction :: Quit )
484
492
. with_children ( |parent| {
485
493
let icon = asset_server. load ( "textures/Game Icons/exitRight.png" ) ;
486
494
parent. spawn_bundle ( ImageBundle {
487
- style : button_icon_style,
495
+ size_constraints : button_icon_size_constraints. clone ( ) ,
496
+ offset : button_icon_offset. clone ( ) ,
497
+ position_type : button_icon_position_type. clone ( ) ,
488
498
image : UiImage ( icon) ,
489
499
..default ( )
490
500
} ) ;
@@ -494,14 +504,14 @@ mod menu {
494
504
}
495
505
496
506
fn settings_menu_setup ( mut commands : Commands , asset_server : Res < AssetServer > ) {
497
- let button_style = Style {
498
- size : Size :: new ( Val :: Px ( 200.0 ) , Val :: Px ( 65 .0) ) ,
499
- margin : UiRect :: all ( Val :: Px ( 20.0 ) ) ,
507
+ // Common style for all buttons on this menu
508
+ let button_spacing = Spacing :: margin ( UiRect :: all ( Val :: Px ( 20 .0) ) ) ;
509
+ let button_layout = FlexLayout {
500
510
justify_content : JustifyContent :: Center ,
501
511
align_items : AlignItems :: Center ,
502
512
..default ( )
503
513
} ;
504
-
514
+ let button_size_constraints = SizeConstraints :: suggested ( Val :: Px ( 250.0 ) , Val :: Px ( 65.0 ) ) ;
505
515
let button_text_style = TextStyle {
506
516
font : asset_server. load ( "fonts/FiraSans-Bold.ttf" ) ,
507
517
font_size : 40.0 ,
@@ -528,7 +538,9 @@ mod menu {
528
538
] {
529
539
parent
530
540
. spawn_bundle ( ButtonBundle {
531
- style : button_style. clone ( ) ,
541
+ size_constraints : button_size_constraints. clone ( ) ,
542
+ flex_layout : button_layout. clone ( ) ,
543
+ spacing : button_spacing. clone ( ) ,
532
544
color : NORMAL_BUTTON . into ( ) ,
533
545
..default ( )
534
546
} )
@@ -548,9 +560,10 @@ mod menu {
548
560
asset_server : Res < AssetServer > ,
549
561
display_quality : Res < DisplayQuality > ,
550
562
) {
551
- let button_style = Style {
552
- size : Size :: new ( Val :: Px ( 200.0 ) , Val :: Px ( 65.0 ) ) ,
553
- margin : UiRect :: all ( Val :: Px ( 20.0 ) ) ,
563
+ // Common style for all buttons on this menu
564
+ let button_size_constraints = SizeConstraints :: suggested ( Val :: Px ( 250.0 ) , Val :: Px ( 65.0 ) ) ;
565
+ let button_spacing = Spacing :: margin ( UiRect :: all ( Val :: Px ( 20.0 ) ) ) ;
566
+ let button_layout = FlexLayout {
554
567
justify_content : JustifyContent :: Center ,
555
568
align_items : AlignItems :: Center ,
556
569
..default ( )
@@ -598,10 +611,9 @@ mod menu {
598
611
DisplayQuality :: High ,
599
612
] {
600
613
let mut entity = parent. spawn_bundle ( ButtonBundle {
601
- style : Style {
602
- size : Size :: new ( Val :: Px ( 150.0 ) , Val :: Px ( 65.0 ) ) ,
603
- ..button_style. clone ( )
604
- } ,
614
+ size_constraints : SizeConstraints :: suggested ( Val :: Px ( 150.0 ) , Val :: Px ( 65.0 ) ) ,
615
+ spacing : button_spacing. clone ( ) ,
616
+ flex_layout : button_layout. clone ( ) ,
605
617
color : NORMAL_BUTTON . into ( ) ,
606
618
..default ( )
607
619
} ) ;
@@ -619,7 +631,9 @@ mod menu {
619
631
// Display the back button to return to the settings screen
620
632
parent
621
633
. spawn_bundle ( ButtonBundle {
622
- style : button_style,
634
+ size_constraints : button_size_constraints. clone ( ) ,
635
+ spacing : button_spacing. clone ( ) ,
636
+ flex_layout : button_layout. clone ( ) ,
623
637
color : NORMAL_BUTTON . into ( ) ,
624
638
..default ( )
625
639
} )
@@ -635,11 +649,12 @@ mod menu {
635
649
asset_server : Res < AssetServer > ,
636
650
volume : Res < Volume > ,
637
651
) {
638
- let button_style = Style {
639
- size : Size :: new ( Val :: Px ( 200.0 ) , Val :: Px ( 65.0 ) ) ,
640
- margin : UiRect :: all ( Val :: Px ( 20.0 ) ) ,
641
- justify_content : JustifyContent :: Center ,
652
+ // Common style for all buttons on this menu
653
+ let button_size_constraints = SizeConstraints :: suggested ( Val :: Px ( 200.0 ) , Val :: Px ( 65.0 ) ) ;
654
+ let button_spacing = Spacing :: margin ( UiRect :: all ( Val :: Px ( 20.0 ) ) ) ;
655
+ let button_layout = FlexLayout {
642
656
align_items : AlignItems :: Center ,
657
+ justify_content : JustifyContent :: Center ,
643
658
..default ( )
644
659
} ;
645
660
let button_text_style = TextStyle {
@@ -650,10 +665,10 @@ mod menu {
650
665
651
666
commands
652
667
. spawn_bundle ( NodeBundle {
653
- style : Style {
654
- margin : UiRect :: all ( Val :: Auto ) ,
655
- flex_direction : FlexDirection :: ColumnReverse ,
668
+ spacing : Spacing :: margin ( UiRect :: all ( Val :: Auto ) ) ,
669
+ flex_layout : FlexLayout {
656
670
align_items : AlignItems :: Center ,
671
+ flex_direction : FlexDirection :: ColumnReverse ,
657
672
..default ( )
658
673
} ,
659
674
color : Color :: CRIMSON . into ( ) ,
@@ -663,10 +678,7 @@ mod menu {
663
678
. with_children ( |parent| {
664
679
parent
665
680
. spawn_bundle ( NodeBundle {
666
- style : Style {
667
- align_items : AlignItems :: Center ,
668
- ..default ( )
669
- } ,
681
+ flex_layout : FlexLayout { align_items : AlignItems :: Center , ..default ( ) } ,
670
682
color : Color :: CRIMSON . into ( ) ,
671
683
..default ( )
672
684
} )
@@ -677,10 +689,9 @@ mod menu {
677
689
) ) ;
678
690
for volume_setting in [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] {
679
691
let mut entity = parent. spawn_bundle ( ButtonBundle {
680
- style : Style {
681
- size : Size :: new ( Val :: Px ( 30.0 ) , Val :: Px ( 65.0 ) ) ,
682
- ..button_style. clone ( )
683
- } ,
692
+ size_constraints : SizeConstraints :: suggested ( Val :: Px ( 30.0 ) , Val :: Px ( 65.0 ) ) ,
693
+ spacing : button_spacing. clone ( ) ,
694
+ flex_layout : button_layout. clone ( ) ,
684
695
color : NORMAL_BUTTON . into ( ) ,
685
696
..default ( )
686
697
} ) ;
@@ -692,7 +703,9 @@ mod menu {
692
703
} ) ;
693
704
parent
694
705
. spawn_bundle ( ButtonBundle {
695
- style : button_style,
706
+ size_constraints : button_size_constraints. clone ( ) ,
707
+ spacing : button_spacing. clone ( ) ,
708
+ flex_layout : button_layout. clone ( ) ,
696
709
color : NORMAL_BUTTON . into ( ) ,
697
710
..default ( )
698
711
} )
0 commit comments