@@ -92,6 +92,7 @@ fn main() -> anyhow::Result<()> {
9292 let mut question_id = Default :: default ( ) ;
9393 let mut question_text = Default :: default ( ) ;
9494 let mut options: Vec < String > = Default :: default ( ) ;
95+ let mut selection: u8 = 0 ;
9596
9697 let header_text_bounds = Rectangle :: new (
9798 Point :: zero ( ) ,
@@ -129,7 +130,7 @@ fn main() -> anyhow::Result<()> {
129130 ) ;
130131 text_box. draw ( & mut display) . unwrap ( ) ;
131132 for ( idx, option) in options. iter ( ) . enumerate ( ) {
132- let selected = idx == 0 ;
133+ let selected = idx as u8 == selection ;
133134 Text :: new (
134135 format ! ( "{} {}" , if selected { ">" } else { " " } , option) . as_str ( ) ,
135136 Point :: new ( 0 , 20 * idx as i32 + DISPLAY_SIZE . 1 as i32 / 2 ) ,
@@ -144,6 +145,10 @@ fn main() -> anyhow::Result<()> {
144145 }
145146 }
146147 DeviceEvent :: Select { data } => {
148+ selection = data;
149+ if question_id. is_empty ( ) {
150+ continue ;
151+ }
147152 // TODO: duplicate, move to display module
148153 Rectangle :: new (
149154 Point :: new ( 0 , ( DISPLAY_SIZE . 1 / 2 - 12 ) . into ( ) ) ,
@@ -152,7 +157,7 @@ fn main() -> anyhow::Result<()> {
152157 . draw_styled ( & PrimitiveStyle :: with_fill ( Rgb565 :: BLACK ) , & mut display)
153158 . unwrap ( ) ;
154159 for ( idx, option) in options. iter ( ) . enumerate ( ) {
155- let selected = idx as u8 == data ;
160+ let selected = idx as u8 == selection ;
156161 Text :: new (
157162 format ! ( "{} {}" , if selected { ">" } else { " " } , option) . as_str ( ) ,
158163 Point :: new ( 0 , 20 * idx as i32 + DISPLAY_SIZE . 1 as i32 / 2 ) ,
@@ -167,7 +172,7 @@ fn main() -> anyhow::Result<()> {
167172 }
168173 }
169174 DeviceEvent :: Enter { data } => {
170- if question_id. len ( ) == 0 {
175+ if question_id. is_empty ( ) {
171176 continue ;
172177 }
173178 // TODO: add device id (from MAC?)
0 commit comments