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.
|
/// Button released up.
|
||||||
/// ▲ * | * ▲
|
/// ▲ * | * ▲
|
||||||
ButtonReleased(PhysicalButton),
|
ButtonReleased(PhysicalButton),
|
||||||
|
|
||||||
HoldStarted,
|
HoldStarted,
|
||||||
HoldEnded,
|
HoldEnded,
|
||||||
|
HoldCanceled,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ButtonEvent {
|
impl ButtonEvent {
|
||||||
|
@ -215,19 +215,26 @@ impl ButtonContainer {
|
|||||||
self.long_pressed_timer.expire(event)
|
self.long_pressed_timer.expire(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Registering hold event.
|
/// Registering the hold event
|
||||||
pub fn hold_started(&mut self, ctx: &mut EventCtx) {
|
pub fn hold_started(&mut self, ctx: &mut EventCtx) {
|
||||||
if let ButtonType::HoldToConfirm(htc) = &mut self.button_type {
|
if let ButtonType::HoldToConfirm(htc) = &mut self.button_type {
|
||||||
htc.event(ctx, Event::Button(ButtonEvent::HoldStarted));
|
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) {
|
pub fn hold_ended(&mut self, ctx: &mut EventCtx) {
|
||||||
if let ButtonType::HoldToConfirm(htc) = &mut self.button_type {
|
if let ButtonType::HoldToConfirm(htc) = &mut self.button_type {
|
||||||
htc.event(ctx, Event::Button(ButtonEvent::HoldEnded));
|
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.
|
/// Component responsible for handling buttons.
|
||||||
@ -469,11 +476,19 @@ impl Component for ButtonController {
|
|||||||
Some(ButtonControllerMsg::Pressed(ButtonPos::Middle)),
|
Some(ButtonControllerMsg::Pressed(ButtonPos::Middle)),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
self.got_pressed(ctx, b.into());
|
// When a button gets pressed while another one is being held,
|
||||||
(
|
// cancel the hold and do not register the press.
|
||||||
ButtonState::BothDown,
|
match which_down {
|
||||||
Some(ButtonControllerMsg::Pressed(b.into())),
|
PhysicalButton::Left => {
|
||||||
)
|
self.left_btn.hold_canceled(ctx);
|
||||||
|
}
|
||||||
|
PhysicalButton::Right => {
|
||||||
|
self.right_btn.hold_canceled(ctx);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (self.state, None),
|
_ => (self.state, None),
|
||||||
|
@ -105,6 +105,9 @@ impl Component for HoldToConfirm {
|
|||||||
self.loader.start_shrinking(ctx, Instant::now());
|
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();
|
ctx.request_paint();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start_shrinking(&mut self, ctx: &mut EventCtx, now: Instant) {
|
fn start_shrinking_with_duration(
|
||||||
let mut anim = Animation::new(
|
&mut self,
|
||||||
display::LOADER_MAX,
|
ctx: &mut EventCtx,
|
||||||
display::LOADER_MIN,
|
now: Instant,
|
||||||
self.shrinking_duration,
|
duration: Duration,
|
||||||
now,
|
) {
|
||||||
);
|
let mut anim = Animation::new(display::LOADER_MAX, display::LOADER_MIN, duration, now);
|
||||||
if let State::Growing(growing) = &self.state {
|
if let State::Growing(growing) = &self.state {
|
||||||
anim.seek_to_value(display::LOADER_MAX - growing.value(now));
|
anim.seek_to_value(display::LOADER_MAX - growing.value(now));
|
||||||
}
|
}
|
||||||
@ -125,6 +125,14 @@ impl Loader {
|
|||||||
ctx.request_paint();
|
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) {
|
pub fn reset(&mut self) {
|
||||||
self.state = State::Initial;
|
self.state = State::Initial;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user