1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-15 12:08:59 +00:00

chore(core): remove empty_right_column field

[no changelog]
This commit is contained in:
cepetr 2024-11-13 11:04:53 +01:00 committed by cepetr
parent c11dc5dcd3
commit 624e95a790
2 changed files with 9 additions and 44 deletions

View File

@ -13,16 +13,11 @@ pub enum ToifFormat {
GrayScaleEH = 3, // even hi GrayScaleEH = 3, // even hi
} }
/// Holding toif data and allowing it to draw itself. /// Holding toif data
/// See https://docs.trezor.io/trezor-firmware/misc/toif.html for data format. /// See https://docs.trezor.io/trezor-firmware/misc/toif.html for data format.
#[derive(PartialEq, Eq, Clone, Copy)] #[derive(PartialEq, Eq, Clone, Copy)]
pub struct Toif<'i> { pub struct Toif<'i> {
data: &'i [u8], 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> { impl<'i> Toif<'i> {
@ -35,15 +30,7 @@ impl<'i> Toif<'i> {
if zdatalen + TOIF_HEADER_LENGTH != data.len() { if zdatalen + TOIF_HEADER_LENGTH != data.len() {
return Err(value_error!(c"Invalid TOIF length.")); return Err(value_error!(c"Invalid TOIF length."));
} }
Ok(Self { Ok(Self { data })
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 { pub const fn format(&self) -> ToifFormat {
@ -64,12 +51,7 @@ impl<'i> Toif<'i> {
} }
pub const fn width(&self) -> i16 { pub const fn width(&self) -> i16 {
let data_width = u16::from_le_bytes([self.data[4], self.data[5]]) as i16; 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 { pub const fn height(&self) -> i16 {
@ -110,11 +92,6 @@ impl Icon {
} }
} }
pub const fn with_empty_right_column(mut self) -> Self {
self.toif.empty_right_column = true;
self
}
/// Create a named icon. /// Create a named icon.
/// The name is only stored in debug builds. /// The name is only stored in debug builds.
pub const fn debug_named(data: &'static [u8], _name: &'static str) -> Self { pub const fn debug_named(data: &'static [u8], _name: &'static str) -> Self {

View File

@ -141,28 +141,16 @@ pub fn long_line_content_with_ellipsis(
} }
/// Create the `Icon` constant with given name and path. /// 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 { macro_rules! include_icon {
($name:ident, $path:expr, empty_right_col = $empty:expr) => {
pub const $name: $crate::ui::display::toif::Icon = if $empty {
$crate::ui::display::toif::Icon::debug_named(
$crate::ui::util::include_res!($path),
stringify!($name),
)
.with_empty_right_column()
} else {
$crate::ui::display::toif::Icon::debug_named(
$crate::ui::util::include_res!($path),
stringify!($name),
)
};
};
// No empty right column by default.
($name:ident, $path:expr) => { ($name:ident, $path:expr) => {
include_icon!($name, $path, empty_right_col = false); pub const $name: $crate::ui::display::toif::Icon =
$crate::ui::display::toif::Icon::debug_named(
$crate::ui::util::include_res!($path),
stringify!($name),
);
}; };
} }
pub(crate) use include_icon; pub(crate) use include_icon;
macro_rules! include_res { macro_rules! include_res {