Skip to content

Commit

Permalink
fix(core) Fix auto-mover hitting wall scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
bieleluk committed Nov 27, 2024
1 parent c595946 commit 7e9aba6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions core/.changelog.d/3692.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix auto-mover hitting wall scenario
25 changes: 19 additions & 6 deletions core/embed/rust/src/ui/model_tr/component/input_methods/choice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,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() {
Expand Down Expand Up @@ -509,10 +518,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;
}
Expand All @@ -535,8 +548,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);
}
}
Expand Down

0 comments on commit 7e9aba6

Please sign in to comment.