mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-03-27 13:35:44 +00:00
fix(core/mercury): fix swipe animation when repeatedly touching display while the transition is already in effect
This commit is contained in:
parent
56385f79c7
commit
e5fc1e1d42
@ -3,6 +3,7 @@ use crate::{
|
|||||||
ui::{
|
ui::{
|
||||||
animation::Animation,
|
animation::Animation,
|
||||||
component::{Event, EventCtx, SwipeDirection},
|
component::{Event, EventCtx, SwipeDirection},
|
||||||
|
constant::screen,
|
||||||
event::TouchEvent,
|
event::TouchEvent,
|
||||||
geometry::{Offset, Point},
|
geometry::{Offset, Point},
|
||||||
util::animation_disabled,
|
util::animation_disabled,
|
||||||
@ -200,6 +201,46 @@ impl SwipeDetect {
|
|||||||
((val as f32 / Self::DISTANCE as f32) * Self::PROGRESS_MAX as f32) as u16
|
((val as f32 / Self::DISTANCE as f32) * Self::PROGRESS_MAX as f32) as u16
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn eval_anim_frame(&mut self, ctx: &mut EventCtx) -> Option<SwipeDetectMsg> {
|
||||||
|
if let Some(locked) = self.locked {
|
||||||
|
let mut finish = false;
|
||||||
|
let res = if let Some(animation) = &self.final_animation {
|
||||||
|
if animation.finished(Instant::now()) {
|
||||||
|
finish = true;
|
||||||
|
if animation.to != 0 {
|
||||||
|
Some(SwipeDetectMsg::Trigger(locked))
|
||||||
|
} else {
|
||||||
|
Some(SwipeDetectMsg::Move(locked, 0))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ctx.request_anim_frame();
|
||||||
|
ctx.request_paint();
|
||||||
|
if animation_disabled() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(SwipeDetectMsg::Move(
|
||||||
|
locked,
|
||||||
|
animation.value(Instant::now()).max(0) as u16,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
if finish {
|
||||||
|
self.locked = None;
|
||||||
|
ctx.request_anim_frame();
|
||||||
|
ctx.request_paint();
|
||||||
|
self.final_animation = None;
|
||||||
|
self.moved = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
pub fn trigger(&mut self, ctx: &mut EventCtx, dir: SwipeDirection, config: SwipeConfig) {
|
pub fn trigger(&mut self, ctx: &mut EventCtx, dir: SwipeDirection, config: SwipeConfig) {
|
||||||
ctx.request_anim_frame();
|
ctx.request_anim_frame();
|
||||||
ctx.request_paint();
|
ctx.request_paint();
|
||||||
@ -232,8 +273,12 @@ impl SwipeDetect {
|
|||||||
) -> Option<SwipeDetectMsg> {
|
) -> Option<SwipeDetectMsg> {
|
||||||
match (event, self.origin) {
|
match (event, self.origin) {
|
||||||
(Event::Touch(TouchEvent::TouchStart(pos)), _) => {
|
(Event::Touch(TouchEvent::TouchStart(pos)), _) => {
|
||||||
// Mark the starting position of this touch.
|
if self.final_animation.is_none() {
|
||||||
self.origin.replace(pos);
|
// Mark the starting position of this touch.
|
||||||
|
self.origin.replace(pos);
|
||||||
|
} else {
|
||||||
|
return self.eval_anim_frame(ctx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(Event::Touch(TouchEvent::TouchMove(pos)), Some(origin)) => {
|
(Event::Touch(TouchEvent::TouchMove(pos)), Some(origin)) => {
|
||||||
if self.final_animation.is_none() {
|
if self.final_animation.is_none() {
|
||||||
@ -261,8 +306,6 @@ impl SwipeDetect {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Todo trigger an action if distance is met
|
|
||||||
|
|
||||||
if let Some(SwipeDetectMsg::Move(_, progress)) = res {
|
if let Some(SwipeDetectMsg::Move(_, progress)) = res {
|
||||||
self.moved = progress;
|
self.moved = progress;
|
||||||
}
|
}
|
||||||
@ -272,6 +315,8 @@ impl SwipeDetect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
} else {
|
||||||
|
return self.eval_anim_frame(ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(Event::Touch(TouchEvent::TouchEnd(pos)), Some(origin)) => {
|
(Event::Touch(TouchEvent::TouchEnd(pos)), Some(origin)) => {
|
||||||
@ -326,45 +371,12 @@ impl SwipeDetect {
|
|||||||
return Some(SwipeDetectMsg::Trigger(locked));
|
return Some(SwipeDetectMsg::Trigger(locked));
|
||||||
}
|
}
|
||||||
return None;
|
return None;
|
||||||
|
} else {
|
||||||
|
return self.eval_anim_frame(ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(Event::Timer(EventCtx::ANIM_FRAME_TIMER), _) => {
|
(Event::Timer(EventCtx::ANIM_FRAME_TIMER), _) => {
|
||||||
if let Some(locked) = self.locked {
|
return self.eval_anim_frame(ctx);
|
||||||
let mut finish = false;
|
|
||||||
let res = if let Some(animation) = &self.final_animation {
|
|
||||||
if animation.finished(Instant::now()) {
|
|
||||||
finish = true;
|
|
||||||
if animation.to != 0 {
|
|
||||||
Some(SwipeDetectMsg::Trigger(locked))
|
|
||||||
} else {
|
|
||||||
Some(SwipeDetectMsg::Move(locked, 0))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ctx.request_anim_frame();
|
|
||||||
ctx.request_paint();
|
|
||||||
if animation_disabled() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(SwipeDetectMsg::Move(
|
|
||||||
locked,
|
|
||||||
animation.value(Instant::now()).max(0) as u16,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
if finish {
|
|
||||||
self.locked = None;
|
|
||||||
ctx.request_anim_frame();
|
|
||||||
ctx.request_paint();
|
|
||||||
self.final_animation = None;
|
|
||||||
self.moved = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
|
Loading…
Reference in New Issue
Block a user