1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-19 12:58:13 +00:00

feat(core): change default homescreen image for mercury

the default homescreen is rendered algorithmically, when changing homescreen to default we now use text message due to lack of scaling

[no changelog]
This commit is contained in:
tychovrahe 2024-06-04 15:46:36 +02:00 committed by matejcik
parent 0cd36cd41b
commit 9ee670a440
13 changed files with 131 additions and 62 deletions

View File

@ -250,6 +250,7 @@ static void _librust_qstrs(void) {
MP_QSTR_hold_danger;
MP_QSTR_homescreen__click_to_connect;
MP_QSTR_homescreen__click_to_unlock;
MP_QSTR_homescreen__set_default;
MP_QSTR_homescreen__title_backup_failed;
MP_QSTR_homescreen__title_backup_needed;
MP_QSTR_homescreen__title_coinjoin_authorized;

View File

@ -1333,6 +1333,7 @@ pub enum TranslatedString {
recovery__title_unlock_repeated_backup = 933, // "Multi-share backup"
recovery__unlock_repeated_backup = 934, // "Create additional backup?"
recovery__unlock_repeated_backup_verb = 935, // "Unlock backup"
homescreen__set_default = 936, // "Do you really want to set default homescreen image?"
}
impl TranslatedString {
@ -2661,6 +2662,7 @@ impl TranslatedString {
Self::recovery__title_unlock_repeated_backup => "Multi-share backup",
Self::recovery__unlock_repeated_backup => "Create additional backup?",
Self::recovery__unlock_repeated_backup_verb => "Unlock backup",
Self::homescreen__set_default => "Do you really want to set default homescreen image?",
}
}
@ -3990,6 +3992,7 @@ impl TranslatedString {
Qstr::MP_QSTR_recovery__title_unlock_repeated_backup => Some(Self::recovery__title_unlock_repeated_backup),
Qstr::MP_QSTR_recovery__unlock_repeated_backup => Some(Self::recovery__unlock_repeated_backup),
Qstr::MP_QSTR_recovery__unlock_repeated_backup_verb => Some(Self::recovery__unlock_repeated_backup_verb),
Qstr::MP_QSTR_homescreen__set_default => Some(Self::homescreen__set_default),
_ => None,
}
}

View File

@ -10,7 +10,7 @@ use crate::{
event::{TouchEvent, USBEvent},
geometry::{Alignment, Alignment2D, Offset, Point, Rect},
layout::util::get_user_custom_image,
model_mercury::{constant, theme::IMAGE_HOMESCREEN},
model_mercury::constant,
shape::{self, Renderer},
},
};
@ -20,7 +20,7 @@ use crate::ui::{
constant::{screen, HEIGHT, WIDTH},
model_mercury::{
cshape,
theme::{GREY_LIGHT, ICON_KEY, TITLE_HEIGHT},
theme::{GREY_LIGHT, HOMESCREEN_ICON, ICON_KEY},
},
shape::{render_on_canvas, ImageBuffer, Rgb565Canvas},
util::animation_disabled,
@ -43,6 +43,46 @@ pub const HOMESCREEN_IMAGE_WIDTH: i16 = WIDTH;
pub const HOMESCREEN_IMAGE_HEIGHT: i16 = HEIGHT;
pub const HOMESCREEN_TOIF_SIZE: i16 = 144;
fn render_default_hs<'a>(target: &mut impl Renderer<'a>) {
const OVERLAY_OFFSET: i16 = 9;
const RADIUS: i16 = 85;
const SPAN: i16 = 10;
const THICKNESS: i16 = 6;
const NUM_CIRCLES: i16 = 5;
let area = AREA.translate(Offset::y(OVERLAY_OFFSET));
shape::Bar::new(area)
.with_fg(theme::BG)
.with_bg(theme::BG)
.render(target);
#[cfg(any(feature = "universal_fw", feature = "ui_debug"))]
let colors = [0x0BB671, 0x247553, 0x235C44, 0x1D3E30, 0x14271F];
#[cfg(not(any(feature = "universal_fw", feature = "ui_debug")))]
let colors = [0xEEA600, 0xB27C00, 0x775300, 0x463100, 0x2C1F00];
for i in 0..NUM_CIRCLES {
let r = RADIUS - i * SPAN;
let fg = Color::from_u32(colors[i as usize]);
let bg = theme::BG;
let thickness = THICKNESS;
shape::Circle::new(area.center(), r)
.with_fg(fg)
.with_bg(bg)
.with_thickness(thickness)
.render(target);
}
shape::ToifImage::new(area.center(), HOMESCREEN_ICON.toif)
.with_align(Alignment2D::CENTER)
.render(target);
}
#[derive(Clone, Copy)]
pub struct HomescreenNotification {
pub text: TString<'static>,
@ -52,8 +92,10 @@ pub struct HomescreenNotification {
pub struct Homescreen {
label: Label<'static>,
label_width: i16,
label_height: i16,
notification: Option<(TString<'static>, u8)>,
image: BinaryData<'static>,
image: Option<BinaryData<'static>>,
hold_to_lock: bool,
loader: Loader,
delay: Option<TimerToken>,
@ -69,8 +111,13 @@ impl Homescreen {
notification: Option<(TString<'static>, u8)>,
hold_to_lock: bool,
) -> Self {
let label_width = label.map(|t| theme::TEXT_DEMIBOLD.text_font.text_width(t));
let label_height = label.map(|t| theme::TEXT_DEMIBOLD.text_font.visible_text_height(t));
Self {
label: Label::new(label, Alignment::Start, theme::TEXT_DEMIBOLD).vertically_centered(),
label: Label::new(label, Alignment::Center, theme::TEXT_DEMIBOLD).vertically_centered(),
label_width,
label_height,
notification,
image: get_homescreen_image(),
hold_to_lock,
@ -171,7 +218,7 @@ impl Component for Homescreen {
fn place(&mut self, bounds: Rect) -> Rect {
self.loader.place(AREA.translate(LOADER_OFFSET));
self.label
.place(bounds.split_top(TITLE_HEIGHT).0.translate(Offset::x(4)));
.place(bounds.split_top(38).0.split_left(self.label_width + 12).0);
bounds
}
@ -192,10 +239,14 @@ impl Component for Homescreen {
if self.loader.is_animating() || self.loader.is_completely_grown(Instant::now()) {
self.render_loader(target);
} else {
if let ImageInfo::Jpeg(_) = ImageInfo::parse(self.image) {
shape::JpegImage::new_image(AREA.center(), self.image)
.with_align(Alignment2D::CENTER)
.render(target);
if let Some(image) = self.image {
if let ImageInfo::Jpeg(_) = ImageInfo::parse(image) {
shape::JpegImage::new_image(AREA.center(), image)
.with_align(Alignment2D::CENTER)
.render(target);
}
} else {
render_default_hs(target);
}
let label_width = self
@ -203,7 +254,7 @@ impl Component for Homescreen {
.text()
.map(|t| theme::TEXT_DEMIBOLD.text_font.text_width(t));
let r = Rect::new(Point::new(-30, -30), Point::new(label_width + 12, 42));
let r = Rect::new(Point::new(-30, -30), Point::new(label_width + 12, 38));
shape::Bar::new(r)
.with_bg(Color::black())
.with_alpha(160)
@ -293,8 +344,10 @@ impl LockscreenAnim {
pub struct Lockscreen {
anim: LockscreenAnim,
label: TString<'static>,
image: BinaryData<'static>,
label: Label<'static>,
label_width: i16,
label_height: i16,
image: Option<BinaryData<'static>>,
bootscreen: bool,
coinjoin_authorized: bool,
bg_image: ImageBuffer<Rgb565Canvas<'static>>,
@ -306,12 +359,21 @@ impl Lockscreen {
let mut buf = unwrap!(ImageBuffer::new(AREA.size()), "no image buf");
render_on_canvas(buf.canvas(), None, |target| {
shape::JpegImage::new_image(Point::zero(), image).render(target);
if let Some(image) = image {
shape::JpegImage::new_image(Point::zero(), image).render(target);
} else {
render_default_hs(target);
}
});
let label_width = label.map(|t| theme::TEXT_DEMIBOLD.text_font.text_width(t));
let label_height = label.map(|t| theme::TEXT_DEMIBOLD.text_font.visible_text_height(t));
Lockscreen {
anim: LockscreenAnim::default(),
label,
label: Label::new(label, Alignment::Center, theme::TEXT_DEMIBOLD),
label_width,
label_height,
image,
bootscreen,
coinjoin_authorized,
@ -324,6 +386,8 @@ impl Component for Lockscreen {
type Msg = HomescreenMsg;
fn place(&mut self, bounds: Rect) -> Rect {
self.label
.place(bounds.split_top(38).0.split_left(self.label_width + 12).0);
bounds
}
@ -395,29 +459,15 @@ impl Component for Lockscreen {
(None, TR::lockscreen__tap_to_unlock)
};
let mut label_style = theme::TEXT_DEMIBOLD;
label_style.text_color = theme::GREY_LIGHT;
self.label.render(target);
let mut offset = 0;
self.label.map(|t| {
offset = theme::TEXT_DEMIBOLD.text_font.visible_text_height(t);
let text_pos = Point::new(0, offset);
shape::Text::new(text_pos, t)
.with_font(theme::TEXT_DEMIBOLD.text_font)
.with_fg(theme::GREY_LIGHT)
.render(target);
});
offset += 6;
let mut offset = 6 + self.label_height;
if let Some(t) = locked {
t.map_translated(|t| {
offset += theme::TEXT_SUB_GREY.text_font.visible_text_height(t);
let text_pos = Point::new(0, offset);
let text_pos = Point::new(6, offset);
shape::Text::new(text_pos, t)
.with_font(theme::TEXT_SUB_GREY.text_font)
@ -457,13 +507,13 @@ pub fn check_homescreen_format(image: BinaryData) -> bool {
}
}
fn get_homescreen_image() -> BinaryData<'static> {
fn get_homescreen_image() -> Option<BinaryData<'static>> {
if let Ok(image) = get_user_custom_image() {
if check_homescreen_format(image) {
return image;
return Some(image);
}
}
IMAGE_HOMESCREEN.into()
None
}
#[cfg(feature = "ui_debug")]

View File

@ -70,7 +70,7 @@ impl UnlockOverlay {
canvas.fill_circle(center, r - Self::THICKNESS, opaque, 255);
// Inner fixed circle
let r = Self::RADIUS - (9 * Self::SPAN) / 2;
let r = Self::RADIUS - (9 * Self::SPAN) / 2 - 1;
canvas.fill_circle(center, r, transp, 255);
canvas.fill_circle(center, r - Self::THICKNESS, opaque, 255);
}

View File

@ -586,24 +586,36 @@ extern "C" fn new_confirm_homescreen(n_args: usize, args: *const Obj, kwargs: *m
let title: TString = kwargs.get(Qstr::MP_QSTR_title)?.try_into()?;
let image: Obj = kwargs.get(Qstr::MP_QSTR_image)?;
let mut jpeg: BinaryData = image.try_into()?;
let jpeg: BinaryData = image.try_into()?;
if jpeg.is_empty() {
// Incoming data may be empty, meaning we should
// display default homescreen image.
jpeg = theme::IMAGE_HOMESCREEN.into();
// display default homescreen message.
let buttons = Button::cancel_confirm_text(None, Some(TR::buttons__change.into()));
let obj = LayoutObj::new(Frame::centered(
title,
Dialog::new(
Paragraphs::new([Paragraph::new(
&theme::TEXT_DEMIBOLD,
TR::homescreen__set_default,
)
.centered()]),
buttons,
),
))?;
Ok(obj.into())
} else {
if !check_homescreen_format(jpeg) {
return Err(value_error!("Invalid image."));
};
let buttons = Button::cancel_confirm_text(None, Some(TR::buttons__change.into()));
let obj = LayoutObj::new(Frame::centered(
title,
Dialog::new(Jpeg::new(jpeg, 1), buttons),
))?;
Ok(obj.into())
}
if !check_homescreen_format(jpeg) {
return Err(value_error!("Invalid image."));
};
let buttons = Button::cancel_confirm_text(None, Some(TR::buttons__change.into()));
let obj = LayoutObj::new(Frame::centered(
title,
Dialog::new(Jpeg::new(jpeg, 1), buttons),
))?;
Ok(obj.into())
};
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

View File

@ -173,7 +173,7 @@ include_icon!(IMAGE_BG_BACK_BTN_TALL, "model_tt/res/bg-back52.toif");
include_icon!(ICON_LOGO_EMPTY, "model_tt/res/lock_empty.toif");
// Default homescreen
pub const IMAGE_HOMESCREEN: &[u8] = include_res!("model_tt/res/bg.jpg");
include_icon!(HOMESCREEN_ICON, "model_mercury/res/hs_lock.toif");
pub const fn label_default() -> TextStyle {
TEXT_NORMAL

View File

@ -356,6 +356,7 @@ class TR:
haptic_feedback__title: str = "Haptic feedback"
homescreen__click_to_connect: str = "Click to Connect"
homescreen__click_to_unlock: str = "Click to Unlock"
homescreen__set_default: str = "Do you really want to set default homescreen image?"
homescreen__title_backup_failed: str = "Backup failed"
homescreen__title_backup_needed: str = "Backup needed"
homescreen__title_coinjoin_authorized: str = "Coinjoin authorized"

View File

@ -366,6 +366,7 @@
"homescreen__title_pin_not_set": "PIN not set",
"homescreen__title_seedless": "Seedless",
"homescreen__title_set": "Change homescreen?",
"homescreen__set_default": "Do you really want to set default homescreen image?",
"inputs__back": "BACK",
"inputs__cancel": "CANCEL",
"inputs__delete": "DELETE",

View File

@ -934,5 +934,6 @@
"932": "brightness__title",
"933": "recovery__title_unlock_repeated_backup",
"934": "recovery__unlock_repeated_backup",
"935": "recovery__unlock_repeated_backup_verb"
"935": "recovery__unlock_repeated_backup_verb",
"936": "homescreen__set_default"
}

View File

@ -1,8 +1,8 @@
{
"current": {
"merkle_root": "45979e4f395fcad03d843869023d35047483512ec797063806998dc553823c72",
"datetime": "2024-06-03T12:43:57.548072",
"commit": "510121bad342d1f900ca123e131448d577a25e39"
"merkle_root": "886b12bcb1eb7dd11f8f8509fb5ee2eb13e1ca6ae968ca0e6732b440ba465416",
"datetime": "2024-06-05T13:23:30.327902",
"commit": "9ad44f311cad1eee987452c8de21d18d931df44e"
},
"history": [
{

View File

@ -22666,14 +22666,14 @@
"T3T1_fr_zcash-test_sign_tx.py::test_version_group_id_missing": "37dad81ffcb3e0cccd78790d07ff0141ddf6cf2c4e67c3a8c9000c7ce7e45eaf"
},
"persistence_tests": {
"T3T1_en_test_safety_checks.py::test_safety_checks_level_after_reboot[SafetyCheckLevel.PromptAlways--081810a6": "5d970f956013d770ac3b9836c8958b1c24b6294079c259b7146071e168bba628",
"T3T1_en_test_safety_checks.py::test_safety_checks_level_after_reboot[SafetyCheckLevel.PromptTempora-b3d21f4a": "9fdd5f4f77b63affc70af34ee0c55be5522f0389340ceb31e644b964610503e9",
"T3T1_en_test_safety_checks.py::test_safety_checks_level_after_reboot[SafetyCheckLevel.Strict-Safety-f1ff9c26": "67c493757e3dc5228907e3db9dd853788c37be93295d247ae988b3ab7f988ec0",
"T3T1_en_test_shamir_persistence.py::test_abort": "699a1450e491a9059926afded4c4bac2fc20bc125adc6508e446457052015014",
"T3T1_en_test_shamir_persistence.py::test_recovery_multiple_resets": "6da13841e94b968ebf1871dd18e20b73ff464f07eb21ebf6d510675505b22945",
"T3T1_en_test_shamir_persistence.py::test_recovery_on_old_wallet": "a4c00fba813a30af023ce02cf7f554f736852f15f68241d88e1a1085cbc23b03",
"T3T1_en_test_shamir_persistence.py::test_recovery_single_reset": "7c1d0aa16d3a4c19815262ef18bf53796d3cefa5d71f19775ddf95acc153055a",
"T3T1_en_test_wipe_code.py::test_wipe_code_activate_core": "d43d9181b68b25ee2520976f899898a9882fdbcf2bd77c0bef92a47ca0487d04"
"T3T1_en_test_safety_checks.py::test_safety_checks_level_after_reboot[SafetyCheckLevel.PromptAlways--081810a6": "7d18d65883b195be762f7d2e7ca1337d19caf65eb4c2c439484a8abc0b7a9f32",
"T3T1_en_test_safety_checks.py::test_safety_checks_level_after_reboot[SafetyCheckLevel.PromptTempora-b3d21f4a": "b01f34ba8953a78b2fb235e345c862a54b91dd0ff4b072fa7172d0f24977558f",
"T3T1_en_test_safety_checks.py::test_safety_checks_level_after_reboot[SafetyCheckLevel.Strict-Safety-f1ff9c26": "5856901cae7d000f7db9a185676fcd2a32a748c42cbbeb50c1069ea842ce3247",
"T3T1_en_test_shamir_persistence.py::test_abort": "a1bb0393f40369d65478bd037fafdec4d64a37486cc432b68ffe7051c5f27df4",
"T3T1_en_test_shamir_persistence.py::test_recovery_multiple_resets": "cca49682544d6fce18e06c9d7f626787b7ebae95821c82a56fdc168d2c89a179",
"T3T1_en_test_shamir_persistence.py::test_recovery_on_old_wallet": "6bd027b12b00011e7fda75b13286751c67c7e279ff32e285f2a7ee7078f00aee",
"T3T1_en_test_shamir_persistence.py::test_recovery_single_reset": "8f2c5939c72cbd699820a81d4edd0b9a082684a6a79739312f9de067bdd47603",
"T3T1_en_test_wipe_code.py::test_wipe_code_activate_core": "d250aad4cba370f28bdac1c2e59b1dc59ba9fcbfd6ed7be5f0e74544a7851424"
}
}
}