mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-18 03:10:58 +00:00
fix(core/ui): make button press cancel current hold
This commit is contained in:
parent
38e362cd5b
commit
30e88f4641
1
core/.changelog.d/3772.fixed
Normal file
1
core/.changelog.d/3772.fixed
Normal file
@ -0,0 +1 @@
|
||||
[T3B1] Fix behavior of a button press during "hold to confirm".
|
@ -12,8 +12,10 @@ pub enum ButtonEvent {
|
||||
/// Button released up.
|
||||
/// ▲ * | * ▲
|
||||
ButtonReleased(PhysicalButton),
|
||||
|
||||
HoldStarted,
|
||||
HoldEnded,
|
||||
HoldCanceled,
|
||||
}
|
||||
|
||||
impl ButtonEvent {
|
||||
|
@ -215,19 +215,26 @@ impl ButtonContainer {
|
||||
self.long_pressed_timer.expire(event)
|
||||
}
|
||||
|
||||
/// Registering hold event.
|
||||
/// Registering the hold event
|
||||
pub fn hold_started(&mut self, ctx: &mut EventCtx) {
|
||||
if let ButtonType::HoldToConfirm(htc) = &mut self.button_type {
|
||||
htc.event(ctx, Event::Button(ButtonEvent::HoldStarted));
|
||||
}
|
||||
}
|
||||
|
||||
/// Cancelling hold event.
|
||||
/// Ending the hold event by releasing the button held
|
||||
pub fn hold_ended(&mut self, ctx: &mut EventCtx) {
|
||||
if let ButtonType::HoldToConfirm(htc) = &mut self.button_type {
|
||||
htc.event(ctx, Event::Button(ButtonEvent::HoldEnded));
|
||||
}
|
||||
}
|
||||
|
||||
/// Canceling the hold event
|
||||
pub fn hold_canceled(&mut self, ctx: &mut EventCtx) {
|
||||
if let ButtonType::HoldToConfirm(htc) = &mut self.button_type {
|
||||
htc.event(ctx, Event::Button(ButtonEvent::HoldCanceled));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Component responsible for handling buttons.
|
||||
@ -469,11 +476,19 @@ impl Component for ButtonController {
|
||||
Some(ButtonControllerMsg::Pressed(ButtonPos::Middle)),
|
||||
)
|
||||
} else {
|
||||
self.got_pressed(ctx, b.into());
|
||||
(
|
||||
ButtonState::BothDown,
|
||||
Some(ButtonControllerMsg::Pressed(b.into())),
|
||||
)
|
||||
// When a button gets pressed while another one is being held,
|
||||
// cancel the hold and do not register the press.
|
||||
match which_down {
|
||||
PhysicalButton::Left => {
|
||||
self.left_btn.hold_canceled(ctx);
|
||||
}
|
||||
PhysicalButton::Right => {
|
||||
self.right_btn.hold_canceled(ctx);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
return None;
|
||||
}
|
||||
}
|
||||
_ => (self.state, None),
|
||||
|
@ -105,6 +105,9 @@ impl Component for HoldToConfirm {
|
||||
self.loader.start_shrinking(ctx, Instant::now());
|
||||
}
|
||||
}
|
||||
Event::Button(ButtonEvent::HoldCanceled) => {
|
||||
self.loader.shrink_completely(ctx, Instant::now());
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
|
||||
|
@ -107,13 +107,13 @@ impl Loader {
|
||||
ctx.request_paint();
|
||||
}
|
||||
|
||||
pub fn start_shrinking(&mut self, ctx: &mut EventCtx, now: Instant) {
|
||||
let mut anim = Animation::new(
|
||||
display::LOADER_MAX,
|
||||
display::LOADER_MIN,
|
||||
self.shrinking_duration,
|
||||
now,
|
||||
);
|
||||
fn start_shrinking_with_duration(
|
||||
&mut self,
|
||||
ctx: &mut EventCtx,
|
||||
now: Instant,
|
||||
duration: Duration,
|
||||
) {
|
||||
let mut anim = Animation::new(display::LOADER_MAX, display::LOADER_MIN, duration, now);
|
||||
if let State::Growing(growing) = &self.state {
|
||||
anim.seek_to_value(display::LOADER_MAX - growing.value(now));
|
||||
}
|
||||
@ -125,6 +125,14 @@ impl Loader {
|
||||
ctx.request_paint();
|
||||
}
|
||||
|
||||
pub fn start_shrinking(&mut self, ctx: &mut EventCtx, now: Instant) {
|
||||
self.start_shrinking_with_duration(ctx, now, self.shrinking_duration);
|
||||
}
|
||||
|
||||
pub fn shrink_completely(&mut self, ctx: &mut EventCtx, now: Instant) {
|
||||
self.start_shrinking_with_duration(ctx, now, Duration::from_millis(0));
|
||||
}
|
||||
|
||||
pub fn reset(&mut self) {
|
||||
self.state = State::Initial;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user