Skip to content

Commit

Permalink
fix(core/t2b1): properly stop auto-mover on edges
Browse files Browse the repository at this point in the history
fixes #3692

[no changelog]
  • Loading branch information
matejcik committed Apr 9, 2024
1 parent 1c87baf commit 519dc9f
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 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,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
}
}

Expand Down Expand Up @@ -496,8 +504,8 @@ where
match animation_direction {
ButtonPos::Left => self.move_left(ctx),
ButtonPos::Right => self.move_right(ctx),
_ => {}
}
_ => false,
};
return None;
}

Expand All @@ -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;
}
Expand All @@ -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);
}
_ => {}
}
}

Expand Down

0 comments on commit 519dc9f

Please sign in to comment.