Skip to content

Commit

Permalink
refactor(core/rust): reuse the same component for "waiting for host" …
Browse files Browse the repository at this point in the history
…screen
  • Loading branch information
matejcik authored and grdddj committed Feb 12, 2024
1 parent 8471e0c commit 65178a6
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 126 deletions.
79 changes: 79 additions & 0 deletions core/embed/rust/src/ui/component/connect.rs
Original file line number Diff line number Diff line change
@@ -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);
}
}
1 change: 1 addition & 0 deletions core/embed/rust/src/ui/component/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

pub mod base;
pub mod border;
pub mod connect;
pub mod empty;
pub mod image;
pub mod label;
Expand Down
47 changes: 0 additions & 47 deletions core/embed/rust/src/ui/model_tr/bootloader/connect.rs

This file was deleted.

45 changes: 21 additions & 24 deletions core/embed/rust/src/ui/model_tr/bootloader/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
52 changes: 0 additions & 52 deletions core/embed/rust/src/ui/model_tt/bootloader/connect.rs

This file was deleted.

5 changes: 2 additions & 3 deletions core/embed/rust/src/ui/model_tt/bootloader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -15,7 +15,7 @@ use crate::{
};

use super::{
bootloader::{connect::Connect, welcome::Welcome},
bootloader::welcome::Welcome,
component::{
bl_confirm::{Confirm, ConfirmTitle},
Button, ResultScreen, WelcomeScreen,
Expand All @@ -35,7 +35,6 @@ use super::{
use intro::Intro;
use menu::Menu;

mod connect;
pub mod intro;
pub mod menu;
pub mod welcome;
Expand Down

0 comments on commit 65178a6

Please sign in to comment.