mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-24 14:20:57 +00:00
refactor(core/rust): use SwipeEvent in place of SwipeDetectMsg
This commit is contained in:
parent
9f083c1865
commit
c0bb55258b
@ -46,7 +46,7 @@ pub use qr_code::Qr;
|
|||||||
#[cfg(feature = "touch")]
|
#[cfg(feature = "touch")]
|
||||||
pub use swipe::Swipe;
|
pub use swipe::Swipe;
|
||||||
#[cfg(feature = "touch")]
|
#[cfg(feature = "touch")]
|
||||||
pub use swipe_detect::{SwipeDetect, SwipeDetectMsg};
|
pub use swipe_detect::SwipeDetect;
|
||||||
pub use text::{
|
pub use text::{
|
||||||
formatted::FormattedText,
|
formatted::FormattedText,
|
||||||
layout::{LineBreaking, PageBreaking, TextLayout},
|
layout::{LineBreaking, PageBreaking, TextLayout},
|
||||||
|
@ -4,7 +4,7 @@ use crate::{
|
|||||||
animation::Animation,
|
animation::Animation,
|
||||||
component::{Event, EventCtx},
|
component::{Event, EventCtx},
|
||||||
constant::screen,
|
constant::screen,
|
||||||
event::TouchEvent,
|
event::{SwipeEvent, TouchEvent},
|
||||||
geometry::{Axis, Direction, Offset, Point},
|
geometry::{Axis, Direction, Offset, Point},
|
||||||
util::animation_disabled,
|
util::animation_disabled,
|
||||||
},
|
},
|
||||||
@ -168,18 +168,11 @@ impl core::ops::IndexMut<Direction> for SwipeConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Eq, PartialEq)]
|
|
||||||
pub enum SwipeDetectMsg {
|
|
||||||
Start(Direction),
|
|
||||||
Move(Direction, u16),
|
|
||||||
Trigger(Direction),
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct SwipeDetect {
|
pub struct SwipeDetect {
|
||||||
origin: Option<Point>,
|
origin: Option<Point>,
|
||||||
locked: Option<Direction>,
|
locked: Option<Direction>,
|
||||||
final_animation: Option<Animation<i16>>,
|
final_animation: Option<Animation<i16>>,
|
||||||
moved: u16,
|
moved: i16,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SwipeDetect {
|
impl SwipeDetect {
|
||||||
@ -237,20 +230,20 @@ impl SwipeDetect {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn progress(&self, val: u16) -> u16 {
|
fn progress(&self, val: u16) -> i16 {
|
||||||
((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 i16
|
||||||
}
|
}
|
||||||
|
|
||||||
fn eval_anim_frame(&mut self, ctx: &mut EventCtx) -> Option<SwipeDetectMsg> {
|
fn eval_anim_frame(&mut self, ctx: &mut EventCtx) -> Option<SwipeEvent> {
|
||||||
if let Some(locked) = self.locked {
|
if let Some(locked) = self.locked {
|
||||||
let mut finish = false;
|
let mut finish = false;
|
||||||
let res = if let Some(animation) = &self.final_animation {
|
let res = if let Some(animation) = &self.final_animation {
|
||||||
if animation.finished(Instant::now()) {
|
if animation.finished(Instant::now()) {
|
||||||
finish = true;
|
finish = true;
|
||||||
if animation.to != 0 {
|
if animation.to != 0 {
|
||||||
Some(SwipeDetectMsg::Trigger(locked))
|
Some(SwipeEvent::End(locked))
|
||||||
} else {
|
} else {
|
||||||
Some(SwipeDetectMsg::Move(locked, 0))
|
Some(SwipeEvent::Move(locked, 0))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.request_anim_frame();
|
ctx.request_anim_frame();
|
||||||
@ -258,9 +251,9 @@ impl SwipeDetect {
|
|||||||
if animation_disabled() {
|
if animation_disabled() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(SwipeDetectMsg::Move(
|
Some(SwipeEvent::Move(
|
||||||
locked,
|
locked,
|
||||||
animation.value(Instant::now()).max(0) as u16,
|
animation.value(Instant::now()).max(0),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -310,7 +303,7 @@ impl SwipeDetect {
|
|||||||
ctx: &mut EventCtx,
|
ctx: &mut EventCtx,
|
||||||
event: Event,
|
event: Event,
|
||||||
config: SwipeConfig,
|
config: SwipeConfig,
|
||||||
) -> Option<SwipeDetectMsg> {
|
) -> Option<SwipeEvent> {
|
||||||
match (event, self.origin) {
|
match (event, self.origin) {
|
||||||
(Event::Touch(TouchEvent::TouchStart(pos)), _) => {
|
(Event::Touch(TouchEvent::TouchStart(pos)), _) => {
|
||||||
if self.final_animation.is_none() {
|
if self.final_animation.is_none() {
|
||||||
@ -330,7 +323,7 @@ impl SwipeDetect {
|
|||||||
Some(locked) => {
|
Some(locked) => {
|
||||||
// advance in locked direction only
|
// advance in locked direction only
|
||||||
let moved = config.progress(locked, ofs, self.min_lock(locked));
|
let moved = config.progress(locked, ofs, self.min_lock(locked));
|
||||||
Some(SwipeDetectMsg::Move(locked, self.progress(moved)))
|
Some(SwipeEvent::Move(locked, self.progress(moved)))
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let mut res = None;
|
let mut res = None;
|
||||||
@ -338,7 +331,7 @@ impl SwipeDetect {
|
|||||||
let progress = config.progress(dir, ofs, self.min_lock(dir));
|
let progress = config.progress(dir, ofs, self.min_lock(dir));
|
||||||
if progress > 0 && self.is_lockable(dir) {
|
if progress > 0 && self.is_lockable(dir) {
|
||||||
self.locked = Some(dir);
|
self.locked = Some(dir);
|
||||||
res = Some(SwipeDetectMsg::Start(dir));
|
res = Some(SwipeEvent::Start(dir));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -346,7 +339,7 @@ impl SwipeDetect {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(SwipeDetectMsg::Move(_, progress)) = res {
|
if let Some(SwipeEvent::Move(_, progress)) = res {
|
||||||
self.moved = progress;
|
self.moved = progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -400,7 +393,7 @@ impl SwipeDetect {
|
|||||||
|
|
||||||
let duration = ((duration.to_millis() as f32 * ratio) as u32).max(0);
|
let duration = ((duration.to_millis() as f32 * ratio) as u32).max(0);
|
||||||
self.final_animation = Some(Animation::new(
|
self.final_animation = Some(Animation::new(
|
||||||
self.moved as i16,
|
self.moved,
|
||||||
final_value,
|
final_value,
|
||||||
Duration::from_millis(duration),
|
Duration::from_millis(duration),
|
||||||
Instant::now(),
|
Instant::now(),
|
||||||
@ -410,7 +403,7 @@ impl SwipeDetect {
|
|||||||
self.final_animation = None;
|
self.final_animation = None;
|
||||||
self.moved = 0;
|
self.moved = 0;
|
||||||
self.locked = None;
|
self.locked = None;
|
||||||
return Some(SwipeDetectMsg::Trigger(locked));
|
return Some(SwipeEvent::End(locked));
|
||||||
}
|
}
|
||||||
return None;
|
return None;
|
||||||
} else {
|
} else {
|
||||||
|
@ -8,7 +8,7 @@ use crate::{
|
|||||||
ui::{
|
ui::{
|
||||||
component::{
|
component::{
|
||||||
base::AttachType::{self, Swipe},
|
base::AttachType::{self, Swipe},
|
||||||
Component, Event, EventCtx, FlowMsg, SwipeDetect, SwipeDetectMsg,
|
Component, Event, EventCtx, FlowMsg, SwipeDetect,
|
||||||
},
|
},
|
||||||
display::Color,
|
display::Color,
|
||||||
event::{SwipeEvent, TouchEvent},
|
event::{SwipeEvent, TouchEvent},
|
||||||
@ -202,7 +202,7 @@ impl SwipeFlow {
|
|||||||
self.internal_pages = page.get_internal_page_count() as u16;
|
self.internal_pages = page.get_internal_page_count() as u16;
|
||||||
|
|
||||||
match self.swipe.event(ctx, event, config) {
|
match self.swipe.event(ctx, event, config) {
|
||||||
Some(SwipeDetectMsg::Trigger(dir)) => {
|
Some(SwipeEvent::End(dir)) => {
|
||||||
if let Some(override_decision) = self.decision_override.take() {
|
if let Some(override_decision) = self.decision_override.take() {
|
||||||
decision = override_decision;
|
decision = override_decision;
|
||||||
} else {
|
} else {
|
||||||
@ -220,10 +220,7 @@ impl SwipeFlow {
|
|||||||
}
|
}
|
||||||
Event::Swipe(SwipeEvent::End(dir))
|
Event::Swipe(SwipeEvent::End(dir))
|
||||||
}
|
}
|
||||||
Some(SwipeDetectMsg::Move(dir, progress)) => {
|
Some(e) => Event::Swipe(e),
|
||||||
Event::Swipe(SwipeEvent::Move(dir, progress as i16))
|
|
||||||
}
|
|
||||||
Some(SwipeDetectMsg::Start(dir)) => Event::Swipe(SwipeEvent::Start(dir)),
|
|
||||||
None => event,
|
None => event,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::ui::{
|
use crate::ui::{
|
||||||
component::{base::AttachType, Component, Event, EventCtx, SwipeDetect, SwipeDetectMsg},
|
component::{base::AttachType, Component, Event, EventCtx, SwipeDetect},
|
||||||
event::{SwipeEvent, TouchEvent},
|
event::SwipeEvent,
|
||||||
flow::Swipable,
|
flow::Swipable,
|
||||||
geometry::Rect,
|
geometry::Rect,
|
||||||
shape::Renderer,
|
shape::Renderer,
|
||||||
@ -49,14 +49,11 @@ impl<T: Swipable + Component> Component for SwipeUpScreen<T> {
|
|||||||
.swipe
|
.swipe
|
||||||
.event(ctx, event, self.content.get_swipe_config())
|
.event(ctx, event, self.content.get_swipe_config())
|
||||||
{
|
{
|
||||||
Some(SwipeDetectMsg::Trigger(dir)) => {
|
Some(SwipeEvent::End(dir)) => {
|
||||||
ctx.set_transition_out(AttachType::Swipe(dir));
|
ctx.set_transition_out(AttachType::Swipe(dir));
|
||||||
return Some(SwipeUpScreenMsg::Swiped);
|
return Some(SwipeUpScreenMsg::Swiped);
|
||||||
}
|
}
|
||||||
Some(SwipeDetectMsg::Move(dir, progress)) => {
|
Some(e) => Event::Swipe(e),
|
||||||
Event::Swipe(SwipeEvent::Move(dir, progress as i16))
|
|
||||||
}
|
|
||||||
Some(SwipeDetectMsg::Start(dir)) => Event::Swipe(SwipeEvent::Start(dir)),
|
|
||||||
_ => event,
|
_ => event,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user