From caa5ed22e006005853d2a255057648062842767e Mon Sep 17 00:00:00 2001 From: Lukas Bielesch Date: Tue, 27 Aug 2024 15:05:44 +0200 Subject: [PATCH] fix(core) Fix auto-mover hitting wall scenario --- .../component/input_methods/choice.rs | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/core/embed/rust/src/ui/model_tr/component/input_methods/choice.rs b/core/embed/rust/src/ui/model_tr/component/input_methods/choice.rs index 4cd681b775..47ec573ea5 100644 --- a/core/embed/rust/src/ui/model_tr/component/input_methods/choice.rs +++ b/core/embed/rust/src/ui/model_tr/component/input_methods/choice.rs @@ -557,6 +557,15 @@ where &self.choices } + /// Check possibility of going left/right. + fn can_move(&self, button: ButtonPos) -> bool { + match button { + ButtonPos::Left => self.has_previous_choice() || self.is_carousel, + ButtonPos::Right => self.has_next_choice() || self.is_carousel, + _ => false, + } + } + /// Go to the choice visually on the left. fn move_left(&mut self, ctx: &mut EventCtx) { if self.has_previous_choice() { @@ -641,10 +650,14 @@ where // Possible automatic movement when user is holding left or right button. if let Some(auto_move_direction) = self.holding_mover.event(ctx, event) { - match auto_move_direction { - ButtonPos::Left => self.move_left(ctx), - ButtonPos::Right => self.move_right(ctx), - _ => {} + if self.can_move(auto_move_direction) { + match auto_move_direction { + ButtonPos::Left => self.move_left(ctx), + ButtonPos::Right => self.move_right(ctx), + _ => {} + } + } else { + self.holding_mover.stop_moving(); } return None; } @@ -667,8 +680,8 @@ where } } } else if let Some(ButtonControllerMsg::Pressed(pos)) = button_event { - // Starting the movement when left/right button is pressed. - if matches!(pos, ButtonPos::Left | ButtonPos::Right) { + // Starting the movement when required movement can be done. + if self.can_move(pos) { self.holding_mover.start_moving(ctx, pos); } }