mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-05-23 17:28:46 +00:00
fix(core/rust): correctly extend SwipeAttach animation duration
so that it covers the interval from the Attach event until timer running out. Without this change, it is possible to slip in a TouchStart event before the animation timer has had a chance to start, and lose the matching TouchEnd.
This commit is contained in:
parent
169d25bd9e
commit
f59deebfba
@ -17,7 +17,11 @@ use crate::{
|
|||||||
|
|
||||||
#[derive(Default, Clone)]
|
#[derive(Default, Clone)]
|
||||||
pub struct SwipeAttachAnimation {
|
pub struct SwipeAttachAnimation {
|
||||||
pub timer: Stopwatch,
|
/// Animation timer for time elapsed since the first animation frame tick
|
||||||
|
/// after the attach event. Stopped state indicates animation initial
|
||||||
|
/// state; after the animation duration elapses, the stopwatch continues
|
||||||
|
/// to run.
|
||||||
|
timer: Stopwatch,
|
||||||
pub attach_type: Option<AttachType>,
|
pub attach_type: Option<AttachType>,
|
||||||
pub show_attach_anim: bool,
|
pub show_attach_anim: bool,
|
||||||
}
|
}
|
||||||
@ -33,12 +37,19 @@ impl SwipeAttachAnimation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Checks if the attach animation is active.
|
||||||
|
///
|
||||||
|
/// The animation is considered "active" from attach event (timer stopped),
|
||||||
|
/// through the first animation frame (timer started), until the timer
|
||||||
|
/// exceeds animation duration.
|
||||||
pub fn is_active(&self) -> bool {
|
pub fn is_active(&self) -> bool {
|
||||||
if animation_disabled() {
|
if animation_disabled() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.timer
|
!self.timer.is_running()
|
||||||
|
|| self
|
||||||
|
.timer
|
||||||
.is_running_within(Duration::from_millis(Self::DURATION_MS))
|
.is_running_within(Duration::from_millis(Self::DURATION_MS))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,14 +104,19 @@ impl SwipeAttachAnimation {
|
|||||||
u8::lerp(0, 255, value.eval(t))
|
u8::lerp(0, 255, value.eval(t))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start(&mut self) {
|
/// Reset the animation to initial state.
|
||||||
self.timer.start();
|
fn reset(&mut self) {
|
||||||
}
|
|
||||||
|
|
||||||
pub fn reset(&mut self) {
|
|
||||||
self.timer = Stopwatch::new_stopped();
|
self.timer = Stopwatch::new_stopped();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Lazily start the animation.
|
||||||
|
///
|
||||||
|
/// Attach event will reset but not start the timer; the timer is started by
|
||||||
|
/// the first animation frame, to avoid any discontinuity in case Attach
|
||||||
|
/// precedes the first animation frame by a noticeable interval.
|
||||||
|
///
|
||||||
|
/// While the animation is active, that is, from the first Attach to until
|
||||||
|
/// the timer runs out, no touch events are allowed through.
|
||||||
pub fn lazy_start(
|
pub fn lazy_start(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &mut EventCtx,
|
ctx: &mut EventCtx,
|
||||||
|
Loading…
Reference in New Issue
Block a user