mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-08-04 12:56:25 +00:00
feat(core): integration of background image into homescreen
[no changelog]
This commit is contained in:
parent
7e4d914818
commit
737b8d4230
@ -2,21 +2,25 @@ use crate::{
|
||||
time::{Duration, Instant},
|
||||
trezorhal::usb::usb_configured,
|
||||
ui::{
|
||||
component::{Component, Empty, Event, EventCtx, Pad, TimerToken},
|
||||
component::{Component, Event, EventCtx, Pad, TimerToken},
|
||||
display::{self, Color, Font},
|
||||
event::{TouchEvent, USBEvent},
|
||||
geometry::{Offset, Point, Rect},
|
||||
model_tt::constant,
|
||||
util::icon_text_center,
|
||||
model_tt::{
|
||||
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 TOP_CENTER: Point = AREA.top_center();
|
||||
const LABEL_Y: i16 = 216;
|
||||
const LOCKED_Y: i16 = 101;
|
||||
const LOCKED_Y: i16 = 107;
|
||||
const TAP_Y: i16 = 134;
|
||||
const HOLD_Y: i16 = 35;
|
||||
const LOADER_OFFSET: Offset = Offset::y(-10);
|
||||
@ -27,9 +31,9 @@ pub struct Homescreen<T> {
|
||||
label: T,
|
||||
notification: Option<(T, u32)>,
|
||||
hold_to_lock: bool,
|
||||
usb_connected: bool,
|
||||
loader: Loader,
|
||||
pad: Pad,
|
||||
paint_notification_only: bool,
|
||||
delay: Option<TimerToken>,
|
||||
}
|
||||
|
||||
@ -48,6 +52,7 @@ where
|
||||
hold_to_lock,
|
||||
loader: Loader::new().with_durations(LOADER_DURATION, LOADER_DURATION / 3),
|
||||
pad: Pad::with_background(theme::BG),
|
||||
paint_notification_only: false,
|
||||
delay: None,
|
||||
}
|
||||
}
|
||||
@ -60,23 +65,15 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn paint_notification(&self) {
|
||||
fn get_notification(&self) -> Option<HomescreenNotification> {
|
||||
if !usb_configured() {
|
||||
let (color, icon) = Self::level_to_style(0);
|
||||
NotificationFrame::<Empty, T>::paint_notification(
|
||||
AREA,
|
||||
icon,
|
||||
"NO USB CONNECTION",
|
||||
color,
|
||||
);
|
||||
Some(("NO USB CONNECTION", icon, color))
|
||||
} else if let Some((notification, level)) = &self.notification {
|
||||
let (color, icon) = Self::level_to_style(*level);
|
||||
NotificationFrame::<Empty, T>::paint_notification(
|
||||
AREA,
|
||||
icon,
|
||||
notification.as_ref(),
|
||||
color,
|
||||
);
|
||||
Some((notification.as_ref(), icon, color))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,6 +94,7 @@ where
|
||||
|
||||
fn event_usb(&mut self, ctx: &mut EventCtx, event: Event) {
|
||||
if let Event::USB(USBEvent::Connected(_)) = event {
|
||||
self.paint_notification_only = true;
|
||||
ctx.request_paint();
|
||||
}
|
||||
}
|
||||
@ -136,6 +134,7 @@ where
|
||||
Some(LoaderMsg::ShrunkCompletely) => {
|
||||
self.loader.reset();
|
||||
self.pad.clear();
|
||||
self.paint_notification_only = false;
|
||||
ctx.request_paint()
|
||||
}
|
||||
None => {}
|
||||
@ -171,8 +170,29 @@ where
|
||||
if self.loader.is_animating() || self.loader.is_completely_grown(Instant::now()) {
|
||||
self.paint_loader();
|
||||
} else {
|
||||
self.paint_notification();
|
||||
paint_label(self.label.as_ref(), false);
|
||||
let mut label_style = theme::TEXT_BOLD;
|
||||
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 {
|
||||
("LOCKED", "Tap to unlock")
|
||||
};
|
||||
icon_text_center(
|
||||
TOP_CENTER + Offset::y(LOCKED_Y),
|
||||
theme::ICON_LOCK,
|
||||
2,
|
||||
locked,
|
||||
theme::TEXT_BOLD,
|
||||
Offset::zero(),
|
||||
);
|
||||
display::text_center(
|
||||
TOP_CENTER + Offset::y(TAP_Y),
|
||||
tap,
|
||||
Font::NORMAL,
|
||||
theme::OFF_WHITE,
|
||||
theme::BG,
|
||||
);
|
||||
paint_label(self.label.as_ref(), true);
|
||||
|
||||
let mut tap_style = theme::TEXT_NORMAL;
|
||||
tap_style.text_color = theme::OFF_WHITE;
|
||||
|
||||
let mut label_style = theme::TEXT_BOLD;
|
||||
label_style.text_color = theme::GREY_MEDIUM;
|
||||
|
||||
let texts: Vec<Option<HomescreenText>, 4> = unwrap!(Vec::from_slice(&[
|
||||
Some((
|
||||
locked,
|
||||
theme::TEXT_BOLD,
|
||||
Offset::new(10, LOCKED_Y),
|
||||
Some(theme::ICON_LOCK)
|
||||
)),
|
||||
Some((tap, tap_style, Offset::new(10, TAP_Y), None)),
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user