mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-18 05:28:40 +00:00
feat(core): show the preview of default homescreen image
[no changelog]
This commit is contained in:
parent
4ecd4cc323
commit
046ff15275
@ -28,6 +28,15 @@ const LABEL_OUTSET: i16 = 3;
|
||||
const NOTIFICATION_FONT: Font = Font::NORMAL;
|
||||
const NOTIFICATION_ICON: Icon = theme::ICON_WARNING;
|
||||
|
||||
fn paint_default_image() {
|
||||
theme::ICON_LOGO.draw(
|
||||
TOP_CENTER + Offset::y(LOGO_ICON_TOP_MARGIN),
|
||||
Alignment2D::TOP_CENTER,
|
||||
theme::FG,
|
||||
theme::BG,
|
||||
);
|
||||
}
|
||||
|
||||
pub struct Homescreen<T>
|
||||
where
|
||||
T: StringType,
|
||||
@ -58,12 +67,7 @@ where
|
||||
let toif_data = unwrap!(Toif::new(user_custom_image.as_ref()));
|
||||
toif_data.draw(TOP_CENTER, Alignment2D::TOP_CENTER, theme::FG, theme::BG);
|
||||
} else {
|
||||
theme::ICON_LOGO.draw(
|
||||
TOP_CENTER + Offset::y(LOGO_ICON_TOP_MARGIN),
|
||||
Alignment2D::TOP_CENTER,
|
||||
theme::FG,
|
||||
theme::BG,
|
||||
);
|
||||
paint_default_image();
|
||||
}
|
||||
}
|
||||
|
||||
@ -273,8 +277,13 @@ where
|
||||
|
||||
fn paint(&mut self) {
|
||||
// Drawing the image full-screen first and then other things on top
|
||||
let toif_data = unwrap!(Toif::new((self.buffer_func)()));
|
||||
let buffer = (self.buffer_func)();
|
||||
if buffer.is_empty() {
|
||||
paint_default_image();
|
||||
} else {
|
||||
let toif_data = unwrap!(Toif::new(buffer));
|
||||
toif_data.draw(TOP_CENTER, Alignment2D::TOP_CENTER, theme::FG, theme::BG);
|
||||
};
|
||||
// Need to make all the title background black, so the title text is well
|
||||
// visible
|
||||
let title_area = self.title.inner().area();
|
||||
|
@ -703,16 +703,25 @@ extern "C" fn new_confirm_homescreen(n_args: usize, args: *const Obj, kwargs: *m
|
||||
|
||||
// Layout needs to hold the Obj to play nice with GC. Obj is resolved to &[u8]
|
||||
// in every paint pass.
|
||||
let buffer_func = move || {
|
||||
// SAFETY: We expect no existing mutable reference. Resulting reference is
|
||||
// discarded before returning to micropython.
|
||||
let buffer_func = move || unsafe { unwrap!(get_buffer(data)) };
|
||||
let buffer = unsafe { unwrap!(get_buffer(data)) };
|
||||
// Incoming data may be empty, meaning we should display default homescreen
|
||||
// image.
|
||||
if buffer.is_empty() {
|
||||
theme::IMAGE_HOMESCREEN
|
||||
} else {
|
||||
buffer
|
||||
}
|
||||
};
|
||||
|
||||
let size = match jpeg_info(buffer_func()) {
|
||||
Some(info) => info.0,
|
||||
_ => return Err(value_error!("Invalid image.")),
|
||||
};
|
||||
|
||||
let buttons = Button::cancel_confirm_text(None, Some("CONFIRM"));
|
||||
let buttons = Button::cancel_confirm_text(None, Some("CHANGE"));
|
||||
let obj = LayoutObj::new(Frame::centered(
|
||||
theme::label_title(),
|
||||
title,
|
||||
|
@ -153,14 +153,6 @@ async def apply_settings(msg: ApplySettings) -> Success:
|
||||
async def _require_confirm_change_homescreen(homescreen: bytes) -> None:
|
||||
from trezor.ui.layouts import confirm_homescreen
|
||||
|
||||
if homescreen == b"":
|
||||
await confirm_action(
|
||||
"set_homescreen",
|
||||
"Set homescreen",
|
||||
description="Do you really want to set default homescreen image?",
|
||||
br_code=BRT_PROTECT_CALL,
|
||||
)
|
||||
else:
|
||||
await confirm_homescreen(homescreen)
|
||||
|
||||
|
||||
|
@ -393,7 +393,7 @@ async def confirm_homescreen(
|
||||
interact(
|
||||
RustLayout(
|
||||
trezorui2.confirm_homescreen(
|
||||
title="SET HOMESCREEN",
|
||||
title="CHANGE HOMESCREEN",
|
||||
image=image,
|
||||
)
|
||||
),
|
||||
|
Loading…
Reference in New Issue
Block a user