Merge pull request #17 from KarlK90/clear

Implement optimized DrawTarget::clear
This commit is contained in:
Yuri Iozzelli 2020-06-06 09:54:06 +02:00 committed by GitHub
commit 0b1ba5c7de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,6 @@
use crate::{Ili9341, Interface, OutputPin};
use core::fmt::Debug;
use core::{fmt::Debug, iter};
use embedded_graphics::{
drawable::Pixel,
@ -26,6 +26,7 @@ where
fn size(&self) -> Size {
Size::new(self.width as u32, self.height as u32)
}
fn draw_pixel(&mut self, pixel: Pixel<Rgb565>) -> Result<(), Self::Error> {
let Pixel(pos, color) = pixel;
@ -41,6 +42,7 @@ where
&[RawU16::from(color).into_inner()],
)
}
fn draw_rectangle(
&mut self,
item: &Styled<Rectangle, PrimitiveStyle<Rgb565>>,
@ -78,4 +80,16 @@ where
.map(|p| RawU16::from(p.1).into_inner()),
)
}
fn clear(&mut self, color: Rgb565) -> Result<(), Self::Error> {
let color = RawU16::from(color).into_inner();
self.draw_iter(
0,
0,
(self.width - 1) as u16,
(self.height - 1) as u16,
iter::repeat(color).take(self.width * self.height),
)
}
}