1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 22:38:08 +00:00

refactor(core/rust): reuse the same component for "waiting for host" screen

This commit is contained in:
matejcik 2024-02-07 10:36:25 +01:00 committed by Jiří Musil
parent 8471e0c455
commit 65178a6a36
6 changed files with 103 additions and 126 deletions

View File

@ -0,0 +1,79 @@
use crate::{
strutil::TString,
ui::{
component::{Component, Event, EventCtx, Never, Pad},
display::{self, Color, Font},
geometry::{Offset, Rect},
},
};
pub struct Connect {
fg: Color,
bg: Pad,
message: TString<'static>,
}
impl Connect {
pub fn new<T>(message: T, fg: Color, bg: Color) -> Self
where
T: Into<TString<'static>>,
{
let mut instance = Self {
fg,
bg: Pad::with_background(bg),
message: message.into(),
};
instance.bg.clear();
instance
}
}
impl Component for Connect {
type Msg = Never;
fn place(&mut self, bounds: Rect) -> Rect {
self.bg.place(bounds);
bounds
}
fn event(&mut self, _ctx: &mut EventCtx, _event: Event) -> Option<Self::Msg> {
None
}
fn paint(&mut self) {
let font = Font::NORMAL;
self.bg.paint();
self.message.map(|t| {
display::text_center(
self.bg.area.center() + Offset::y(font.text_height() / 2),
t,
font,
self.fg,
self.bg.color,
)
});
}
}
#[cfg(feature = "micropython")]
mod micropython {
use crate::{error::Error, micropython::obj::Obj, ui::layout::obj::ComponentMsgObj};
use super::Connect;
impl ComponentMsgObj for Connect {
fn msg_try_into_obj(&self, _msg: Self::Msg) -> Result<Obj, Error> {
unreachable!()
}
}
}
#[cfg(feature = "ui_debug")]
impl crate::trace::Trace for Connect {
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
t.component("Connect");
t.string("message", self.message);
}
}

View File

@ -2,6 +2,7 @@
pub mod base;
pub mod border;
pub mod connect;
pub mod empty;
pub mod image;
pub mod label;

View File

@ -1,47 +0,0 @@
use crate::ui::{
component::{Component, Event, EventCtx, Never, Pad},
display::{self, Font},
geometry::{Offset, Rect},
};
use super::super::theme::bootloader::{BLD_BG, BLD_FG};
pub struct Connect {
bg: Pad,
message: &'static str,
}
impl Connect {
pub fn new(message: &'static str) -> Self {
Self {
bg: Pad::with_background(BLD_BG).with_clear(),
message,
}
}
}
impl Component for Connect {
type Msg = Never;
fn place(&mut self, bounds: Rect) -> Rect {
self.bg.place(bounds);
bounds
}
fn event(&mut self, _ctx: &mut EventCtx, _event: Event) -> Option<Self::Msg> {
None
}
fn paint(&mut self) {
let font = Font::NORMAL;
self.bg.paint();
display::text_center(
self.bg.area.center() + Offset::y(font.text_height() / 2),
self.message,
font,
BLD_FG,
BLD_BG,
);
}
}

View File

@ -1,40 +1,37 @@
use heapless::String;
use crate::{
strutil::hexlify,
trezorhal::io::io_button_read,
trezorhal::{io::io_button_read, secbool::secbool},
ui::{
component::{Component, Event, EventCtx, Label, LineBreaking::BreakWordsNoHyphen, Never},
constant::SCREEN,
component::{
connect::Connect, Component, Event, EventCtx, Label, LineBreaking::BreakWordsNoHyphen,
Never,
},
constant,
constant::{HEIGHT, SCREEN},
display::{self, Color, Font, Icon},
event::ButtonEvent,
geometry::{Alignment2D, Offset, Rect},
geometry::{Alignment2D, Offset, Point, Rect},
util::{from_c_array, from_c_str},
},
};
use heapless::String;
use super::component::{ResultScreen, WelcomeScreen};
use super::{
component::{
bl_confirm::{Confirm, ConfirmMsg},
ResultScreen, WelcomeScreen,
},
theme::{
bootloader::{BLD_BG, BLD_FG, ICON_ALERT, ICON_SPINNER, ICON_SUCCESS},
ICON_ARM_LEFT, ICON_ARM_RIGHT, TEXT_BOLD, TEXT_NORMAL, WHITE,
},
};
mod connect;
mod intro;
mod menu;
mod welcome;
use crate::{
trezorhal::secbool::secbool,
ui::{
constant,
constant::HEIGHT,
geometry::Point,
model_tr::{
component::bl_confirm::{Confirm, ConfirmMsg},
theme::{
bootloader::{BLD_BG, BLD_FG, ICON_ALERT, ICON_SPINNER, ICON_SUCCESS},
ICON_ARM_LEFT, ICON_ARM_RIGHT, TEXT_BOLD, TEXT_NORMAL, WHITE,
},
},
},
};
use connect::Connect;
use intro::Intro;
use menu::Menu;
use welcome::Welcome;
@ -301,7 +298,7 @@ extern "C" fn screen_wipe_progress(progress: u16, initialize: bool) {
#[no_mangle]
extern "C" fn screen_connect(_initial_setup: bool) {
let mut frame = Connect::new("Waiting for host...");
let mut frame = Connect::new("Waiting for host...", BLD_FG, BLD_BG);
show(&mut frame);
}

View File

@ -1,52 +0,0 @@
use crate::ui::{
component::{Component, Event, EventCtx, Never, Pad},
constant::screen,
display::{self, Color, Font},
geometry::{Offset, Rect},
model_tt::theme::bootloader::BLD_TITLE_COLOR,
};
pub struct Connect {
fg: Color,
bg: Pad,
message: &'static str,
}
impl Connect {
pub fn new(message: &'static str, fg: Color, bg: Color) -> Self {
let mut instance = Self {
fg,
bg: Pad::with_background(bg),
message,
};
instance.bg.clear();
instance
}
}
impl Component for Connect {
type Msg = Never;
fn place(&mut self, bounds: Rect) -> Rect {
self.bg.place(screen());
bounds
}
fn event(&mut self, _ctx: &mut EventCtx, _event: Event) -> Option<Self::Msg> {
None
}
fn paint(&mut self) {
let font = Font::NORMAL;
self.bg.paint();
display::text_center(
screen().center() + Offset::y(font.text_height() / 2),
self.message,
Font::NORMAL,
BLD_TITLE_COLOR,
self.bg.color,
);
}
}

View File

@ -5,7 +5,7 @@ use crate::{
strutil::hexlify,
trezorhal::{io::io_touch_read, secbool::secbool},
ui::{
component::{Component, Event, EventCtx, Label, Never},
component::{connect::Connect, Component, Event, EventCtx, Label, Never},
constant::{screen, HEIGHT},
display::{self, Color, Font, Icon},
event::TouchEvent,
@ -15,7 +15,7 @@ use crate::{
};
use super::{
bootloader::{connect::Connect, welcome::Welcome},
bootloader::welcome::Welcome,
component::{
bl_confirm::{Confirm, ConfirmTitle},
Button, ResultScreen, WelcomeScreen,
@ -35,7 +35,6 @@ use super::{
use intro::Intro;
use menu::Menu;
mod connect;
pub mod intro;
pub mod menu;
pub mod welcome;