mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-08 22:40:59 +00:00
refactor(core/rust): reuse the same component for "waiting for host" screen
This commit is contained in:
parent
8471e0c455
commit
65178a6a36
79
core/embed/rust/src/ui/component/connect.rs
Normal file
79
core/embed/rust/src/ui/component/connect.rs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
pub mod base;
|
pub mod base;
|
||||||
pub mod border;
|
pub mod border;
|
||||||
|
pub mod connect;
|
||||||
pub mod empty;
|
pub mod empty;
|
||||||
pub mod image;
|
pub mod image;
|
||||||
pub mod label;
|
pub mod label;
|
||||||
|
@ -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,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,40 +1,37 @@
|
|||||||
|
use heapless::String;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
strutil::hexlify,
|
strutil::hexlify,
|
||||||
trezorhal::io::io_button_read,
|
trezorhal::{io::io_button_read, secbool::secbool},
|
||||||
ui::{
|
ui::{
|
||||||
component::{Component, Event, EventCtx, Label, LineBreaking::BreakWordsNoHyphen, Never},
|
component::{
|
||||||
constant::SCREEN,
|
connect::Connect, Component, Event, EventCtx, Label, LineBreaking::BreakWordsNoHyphen,
|
||||||
|
Never,
|
||||||
|
},
|
||||||
|
constant,
|
||||||
|
constant::{HEIGHT, SCREEN},
|
||||||
display::{self, Color, Font, Icon},
|
display::{self, Color, Font, Icon},
|
||||||
event::ButtonEvent,
|
event::ButtonEvent,
|
||||||
geometry::{Alignment2D, Offset, Rect},
|
geometry::{Alignment2D, Offset, Point, Rect},
|
||||||
util::{from_c_array, from_c_str},
|
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 intro;
|
||||||
mod menu;
|
mod menu;
|
||||||
mod welcome;
|
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 intro::Intro;
|
||||||
use menu::Menu;
|
use menu::Menu;
|
||||||
use welcome::Welcome;
|
use welcome::Welcome;
|
||||||
@ -301,7 +298,7 @@ extern "C" fn screen_wipe_progress(progress: u16, initialize: bool) {
|
|||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
extern "C" fn screen_connect(_initial_setup: bool) {
|
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);
|
show(&mut frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -5,7 +5,7 @@ use crate::{
|
|||||||
strutil::hexlify,
|
strutil::hexlify,
|
||||||
trezorhal::{io::io_touch_read, secbool::secbool},
|
trezorhal::{io::io_touch_read, secbool::secbool},
|
||||||
ui::{
|
ui::{
|
||||||
component::{Component, Event, EventCtx, Label, Never},
|
component::{connect::Connect, Component, Event, EventCtx, Label, Never},
|
||||||
constant::{screen, HEIGHT},
|
constant::{screen, HEIGHT},
|
||||||
display::{self, Color, Font, Icon},
|
display::{self, Color, Font, Icon},
|
||||||
event::TouchEvent,
|
event::TouchEvent,
|
||||||
@ -15,7 +15,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
bootloader::{connect::Connect, welcome::Welcome},
|
bootloader::welcome::Welcome,
|
||||||
component::{
|
component::{
|
||||||
bl_confirm::{Confirm, ConfirmTitle},
|
bl_confirm::{Confirm, ConfirmTitle},
|
||||||
Button, ResultScreen, WelcomeScreen,
|
Button, ResultScreen, WelcomeScreen,
|
||||||
@ -35,7 +35,6 @@ use super::{
|
|||||||
use intro::Intro;
|
use intro::Intro;
|
||||||
use menu::Menu;
|
use menu::Menu;
|
||||||
|
|
||||||
mod connect;
|
|
||||||
pub mod intro;
|
pub mod intro;
|
||||||
pub mod menu;
|
pub mod menu;
|
||||||
pub mod welcome;
|
pub mod welcome;
|
||||||
|
Loading…
Reference in New Issue
Block a user