mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-06 05:21:05 +00:00
feat(core/rust): introduce RawImage shape
[no changelog]
This commit is contained in:
parent
89ae44ebfa
commit
e579254f7a
@ -295,6 +295,7 @@ impl<'a> Drop for Bitmap<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
pub struct BitmapView<'a> {
|
pub struct BitmapView<'a> {
|
||||||
pub bitmap: &'a Bitmap<'a>,
|
pub bitmap: &'a Bitmap<'a>,
|
||||||
pub offset: Offset,
|
pub offset: Offset,
|
||||||
|
@ -10,6 +10,7 @@ mod display;
|
|||||||
#[cfg(feature = "ui_jpeg_decoder")]
|
#[cfg(feature = "ui_jpeg_decoder")]
|
||||||
mod jpeg;
|
mod jpeg;
|
||||||
mod qrcode;
|
mod qrcode;
|
||||||
|
mod rawimage;
|
||||||
mod render;
|
mod render;
|
||||||
mod text;
|
mod text;
|
||||||
mod toif;
|
mod toif;
|
||||||
@ -29,6 +30,7 @@ pub use display::render_on_display;
|
|||||||
#[cfg(feature = "ui_jpeg_decoder")]
|
#[cfg(feature = "ui_jpeg_decoder")]
|
||||||
pub use jpeg::JpegImage;
|
pub use jpeg::JpegImage;
|
||||||
pub use qrcode::QrImage;
|
pub use qrcode::QrImage;
|
||||||
|
pub use rawimage::RawImage;
|
||||||
pub use render::{DirectRenderer, ProgressiveRenderer, Renderer};
|
pub use render::{DirectRenderer, ProgressiveRenderer, Renderer};
|
||||||
pub use text::Text;
|
pub use text::Text;
|
||||||
pub use toif::ToifImage;
|
pub use toif::ToifImage;
|
||||||
|
45
core/embed/rust/src/ui/shape/rawimage.rs
Normal file
45
core/embed/rust/src/ui/shape/rawimage.rs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
use crate::ui::geometry::Rect;
|
||||||
|
|
||||||
|
use super::{BitmapView, Canvas, DrawingCache, Renderer, Shape, ShapeClone};
|
||||||
|
|
||||||
|
use without_alloc::alloc::LocalAllocLeakExt;
|
||||||
|
|
||||||
|
/// A shape for rendering compressed TOIF images.
|
||||||
|
pub struct RawImage<'a> {
|
||||||
|
/// Destination area
|
||||||
|
area: Rect,
|
||||||
|
// Bitmap reference
|
||||||
|
bitmap: BitmapView<'a>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> RawImage<'a> {
|
||||||
|
pub fn new(area: Rect, bitmap: BitmapView<'a>) -> Self {
|
||||||
|
Self { area, bitmap }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn render(self, renderer: &mut impl Renderer<'a>) {
|
||||||
|
renderer.render_shape(self);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Shape<'a> for RawImage<'a> {
|
||||||
|
fn bounds(&self) -> Rect {
|
||||||
|
self.area
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cleanup(&mut self, _cache: &DrawingCache<'a>) {}
|
||||||
|
|
||||||
|
fn draw(&mut self, canvas: &mut dyn Canvas, _cache: &DrawingCache<'a>) {
|
||||||
|
canvas.draw_bitmap(self.area, self.bitmap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> ShapeClone<'a> for RawImage<'a> {
|
||||||
|
fn clone_at_bump<T>(self, bump: &'a T) -> Option<&'a mut dyn Shape<'a>>
|
||||||
|
where
|
||||||
|
T: LocalAllocLeakExt<'a>,
|
||||||
|
{
|
||||||
|
let clone = bump.alloc_t()?;
|
||||||
|
Some(clone.uninit.init(RawImage { ..self }))
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user