|
|
|
@ -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 {
|
|
|
|
|