@@ -9,6 +9,7 @@ use smart_default::SmartDefault;
99pub struct Widget {
1010 pub state : State ,
1111 source : Source ,
12+ values : Values ,
1213}
1314
1415impl Widget {
@@ -48,21 +49,16 @@ impl Widget {
4849 }
4950
5051 pub fn set_format ( & mut self , format : Format ) {
51- match & mut self . source {
52- Source :: Format ( old, _) => * old = format,
53- _ => self . source = Source :: Format ( format, Default :: default ( ) ) ,
54- }
52+ self . source = Source :: Format ( format) ;
5553 }
5654
5755 pub fn set_values ( & mut self , new_values : Values ) {
58- if let Source :: Format ( _, values) = & mut self . source {
59- * values = new_values;
60- }
56+ self . values = new_values;
6157 }
6258
6359 pub fn intervals ( & self ) -> Vec < u64 > {
6460 match & self . source {
65- Source :: Format ( f, _ ) => f. intervals ( ) ,
61+ Source :: Format ( f) => f. intervals ( ) ,
6662 _ => Vec :: new ( ) ,
6763 }
6864 }
@@ -71,7 +67,7 @@ impl Widget {
7167 pub fn get_data ( & self , shared_config : & SharedConfig , id : usize ) -> Result < Vec < I3BarBlock > > {
7268 // Create a "template" block
7369 let ( key_bg, key_fg) = shared_config. theme . get_colors ( self . state ) ;
74- let ( full, short) = self . source . render ( shared_config) ?;
70+ let ( full, short) = self . source . render ( shared_config, & self . values ) ?;
7571 let mut template = I3BarBlock {
7672 instance : format ! ( "{id}:" ) ,
7773 background : key_bg,
@@ -142,14 +138,18 @@ enum Source {
142138 /// Simple text
143139 Text ( String ) ,
144140 /// A format template
145- Format ( Format , Values ) ,
141+ Format ( Format ) ,
146142}
147143
148144impl Source {
149- fn render ( & self , config : & SharedConfig ) -> Result < ( Vec < Fragment > , Vec < Fragment > ) > {
145+ fn render (
146+ & self ,
147+ config : & SharedConfig ,
148+ values : & Values ,
149+ ) -> Result < ( Vec < Fragment > , Vec < Fragment > ) > {
150150 match self {
151151 Self :: Text ( text) => Ok ( ( vec ! [ text. clone( ) . into( ) ] , vec ! [ ] ) ) ,
152- Self :: Format ( format, values ) => format. render ( values, config) ,
152+ Self :: Format ( format) => format. render ( values, config) ,
153153 Self :: None => Ok ( ( vec ! [ ] , vec ! [ ] ) ) ,
154154 }
155155 }
0 commit comments