mirror of
https://github.com/Feliix42/ssd1675.git
synced 2024-11-24 03:36:30 +00:00
migrate code from embedded-graphics 0.6 to 0.7
This commit is contained in:
parent
4852726410
commit
74735f77e8
1 changed files with 37 additions and 24 deletions
|
@ -130,25 +130,34 @@ extern crate embedded_graphics;
|
||||||
use self::embedded_graphics::prelude::*;
|
use self::embedded_graphics::prelude::*;
|
||||||
|
|
||||||
#[cfg(feature = "graphics")]
|
#[cfg(feature = "graphics")]
|
||||||
impl<'a, I> DrawTarget<Color> for GraphicDisplay<'a, I>
|
impl<'a, I> DrawTarget for GraphicDisplay<'a, I>
|
||||||
where
|
where
|
||||||
I: DisplayInterface,
|
I: DisplayInterface,
|
||||||
{
|
{
|
||||||
|
type Color = Color;
|
||||||
type Error = core::convert::Infallible;
|
type Error = core::convert::Infallible;
|
||||||
|
|
||||||
fn draw_pixel(
|
fn draw_iter<Iter>(&mut self, pixels: Iter) -> Result<(), Self::Error>
|
||||||
&mut self,
|
where
|
||||||
Pixel(Point { x, y }, color): Pixel<Color>,
|
Iter: IntoIterator<Item = Pixel<Self::Color>>,
|
||||||
) -> Result<(), Self::Error> {
|
{
|
||||||
let sz = self.size();
|
let sz = self.size();
|
||||||
let x = x as u32;
|
for Pixel(Point { x, y }, color) in pixels {
|
||||||
let y = y as u32;
|
let x = x as u32;
|
||||||
if x < sz.width && y < sz.height {
|
let y = y as u32;
|
||||||
self.set_pixel(x, y, color)
|
if x < sz.width && y < sz.height {
|
||||||
|
self.set_pixel(x, y, color)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "graphics")]
|
||||||
|
impl<'a, I> OriginDimensions for GraphicDisplay<'a, I>
|
||||||
|
where
|
||||||
|
I: DisplayInterface,
|
||||||
|
{
|
||||||
fn size(&self) -> Size {
|
fn size(&self) -> Size {
|
||||||
match self.rotation() {
|
match self.rotation() {
|
||||||
Rotation::Rotate0 | Rotation::Rotate180 => {
|
Rotation::Rotate0 | Rotation::Rotate180 => {
|
||||||
|
@ -163,7 +172,7 @@ where
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use self::embedded_graphics::{egrectangle, primitive_style};
|
use self::embedded_graphics::primitives::{PrimitiveStyleBuilder, Rectangle};
|
||||||
use super::*;
|
use super::*;
|
||||||
use {Builder, Color, Dimensions, Display, DisplayInterface, GraphicDisplay, Rotation};
|
use {Builder, Color, Dimensions, Display, DisplayInterface, GraphicDisplay, Rotation};
|
||||||
|
|
||||||
|
@ -265,13 +274,15 @@ mod tests {
|
||||||
let mut display =
|
let mut display =
|
||||||
GraphicDisplay::new(build_mock_display(), &mut black_buffer, &mut red_buffer);
|
GraphicDisplay::new(build_mock_display(), &mut black_buffer, &mut red_buffer);
|
||||||
|
|
||||||
egrectangle!(
|
Rectangle::with_corners(Point::new(0, 0), Point::new(2, 2))
|
||||||
top_left = (0, 0),
|
.into_styled(
|
||||||
bottom_right = (2, 2),
|
PrimitiveStyleBuilder::new()
|
||||||
style = primitive_style!(stroke_color = Color::White, stroke_width = 1)
|
.stroke_color(Color::White)
|
||||||
)
|
.stroke_width(1)
|
||||||
.draw(&mut display)
|
.build(),
|
||||||
.unwrap()
|
)
|
||||||
|
.draw(&mut display)
|
||||||
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
|
@ -294,13 +305,15 @@ mod tests {
|
||||||
let mut display =
|
let mut display =
|
||||||
GraphicDisplay::new(build_mock_display(), &mut black_buffer, &mut red_buffer);
|
GraphicDisplay::new(build_mock_display(), &mut black_buffer, &mut red_buffer);
|
||||||
|
|
||||||
egrectangle!(
|
Rectangle::with_corners(Point::new(0, 0), Point::new(2, 2))
|
||||||
top_left = (0, 0),
|
.into_styled(
|
||||||
bottom_right = (2, 2),
|
PrimitiveStyleBuilder::new()
|
||||||
style = primitive_style!(stroke_color = Color::Red, stroke_width = 1)
|
.stroke_color(Color::Red)
|
||||||
)
|
.stroke_width(1)
|
||||||
.draw(&mut display)
|
.build(),
|
||||||
.unwrap();
|
)
|
||||||
|
.draw(&mut display)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
|
|
Loading…
Reference in a new issue