1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-08-04 21:05:29 +00:00

feat(core): integration of background image into homescreen

[no changelog]
This commit is contained in:
tychovrahe 2022-10-13 13:45:19 +02:00
parent 7e4d914818
commit 737b8d4230

View File

@ -2,21 +2,25 @@ use crate::{
time::{Duration, Instant}, time::{Duration, Instant},
trezorhal::usb::usb_configured, trezorhal::usb::usb_configured,
ui::{ ui::{
component::{Component, Empty, Event, EventCtx, Pad, TimerToken}, component::{Component, Event, EventCtx, Pad, TimerToken},
display::{self, Color, Font}, display::{self, Color, Font},
event::{TouchEvent, USBEvent}, event::{TouchEvent, USBEvent},
geometry::{Offset, Point, Rect}, geometry::{Offset, Point, Rect},
model_tt::constant, model_tt::{
util::icon_text_center, component::hs_render::{homescreen, HomescreenNotification, HomescreenText},
constant,
theme::IMAGE_HOMESCREEN,
},
}, },
}; };
use heapless::Vec;
use super::{theme, Loader, LoaderMsg, NotificationFrame}; use super::{theme, Loader, LoaderMsg};
const AREA: Rect = constant::screen(); const AREA: Rect = constant::screen();
const TOP_CENTER: Point = AREA.top_center(); const TOP_CENTER: Point = AREA.top_center();
const LABEL_Y: i16 = 216; const LABEL_Y: i16 = 216;
const LOCKED_Y: i16 = 101; const LOCKED_Y: i16 = 107;
const TAP_Y: i16 = 134; const TAP_Y: i16 = 134;
const HOLD_Y: i16 = 35; const HOLD_Y: i16 = 35;
const LOADER_OFFSET: Offset = Offset::y(-10); const LOADER_OFFSET: Offset = Offset::y(-10);
@ -27,9 +31,9 @@ pub struct Homescreen<T> {
label: T, label: T,
notification: Option<(T, u32)>, notification: Option<(T, u32)>,
hold_to_lock: bool, hold_to_lock: bool,
usb_connected: bool,
loader: Loader, loader: Loader,
pad: Pad, pad: Pad,
paint_notification_only: bool,
delay: Option<TimerToken>, delay: Option<TimerToken>,
} }
@ -48,6 +52,7 @@ where
hold_to_lock, hold_to_lock,
loader: Loader::new().with_durations(LOADER_DURATION, LOADER_DURATION / 3), loader: Loader::new().with_durations(LOADER_DURATION, LOADER_DURATION / 3),
pad: Pad::with_background(theme::BG), pad: Pad::with_background(theme::BG),
paint_notification_only: false,
delay: None, delay: None,
} }
} }
@ -60,23 +65,15 @@ where
} }
} }
fn paint_notification(&self) { fn get_notification(&self) -> Option<HomescreenNotification> {
if !usb_configured() { if !usb_configured() {
let (color, icon) = Self::level_to_style(0); let (color, icon) = Self::level_to_style(0);
NotificationFrame::<Empty, T>::paint_notification( Some(("NO USB CONNECTION", icon, color))
AREA,
icon,
"NO USB CONNECTION",
color,
);
} else if let Some((notification, level)) = &self.notification { } else if let Some((notification, level)) = &self.notification {
let (color, icon) = Self::level_to_style(*level); let (color, icon) = Self::level_to_style(*level);
NotificationFrame::<Empty, T>::paint_notification( Some((notification.as_ref(), icon, color))
AREA, } else {
icon, None
notification.as_ref(),
color,
);
} }
} }
@ -97,6 +94,7 @@ where
fn event_usb(&mut self, ctx: &mut EventCtx, event: Event) { fn event_usb(&mut self, ctx: &mut EventCtx, event: Event) {
if let Event::USB(USBEvent::Connected(_)) = event { if let Event::USB(USBEvent::Connected(_)) = event {
self.paint_notification_only = true;
ctx.request_paint(); ctx.request_paint();
} }
} }
@ -136,6 +134,7 @@ where
Some(LoaderMsg::ShrunkCompletely) => { Some(LoaderMsg::ShrunkCompletely) => {
self.loader.reset(); self.loader.reset();
self.pad.clear(); self.pad.clear();
self.paint_notification_only = false;
ctx.request_paint() ctx.request_paint()
} }
None => {} None => {}
@ -171,8 +170,29 @@ where
if self.loader.is_animating() || self.loader.is_completely_grown(Instant::now()) { if self.loader.is_animating() || self.loader.is_completely_grown(Instant::now()) {
self.paint_loader(); self.paint_loader();
} else { } else {
self.paint_notification(); let mut label_style = theme::TEXT_BOLD;
paint_label(self.label.as_ref(), false); label_style.text_color = theme::FG;
let texts: Vec<Option<HomescreenText>, 4> = unwrap!(Vec::from_slice(&[
Some((
self.label.as_ref(),
label_style,
Offset::new(10, LABEL_Y),
None
)),
None,
None,
None,
],));
let notification = self.get_notification();
homescreen(
IMAGE_HOMESCREEN,
texts,
notification,
self.paint_notification_only,
);
} }
} }
@ -225,22 +245,31 @@ where
} else { } else {
("LOCKED", "Tap to unlock") ("LOCKED", "Tap to unlock")
}; };
icon_text_center(
TOP_CENTER + Offset::y(LOCKED_Y), let mut tap_style = theme::TEXT_NORMAL;
theme::ICON_LOCK, tap_style.text_color = theme::OFF_WHITE;
2,
locked, let mut label_style = theme::TEXT_BOLD;
theme::TEXT_BOLD, label_style.text_color = theme::GREY_MEDIUM;
Offset::zero(),
); let texts: Vec<Option<HomescreenText>, 4> = unwrap!(Vec::from_slice(&[
display::text_center( Some((
TOP_CENTER + Offset::y(TAP_Y), locked,
tap, theme::TEXT_BOLD,
Font::NORMAL, Offset::new(10, LOCKED_Y),
theme::OFF_WHITE, Some(theme::ICON_LOCK)
theme::BG, )),
); Some((tap, tap_style, Offset::new(10, TAP_Y), None)),
paint_label(self.label.as_ref(), true); Some((
self.label.as_ref(),
label_style,
Offset::new(10, LABEL_Y),
None
)),
None,
],));
homescreen(IMAGE_HOMESCREEN, texts, None, false);
} }
} }
@ -251,18 +280,3 @@ impl<T> crate::trace::Trace for Lockscreen<T> {
d.close(); d.close();
} }
} }
fn paint_label(label: &str, lockscreen: bool) {
let label_color = if lockscreen {
theme::GREY_MEDIUM
} else {
theme::FG
};
display::text_center(
TOP_CENTER + Offset::y(LABEL_Y),
label,
Font::BOLD,
label_color,
theme::BG,
);
}