@@ -4,7 +4,7 @@ use bevy::prelude::*;
44use bevy_prototype_lyon:: prelude:: * ;
55use bevy_utils:: prelude:: { FillRectangle , LayoutSize , ShapeOp } ;
66
7- use crate :: prelude:: { BarData , NotationTheme } ;
7+ use crate :: prelude:: { BarData , NotationTheme , TabState } ;
88use notation_model:: prelude:: { Signature , TabBar } ;
99
1010#[ derive( Clone , Debug ) ]
@@ -13,6 +13,7 @@ pub struct BarBeatValue {
1313 pub bar_beats : u8 ,
1414 pub beat : u8 ,
1515 pub bar_size : LayoutSize ,
16+ pub selected : bool ,
1617}
1718impl Display for BarBeatValue {
1819 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
@@ -27,19 +28,9 @@ impl BarBeatValue {
2728 bar_beats,
2829 beat,
2930 bar_size : LayoutSize :: ZERO ,
31+ selected : false ,
3032 }
3133 }
32- pub fn may_new (
33- theme : & NotationTheme ,
34- tab_bar : & TabBar ,
35- signature : & Signature ,
36- beat : u8 ,
37- ) -> Option < Self > {
38- theme
39- . colors . bar
40- . get_beat_color ( signature, beat)
41- . map ( |_color| Self :: new ( tab_bar, signature, beat) )
42- }
4334}
4435
4536pub type BarBeatData = BarData < BarBeatValue > ;
@@ -49,8 +40,7 @@ impl ShapeOp<NotationTheme, FillRectangle> for BarBeatData {
4940 let signature = self . value . signature ;
5041 let color = theme
5142 . colors . bar
52- . get_beat_color ( & signature, self . value . beat )
53- . unwrap_or ( theme. core . background_color ) ;
43+ . get_beat_color ( & signature, self . value . beat , self . value . selected ) ;
5444 let x = self . value . bar_size . width / self . value . bar_beats as f32
5545 * self . value . beat as f32 ;
5646 FillRectangle {
@@ -63,4 +53,18 @@ impl ShapeOp<NotationTheme, FillRectangle> for BarBeatData {
6353 ) ,
6454 }
6555 }
56+ }
57+
58+ impl BarBeatData {
59+ pub fn update_all (
60+ commands : & mut Commands ,
61+ theme : & NotationTheme ,
62+ tab_state : & TabState ,
63+ beat_query : & mut Query < ( Entity , & mut BarBeatData ) > ,
64+ ) {
65+ for ( entity, mut data) in beat_query. iter_mut ( ) {
66+ data. value . selected = tab_state. is_bar_selected ( data. bar_props . bar_ordinal ) ;
67+ data. update ( commands, theme, entity) ;
68+ }
69+ }
6670}
0 commit comments