From 88a76b3063dc41a4774f5672cdb29c1ace248c77 Mon Sep 17 00:00:00 2001 From: matejcik Date: Tue, 9 Apr 2024 11:12:54 +0200 Subject: [PATCH] fix(core/t2b1): properly stop auto-mover on edges fixes #3692 [no changelog] --- .../component/input_methods/choice.rs | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 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 4dc9a9d93..ca917c4f1 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 @@ -425,24 +425,32 @@ where } /// Go to the choice visually on the left. - fn move_left(&mut self, ctx: &mut EventCtx) { + fn move_left(&mut self, ctx: &mut EventCtx) -> bool { if self.has_previous_choice() { self.decrease_page_counter(); self.update(ctx); + true } else if self.is_carousel { self.page_counter_to_max(); self.update(ctx); + true + } else { + false } } /// Go to the choice visually on the right. - fn move_right(&mut self, ctx: &mut EventCtx) { + fn move_right(&mut self, ctx: &mut EventCtx) -> bool { if self.has_next_choice() { self.increase_page_counter(); self.update(ctx); + true } else if self.is_carousel { self.page_counter_to_zero(); self.update(ctx); + true + } else { + false } } @@ -496,8 +504,8 @@ where match animation_direction { ButtonPos::Left => self.move_left(ctx), ButtonPos::Right => self.move_right(ctx), - _ => {} - } + _ => false, + }; return None; } @@ -508,10 +516,13 @@ 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 { + let moved = match auto_move_direction { ButtonPos::Left => self.move_left(ctx), ButtonPos::Right => self.move_right(ctx), - _ => {} + _ => false, + }; + if !moved { + self.holding_mover.stop_moving(); } return None; } @@ -535,8 +546,14 @@ 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) { - self.holding_mover.start_moving(ctx, pos); + match pos { + ButtonPos::Left if self.has_previous_choice() || self.is_carousel => { + self.holding_mover.start_moving(ctx, ButtonPos::Left); + } + ButtonPos::Right if self.has_next_choice() || self.is_carousel => { + self.holding_mover.start_moving(ctx, ButtonPos::Right); + } + _ => {} } }