mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-05 13:01:12 +00:00
refactor(core): introduce Simplified trait
to abstract over some common operations between models [no changelog]
This commit is contained in:
parent
047c8a881b
commit
b2649b0085
@ -8,13 +8,22 @@ use crate::ui::event::ButtonEvent;
|
|||||||
use crate::ui::event::TouchEvent;
|
use crate::ui::event::TouchEvent;
|
||||||
use crate::ui::{
|
use crate::ui::{
|
||||||
component::{Component, Event, EventCtx, Never},
|
component::{Component, Event, EventCtx, Never},
|
||||||
constant::SCREEN,
|
|
||||||
display,
|
display,
|
||||||
|
geometry::Rect,
|
||||||
};
|
};
|
||||||
use num_traits::ToPrimitive;
|
use num_traits::ToPrimitive;
|
||||||
|
|
||||||
#[cfg(feature = "backlight")]
|
pub trait SimplifiedFeatures {
|
||||||
use crate::ui::model::theme::{BACKLIGHT_DIM, BACKLIGHT_NORMAL};
|
fn fadein() {}
|
||||||
|
fn fadeout() {}
|
||||||
|
|
||||||
|
const SCREEN: Rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(all(feature = "model_tr", not(feature = "model_tt")))]
|
||||||
|
pub type ModelFeatures = crate::ui::model_tr::ModelTRFeatures;
|
||||||
|
#[cfg(feature = "model_tt")]
|
||||||
|
pub type ModelFeatures = crate::ui::model_tt::ModelTTFeatures;
|
||||||
|
|
||||||
pub trait ReturnToC {
|
pub trait ReturnToC {
|
||||||
fn return_to_c(self) -> u32;
|
fn return_to_c(self) -> u32;
|
||||||
@ -65,27 +74,17 @@ fn touch_eval() -> Option<TouchEvent> {
|
|||||||
TouchEvent::new(event_type, ex as _, ey as _).ok()
|
TouchEvent::new(event_type, ex as _, ey as _).ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fadein() {
|
|
||||||
#[cfg(feature = "backlight")]
|
|
||||||
display::fade_backlight_duration(BACKLIGHT_NORMAL, 150);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn fadeout() {
|
|
||||||
#[cfg(feature = "backlight")]
|
|
||||||
display::fade_backlight_duration(BACKLIGHT_DIM, 150);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn run<F>(frame: &mut F) -> u32
|
pub fn run<F>(frame: &mut F) -> u32
|
||||||
where
|
where
|
||||||
F: Component,
|
F: Component,
|
||||||
F::Msg: ReturnToC,
|
F::Msg: ReturnToC,
|
||||||
{
|
{
|
||||||
frame.place(SCREEN);
|
frame.place(ModelFeatures::SCREEN);
|
||||||
fadeout();
|
ModelFeatures::fadeout();
|
||||||
display::sync();
|
display::sync();
|
||||||
frame.paint();
|
frame.paint();
|
||||||
display::refresh();
|
display::refresh();
|
||||||
fadein();
|
ModelFeatures::fadein();
|
||||||
|
|
||||||
#[cfg(feature = "button")]
|
#[cfg(feature = "button")]
|
||||||
while button_eval().is_some() {}
|
while button_eval().is_some() {}
|
||||||
@ -116,14 +115,14 @@ pub fn show<F>(frame: &mut F, fading: bool)
|
|||||||
where
|
where
|
||||||
F: Component,
|
F: Component,
|
||||||
{
|
{
|
||||||
frame.place(SCREEN);
|
frame.place(ModelFeatures::SCREEN);
|
||||||
if fading {
|
if fading {
|
||||||
fadeout()
|
ModelFeatures::fadeout()
|
||||||
};
|
};
|
||||||
display::sync();
|
display::sync();
|
||||||
frame.paint();
|
frame.paint();
|
||||||
display::refresh();
|
display::refresh();
|
||||||
if fading {
|
if fading {
|
||||||
fadein()
|
ModelFeatures::fadein()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -18,14 +18,3 @@ pub mod layout;
|
|||||||
pub mod model_tr;
|
pub mod model_tr;
|
||||||
#[cfg(feature = "model_tt")]
|
#[cfg(feature = "model_tt")]
|
||||||
pub mod model_tt;
|
pub mod model_tt;
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
feature = "model_t1",
|
|
||||||
not(feature = "model_tr"),
|
|
||||||
not(feature = "model_tt")
|
|
||||||
))]
|
|
||||||
pub use model_t1 as model;
|
|
||||||
#[cfg(all(feature = "model_tr", not(feature = "model_tt")))]
|
|
||||||
pub use model_tr as model;
|
|
||||||
#[cfg(feature = "model_tt")]
|
|
||||||
pub use model_tt as model;
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use super::{geometry::Rect, layout::simplified::SimplifiedFeatures};
|
||||||
|
|
||||||
#[cfg(feature = "bootloader")]
|
#[cfg(feature = "bootloader")]
|
||||||
pub mod bootloader;
|
pub mod bootloader;
|
||||||
pub mod common_messages;
|
pub mod common_messages;
|
||||||
@ -7,3 +9,9 @@ pub mod constant;
|
|||||||
pub mod layout;
|
pub mod layout;
|
||||||
pub mod screens;
|
pub mod screens;
|
||||||
pub mod theme;
|
pub mod theme;
|
||||||
|
|
||||||
|
pub struct ModelTRFeatures {}
|
||||||
|
|
||||||
|
impl SimplifiedFeatures for ModelTRFeatures {
|
||||||
|
const SCREEN: Rect = constant::SCREEN;
|
||||||
|
}
|
||||||
|
@ -5,9 +5,9 @@ use crate::{
|
|||||||
trezorhal::secbool::secbool,
|
trezorhal::secbool::secbool,
|
||||||
ui::{
|
ui::{
|
||||||
component::{connect::Connect, Label},
|
component::{connect::Connect, Label},
|
||||||
constant::HEIGHT,
|
|
||||||
display::{self, Color, Font, Icon},
|
display::{self, Color, Font, Icon},
|
||||||
geometry::Point,
|
geometry::{Point, Rect},
|
||||||
|
layout::simplified::{run, show, SimplifiedFeatures as _},
|
||||||
util::{from_c_array, from_c_str},
|
util::{from_c_array, from_c_str},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -18,7 +18,6 @@ use super::{
|
|||||||
bl_confirm::{Confirm, ConfirmTitle},
|
bl_confirm::{Confirm, ConfirmTitle},
|
||||||
Button, ResultScreen, WelcomeScreen,
|
Button, ResultScreen, WelcomeScreen,
|
||||||
},
|
},
|
||||||
constant,
|
|
||||||
theme::{
|
theme::{
|
||||||
bootloader::{
|
bootloader::{
|
||||||
button_bld, button_bld_menu, button_confirm, button_wipe_cancel, button_wipe_confirm,
|
button_bld, button_bld_menu, button_confirm, button_wipe_cancel, button_wipe_confirm,
|
||||||
@ -28,9 +27,9 @@ use super::{
|
|||||||
},
|
},
|
||||||
BACKLIGHT_NORMAL, BLACK, FG, WHITE,
|
BACKLIGHT_NORMAL, BLACK, FG, WHITE,
|
||||||
},
|
},
|
||||||
|
ModelTTFeatures,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::ui::layout::simplified::{fadein, fadeout, run, show};
|
|
||||||
use intro::Intro;
|
use intro::Intro;
|
||||||
use menu::Menu;
|
use menu::Menu;
|
||||||
|
|
||||||
@ -42,6 +41,8 @@ pub type BootloaderString = String<128>;
|
|||||||
|
|
||||||
const RECONNECT_MESSAGE: &str = "PLEASE RECONNECT\nTHE DEVICE";
|
const RECONNECT_MESSAGE: &str = "PLEASE RECONNECT\nTHE DEVICE";
|
||||||
|
|
||||||
|
const SCREEN: Rect = ModelTTFeatures::SCREEN;
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
extern "C" fn screen_install_confirm(
|
extern "C" fn screen_install_confirm(
|
||||||
vendor_str: *const cty::c_char,
|
vendor_str: *const cty::c_char,
|
||||||
@ -165,12 +166,12 @@ fn screen_progress(
|
|||||||
icon: Option<(Icon, Color)>,
|
icon: Option<(Icon, Color)>,
|
||||||
) {
|
) {
|
||||||
if initialize {
|
if initialize {
|
||||||
fadeout();
|
ModelTTFeatures::fadeout();
|
||||||
display::rect_fill(constant::screen(), bg_color);
|
display::rect_fill(SCREEN, bg_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
display::text_center(
|
display::text_center(
|
||||||
Point::new(constant::WIDTH / 2, HEIGHT - 45),
|
Point::new(SCREEN.width() / 2, SCREEN.height() - 45),
|
||||||
text,
|
text,
|
||||||
Font::NORMAL,
|
Font::NORMAL,
|
||||||
fg_color,
|
fg_color,
|
||||||
@ -179,7 +180,7 @@ fn screen_progress(
|
|||||||
display::loader(progress, -20, fg_color, bg_color, icon);
|
display::loader(progress, -20, fg_color, bg_color, icon);
|
||||||
display::refresh();
|
display::refresh();
|
||||||
if initialize {
|
if initialize {
|
||||||
fadein();
|
ModelTTFeatures::fadein();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,16 +245,16 @@ extern "C" fn screen_wipe_fail() {
|
|||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
extern "C" fn screen_boot_empty(fading: bool) {
|
extern "C" fn screen_boot_empty(fading: bool) {
|
||||||
if fading {
|
if fading {
|
||||||
fadeout();
|
ModelTTFeatures::fadeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
display::rect_fill(constant::screen(), BLACK);
|
display::rect_fill(SCREEN, BLACK);
|
||||||
|
|
||||||
let mut frame = WelcomeScreen::new(true);
|
let mut frame = WelcomeScreen::new(true);
|
||||||
show(&mut frame, false);
|
show(&mut frame, false);
|
||||||
|
|
||||||
if fading {
|
if fading {
|
||||||
fadein();
|
ModelTTFeatures::fadein();
|
||||||
} else {
|
} else {
|
||||||
display::set_backlight(BACKLIGHT_NORMAL);
|
display::set_backlight(BACKLIGHT_NORMAL);
|
||||||
}
|
}
|
||||||
@ -328,7 +329,7 @@ extern "C" fn screen_welcome() {
|
|||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
extern "C" fn bld_continue_label(bg_color: cty::uint16_t) {
|
extern "C" fn bld_continue_label(bg_color: cty::uint16_t) {
|
||||||
display::text_center(
|
display::text_center(
|
||||||
Point::new(constant::WIDTH / 2, HEIGHT - 5),
|
Point::new(SCREEN.width() / 2, SCREEN.height() - 5),
|
||||||
"click to continue ...",
|
"click to continue ...",
|
||||||
Font::NORMAL,
|
Font::NORMAL,
|
||||||
WHITE,
|
WHITE,
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use super::{geometry::Rect, layout::simplified::SimplifiedFeatures};
|
||||||
|
|
||||||
#[cfg(feature = "bootloader")]
|
#[cfg(feature = "bootloader")]
|
||||||
pub mod bootloader;
|
pub mod bootloader;
|
||||||
pub mod component;
|
pub mod component;
|
||||||
@ -7,3 +9,19 @@ pub mod theme;
|
|||||||
#[cfg(feature = "micropython")]
|
#[cfg(feature = "micropython")]
|
||||||
pub mod layout;
|
pub mod layout;
|
||||||
pub mod screens;
|
pub mod screens;
|
||||||
|
|
||||||
|
pub struct ModelTTFeatures {}
|
||||||
|
|
||||||
|
impl SimplifiedFeatures for ModelTTFeatures {
|
||||||
|
fn fadein() {
|
||||||
|
#[cfg(feature = "backlight")]
|
||||||
|
crate::ui::display::fade_backlight_duration(theme::BACKLIGHT_NORMAL, 150);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fadeout() {
|
||||||
|
#[cfg(feature = "backlight")]
|
||||||
|
crate::ui::display::fade_backlight_duration(theme::BACKLIGHT_DIM, 150);
|
||||||
|
}
|
||||||
|
|
||||||
|
const SCREEN: Rect = constant::SCREEN;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user