mirror of
https://github.com/yuri91/ili9341-rs.git
synced 2024-11-21 22:30:59 +00:00
Merge pull request #17 from KarlK90/clear
Implement optimized DrawTarget::clear
This commit is contained in:
commit
0b1ba5c7de
1 changed files with 15 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
||||||
use crate::{Ili9341, Interface, OutputPin};
|
use crate::{Ili9341, Interface, OutputPin};
|
||||||
|
|
||||||
use core::fmt::Debug;
|
use core::{fmt::Debug, iter};
|
||||||
|
|
||||||
use embedded_graphics::{
|
use embedded_graphics::{
|
||||||
drawable::Pixel,
|
drawable::Pixel,
|
||||||
|
@ -26,6 +26,7 @@ where
|
||||||
fn size(&self) -> Size {
|
fn size(&self) -> Size {
|
||||||
Size::new(self.width as u32, self.height as u32)
|
Size::new(self.width as u32, self.height as u32)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_pixel(&mut self, pixel: Pixel<Rgb565>) -> Result<(), Self::Error> {
|
fn draw_pixel(&mut self, pixel: Pixel<Rgb565>) -> Result<(), Self::Error> {
|
||||||
let Pixel(pos, color) = pixel;
|
let Pixel(pos, color) = pixel;
|
||||||
|
|
||||||
|
@ -41,6 +42,7 @@ where
|
||||||
&[RawU16::from(color).into_inner()],
|
&[RawU16::from(color).into_inner()],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_rectangle(
|
fn draw_rectangle(
|
||||||
&mut self,
|
&mut self,
|
||||||
item: &Styled<Rectangle, PrimitiveStyle<Rgb565>>,
|
item: &Styled<Rectangle, PrimitiveStyle<Rgb565>>,
|
||||||
|
@ -78,4 +80,16 @@ where
|
||||||
.map(|p| RawU16::from(p.1).into_inner()),
|
.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),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue