refactor(core): introduce Simplified trait

to abstract over some common operations between models

[no changelog]
pull/3659/head
matejcik 1 month ago committed by matejcik
parent 047c8a881b
commit b2649b0085

@ -8,13 +8,22 @@ use crate::ui::event::ButtonEvent;
use crate::ui::event::TouchEvent;
use crate::ui::{
component::{Component, Event, EventCtx, Never},
constant::SCREEN,
display,
geometry::Rect,
};
use num_traits::ToPrimitive;
#[cfg(feature = "backlight")]
use crate::ui::model::theme::{BACKLIGHT_DIM, BACKLIGHT_NORMAL};
pub trait SimplifiedFeatures {
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 {
fn return_to_c(self) -> u32;
@ -65,27 +74,17 @@ fn touch_eval() -> Option<TouchEvent> {
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
where
F: Component,
F::Msg: ReturnToC,
{
frame.place(SCREEN);
fadeout();
frame.place(ModelFeatures::SCREEN);
ModelFeatures::fadeout();
display::sync();
frame.paint();
display::refresh();
fadein();
ModelFeatures::fadein();
#[cfg(feature = "button")]
while button_eval().is_some() {}
@ -116,14 +115,14 @@ pub fn show<F>(frame: &mut F, fading: bool)
where
F: Component,
{
frame.place(SCREEN);
frame.place(ModelFeatures::SCREEN);
if fading {
fadeout()
ModelFeatures::fadeout()
};
display::sync();
frame.paint();
display::refresh();
if fading {
fadein()
ModelFeatures::fadein()
};
}

@ -18,14 +18,3 @@ pub mod layout;
pub mod model_tr;
#[cfg(feature = "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")]
pub mod bootloader;
pub mod common_messages;
@ -7,3 +9,9 @@ pub mod constant;
pub mod layout;
pub mod screens;
pub mod theme;
pub struct ModelTRFeatures {}
impl SimplifiedFeatures for ModelTRFeatures {
const SCREEN: Rect = constant::SCREEN;
}

@ -5,9 +5,9 @@ use crate::{
trezorhal::secbool::secbool,
ui::{
component::{connect::Connect, Label},
constant::HEIGHT,
display::{self, Color, Font, Icon},
geometry::Point,
geometry::{Point, Rect},
layout::simplified::{run, show, SimplifiedFeatures as _},
util::{from_c_array, from_c_str},
},
};
@ -18,7 +18,6 @@ use super::{
bl_confirm::{Confirm, ConfirmTitle},
Button, ResultScreen, WelcomeScreen,
},
constant,
theme::{
bootloader::{
button_bld, button_bld_menu, button_confirm, button_wipe_cancel, button_wipe_confirm,
@ -28,9 +27,9 @@ use super::{
},
BACKLIGHT_NORMAL, BLACK, FG, WHITE,
},
ModelTTFeatures,
};
use crate::ui::layout::simplified::{fadein, fadeout, run, show};
use intro::Intro;
use menu::Menu;
@ -42,6 +41,8 @@ pub type BootloaderString = String<128>;
const RECONNECT_MESSAGE: &str = "PLEASE RECONNECT\nTHE DEVICE";
const SCREEN: Rect = ModelTTFeatures::SCREEN;
#[no_mangle]
extern "C" fn screen_install_confirm(
vendor_str: *const cty::c_char,
@ -165,12 +166,12 @@ fn screen_progress(
icon: Option<(Icon, Color)>,
) {
if initialize {
fadeout();
display::rect_fill(constant::screen(), bg_color);
ModelTTFeatures::fadeout();
display::rect_fill(SCREEN, bg_color);
}
display::text_center(
Point::new(constant::WIDTH / 2, HEIGHT - 45),
Point::new(SCREEN.width() / 2, SCREEN.height() - 45),
text,
Font::NORMAL,
fg_color,
@ -179,7 +180,7 @@ fn screen_progress(
display::loader(progress, -20, fg_color, bg_color, icon);
display::refresh();
if initialize {
fadein();
ModelTTFeatures::fadein();
}
}
@ -244,16 +245,16 @@ extern "C" fn screen_wipe_fail() {
#[no_mangle]
extern "C" fn screen_boot_empty(fading: bool) {
if fading {
fadeout();
ModelTTFeatures::fadeout();
}
display::rect_fill(constant::screen(), BLACK);
display::rect_fill(SCREEN, BLACK);
let mut frame = WelcomeScreen::new(true);
show(&mut frame, false);
if fading {
fadein();
ModelTTFeatures::fadein();
} else {
display::set_backlight(BACKLIGHT_NORMAL);
}
@ -328,7 +329,7 @@ extern "C" fn screen_welcome() {
#[no_mangle]
extern "C" fn bld_continue_label(bg_color: cty::uint16_t) {
display::text_center(
Point::new(constant::WIDTH / 2, HEIGHT - 5),
Point::new(SCREEN.width() / 2, SCREEN.height() - 5),
"click to continue ...",
Font::NORMAL,
WHITE,

@ -1,3 +1,5 @@
use super::{geometry::Rect, layout::simplified::SimplifiedFeatures};
#[cfg(feature = "bootloader")]
pub mod bootloader;
pub mod component;
@ -7,3 +9,19 @@ pub mod theme;
#[cfg(feature = "micropython")]
pub mod layout;
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…
Cancel
Save