cargo fmt

This commit is contained in:
Yu Chen 2022-06-20 23:32:27 +08:00
parent 45c2caf564
commit a6c8f4de34
13 changed files with 181 additions and 135 deletions

View file

@ -1,7 +1,9 @@
use alloc::{vec::Vec, sync::Arc};
use alloc::{sync::Arc, vec::Vec};
use embedded_graphics::{
image::Image,
prelude::{Point, Size}, pixelcolor::Rgb888, Drawable,
pixelcolor::Rgb888,
prelude::{Point, Size},
Drawable,
};
use tinybmp::Bmp;
@ -10,21 +12,25 @@ use crate::{
sync::UPIntrFreeCell,
};
use super::{Graphics, Component};
use super::{Component, Graphics};
pub struct ImageComp {
inner: UPIntrFreeCell<ImageInner>,
}
pub struct ImageInner {
image: &'static [u8],
graphic: Graphics,
parent: Option<Arc<dyn Component>>
parent: Option<Arc<dyn Component>>,
}
impl ImageComp {
pub fn new(size: Size, point: Point, v: &'static [u8],parent: Option<Arc<dyn Component>>) -> Self {
pub fn new(
size: Size,
point: Point,
v: &'static [u8],
parent: Option<Arc<dyn Component>>,
) -> Self {
unsafe {
ImageComp {
inner: UPIntrFreeCell::new(ImageInner {
@ -44,21 +50,23 @@ impl ImageComp {
impl Component for ImageComp {
fn paint(&self) {
let mut inner = self.inner.exclusive_access();
let b = unsafe {
let b = unsafe {
let len = inner.image.len();
let ptr = inner.image
.as_ptr() as *const u8;
let ptr = inner.image.as_ptr() as *const u8;
core::slice::from_raw_parts(ptr, len)
};
let bmp = Bmp::<Rgb888>::from_slice(b).unwrap();
let point = match &inner.parent {
Some(parent) => {
let (_, point) = parent.bound();
Point::new(point.x + inner.graphic.point.x, point.y + inner.graphic.point.y)
Point::new(
point.x + inner.graphic.point.x,
point.y + inner.graphic.point.y,
)
}
None => inner.graphic.point,
};
Image::new(&bmp, point,).draw(&mut inner.graphic);
Image::new(&bmp, point).draw(&mut inner.graphic);
}
fn add(&self, comp: alloc::sync::Arc<dyn Component>) {