File tree Expand file tree Collapse file tree 3 files changed +52
-5
lines changed Expand file tree Collapse file tree 3 files changed +52
-5
lines changed Original file line number Diff line number Diff line change @@ -56,7 +56,6 @@ impl ActivatableScreen for IoBusScreen {
56
56
57
57
display. with_lock ( |target| {
58
58
draw_border ( target, "IOBus" , SCREEN_TYPE ) ;
59
- draw_button_legend ( target, "Toggle" , "Screen" ) ;
60
59
61
60
Text :: new ( "CAN Status:" , row_anchor ( 0 ) , ui_text_style)
62
61
. draw ( target)
@@ -134,6 +133,21 @@ impl ActivatableScreen for IoBusScreen {
134
133
)
135
134
} ) ;
136
135
136
+ widgets. push ( |display| {
137
+ DynamicWidget :: button_legend (
138
+ ui. res . regulators . iobus_pwr_en . clone ( ) ,
139
+ display,
140
+ |state : & bool | {
141
+ let lower = match * state {
142
+ false => "Turn On" ,
143
+ true => "Turn Off" ,
144
+ } ;
145
+
146
+ ( lower. into ( ) , "Screen" . into ( ) )
147
+ } ,
148
+ )
149
+ } ) ;
150
+
137
151
let iobus_pwr_en = ui. res . regulators . iobus_pwr_en . clone ( ) ;
138
152
139
153
let active = Active {
Original file line number Diff line number Diff line change @@ -56,10 +56,7 @@ impl ActivatableScreen for PowerScreen {
56
56
}
57
57
58
58
fn activate ( & mut self , ui : & Ui , display : Display ) -> Box < dyn ActiveScreen > {
59
- display. with_lock ( |target| {
60
- draw_border ( target, "DUT Power" , SCREEN_TYPE ) ;
61
- draw_button_legend ( target, "Toggle" , "Screen" ) ;
62
- } ) ;
59
+ display. with_lock ( |target| draw_border ( target, "DUT Power" , SCREEN_TYPE ) ) ;
63
60
64
61
let mut widgets = WidgetContainer :: new ( display) ;
65
62
@@ -135,6 +132,21 @@ impl ActivatableScreen for PowerScreen {
135
132
)
136
133
} ) ;
137
134
135
+ widgets. push ( |display| {
136
+ DynamicWidget :: button_legend (
137
+ ui. res . dut_pwr . state . clone ( ) ,
138
+ display,
139
+ |state : & OutputState | {
140
+ let lower = match state {
141
+ OutputState :: On => "Turn Off" ,
142
+ _ => "Turn On" ,
143
+ } ;
144
+
145
+ ( lower. into ( ) , "Screen" . into ( ) )
146
+ } ,
147
+ )
148
+ } ) ;
149
+
138
150
let power_state = ui. res . dut_pwr . state . clone ( ) ;
139
151
let power_request = ui. res . dut_pwr . request . clone ( ) ;
140
152
Original file line number Diff line number Diff line change @@ -318,6 +318,27 @@ impl<T: Serialize + DeserializeOwned + Send + Sync + Clone + 'static> DynamicWid
318
318
)
319
319
}
320
320
321
+ /// Draw a dynamic button legend
322
+ ///
323
+ /// Sometimes you want to draw different button legend text based on
324
+ /// external input. For example change from "Turn On" to "Turn Off" when
325
+ /// the status of the controlled value changes.
326
+ pub fn button_legend (
327
+ topic : Arc < Topic < T > > ,
328
+ display : Arc < Display > ,
329
+ format_fn : fn ( & T ) -> ( String , String ) ,
330
+ ) -> Self {
331
+ Self :: new (
332
+ topic,
333
+ display,
334
+ Box :: new ( move |msg, target| {
335
+ let ( lower, upper) = format_fn ( msg) ;
336
+
337
+ Some ( draw_button_legend ( target, & lower, & upper) )
338
+ } ) ,
339
+ )
340
+ }
341
+
321
342
/// Draw self-updating text with configurable alignment
322
343
pub fn text_aligned (
323
344
topic : Arc < Topic < T > > ,
You can’t perform that action at this time.
0 commit comments