mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-18 13:38:12 +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_FONT: Font = Font::NORMAL;
|
||||||
const NOTIFICATION_ICON: Icon = theme::ICON_WARNING;
|
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>
|
pub struct Homescreen<T>
|
||||||
where
|
where
|
||||||
T: StringType,
|
T: StringType,
|
||||||
@ -58,12 +67,7 @@ where
|
|||||||
let toif_data = unwrap!(Toif::new(user_custom_image.as_ref()));
|
let toif_data = unwrap!(Toif::new(user_custom_image.as_ref()));
|
||||||
toif_data.draw(TOP_CENTER, Alignment2D::TOP_CENTER, theme::FG, theme::BG);
|
toif_data.draw(TOP_CENTER, Alignment2D::TOP_CENTER, theme::FG, theme::BG);
|
||||||
} else {
|
} else {
|
||||||
theme::ICON_LOGO.draw(
|
paint_default_image();
|
||||||
TOP_CENTER + Offset::y(LOGO_ICON_TOP_MARGIN),
|
|
||||||
Alignment2D::TOP_CENTER,
|
|
||||||
theme::FG,
|
|
||||||
theme::BG,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,8 +277,13 @@ where
|
|||||||
|
|
||||||
fn paint(&mut self) {
|
fn paint(&mut self) {
|
||||||
// Drawing the image full-screen first and then other things on top
|
// 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);
|
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
|
// Need to make all the title background black, so the title text is well
|
||||||
// visible
|
// visible
|
||||||
let title_area = self.title.inner().area();
|
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]
|
// Layout needs to hold the Obj to play nice with GC. Obj is resolved to &[u8]
|
||||||
// in every paint pass.
|
// in every paint pass.
|
||||||
|
let buffer_func = move || {
|
||||||
// SAFETY: We expect no existing mutable reference. Resulting reference is
|
// SAFETY: We expect no existing mutable reference. Resulting reference is
|
||||||
// discarded before returning to micropython.
|
// 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()) {
|
let size = match jpeg_info(buffer_func()) {
|
||||||
Some(info) => info.0,
|
Some(info) => info.0,
|
||||||
_ => return Err(value_error!("Invalid image.")),
|
_ => 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(
|
let obj = LayoutObj::new(Frame::centered(
|
||||||
theme::label_title(),
|
theme::label_title(),
|
||||||
title,
|
title,
|
||||||
|
@ -153,14 +153,6 @@ async def apply_settings(msg: ApplySettings) -> Success:
|
|||||||
async def _require_confirm_change_homescreen(homescreen: bytes) -> None:
|
async def _require_confirm_change_homescreen(homescreen: bytes) -> None:
|
||||||
from trezor.ui.layouts import confirm_homescreen
|
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)
|
await confirm_homescreen(homescreen)
|
||||||
|
|
||||||
|
|
||||||
|
@ -393,7 +393,7 @@ async def confirm_homescreen(
|
|||||||
interact(
|
interact(
|
||||||
RustLayout(
|
RustLayout(
|
||||||
trezorui2.confirm_homescreen(
|
trezorui2.confirm_homescreen(
|
||||||
title="SET HOMESCREEN",
|
title="CHANGE HOMESCREEN",
|
||||||
image=image,
|
image=image,
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user