diff --git a/core/embed/rust/src/ui/display/toif.rs b/core/embed/rust/src/ui/display/toif.rs index c831319e3..250bcbc29 100644 --- a/core/embed/rust/src/ui/display/toif.rs +++ b/core/embed/rust/src/ui/display/toif.rs @@ -156,6 +156,11 @@ pub fn image(image: &Image, center: Point) { #[derive(PartialEq, Eq, Clone, Copy)] pub struct Toif<'i> { data: &'i [u8], + /// Due to toif limitations, image width must be divisible by 2. + /// In cases the actual image is odd-width, it will have empty + /// rightmost column and this flag will make account for it + /// when determining the width and when drawing it. + pub empty_right_column: bool, } impl<'i> Toif<'i> { @@ -168,7 +173,15 @@ impl<'i> Toif<'i> { if zdatalen + TOIF_HEADER_LENGTH != data.len() { return None; } - Some(Self { data }) + Some(Self { + data, + empty_right_column: false, + }) + } + + pub const fn with_empty_right_column(mut self) -> Self { + self.empty_right_column = true; + self } pub const fn format(&self) -> ToifFormat { @@ -189,7 +202,12 @@ impl<'i> Toif<'i> { } pub const fn width(&self) -> i16 { - u16::from_le_bytes([self.data[4], self.data[5]]) as i16 + let data_width = u16::from_le_bytes([self.data[4], self.data[5]]) as i16; + if self.empty_right_column { + data_width - 1 + } else { + data_width + } } pub const fn height(&self) -> i16 { @@ -245,6 +263,11 @@ impl Icon { } } + pub const fn with_empty_right_column(mut self) -> Self { + self.toif.empty_right_column = true; + self + } + /// Create a named icon. /// The name is only stored in debug builds. pub const fn debug_named(data: &'static [u8], name: &'static str) -> Self { diff --git a/core/embed/rust/src/ui/model_tr/component/homescreen.rs b/core/embed/rust/src/ui/model_tr/component/homescreen.rs index 19a397c0b..c4c345690 100644 --- a/core/embed/rust/src/ui/model_tr/component/homescreen.rs +++ b/core/embed/rust/src/ui/model_tr/component/homescreen.rs @@ -97,14 +97,7 @@ where fn paint_warning_icons_in_top_corners(&self) { let warning_icon = theme::ICON_WARNING; warning_icon.draw(AREA.top_left(), geometry::TOP_LEFT, theme::FG, theme::BG); - // Needs x+1 Offset to compensate for empty right column (icon needs to be - // even-wide) - warning_icon.draw( - AREA.top_right() + Offset::x(1), - geometry::TOP_RIGHT, - theme::FG, - theme::BG, - ); + warning_icon.draw(AREA.top_right(), geometry::TOP_RIGHT, theme::FG, theme::BG); } fn event_usb(&mut self, ctx: &mut EventCtx, event: Event) { diff --git a/core/embed/rust/src/ui/util.rs b/core/embed/rust/src/ui/util.rs index 1d02e20bc..88efa3c52 100644 --- a/core/embed/rust/src/ui/util.rs +++ b/core/embed/rust/src/ui/util.rs @@ -160,9 +160,20 @@ pub fn long_line_content_with_ellipsis( } #[macro_export] +/// Create the `Icon` constant with given name and path. +/// Possibly users can supply `true` as a third argument and this +/// will signify that the icon has empty right column. macro_rules! include_icon { + ($name:ident, $path:expr, empty_right_col = $empty:expr) => { + pub const $name: Icon = if $empty { + Icon::debug_named(include_res!($path), stringify!($name)).with_empty_right_column() + } else { + Icon::debug_named(include_res!($path), stringify!($name)) + }; + }; + // No empty right column by default. ($name:ident, $path:expr) => { - pub const $name: Icon = Icon::debug_named(include_res!($path), stringify!($name)); + include_icon!($name, $path, empty_right_col = false); }; }