mirror of
https://github.com/Feliix42/ssd1675.git
synced 2024-11-21 18:36:30 +00:00
Merge pull request #20 from ferristseng/ferristseng/eg-07
Upgrade to embedded-graphics 0.7
This commit is contained in:
commit
61b6ea9d59
2 changed files with 42 additions and 29 deletions
10
Cargo.toml
10
Cargo.toml
|
@ -18,23 +18,23 @@ travis-ci = { repository = "wezm/ssd1675" }
|
|||
codecov = { repository = "wezm/ssd1675" }
|
||||
|
||||
[dependencies]
|
||||
libm = "0.2.1"
|
||||
libm = "0.2.2"
|
||||
|
||||
[dependencies.embedded-hal]
|
||||
features = ["unproven"]
|
||||
version = "0.2.3"
|
||||
version = "0.2.6"
|
||||
|
||||
[dependencies.embedded-graphics]
|
||||
optional = true
|
||||
version = "0.6.2"
|
||||
version = "0.7.1"
|
||||
|
||||
[dependencies.linux-embedded-hal]
|
||||
optional = true
|
||||
version = "0.3.0"
|
||||
version = "0.3.2"
|
||||
|
||||
[dependencies.profont]
|
||||
optional = true
|
||||
version = "0.4.0"
|
||||
version = "0.5.0"
|
||||
|
||||
[features]
|
||||
default = ["graphics"]
|
||||
|
|
|
@ -130,25 +130,34 @@ extern crate embedded_graphics;
|
|||
use self::embedded_graphics::prelude::*;
|
||||
|
||||
#[cfg(feature = "graphics")]
|
||||
impl<'a, I> DrawTarget<Color> for GraphicDisplay<'a, I>
|
||||
impl<'a, I> DrawTarget for GraphicDisplay<'a, I>
|
||||
where
|
||||
I: DisplayInterface,
|
||||
{
|
||||
type Color = Color;
|
||||
type Error = core::convert::Infallible;
|
||||
|
||||
fn draw_pixel(
|
||||
&mut self,
|
||||
Pixel(Point { x, y }, color): Pixel<Color>,
|
||||
) -> Result<(), Self::Error> {
|
||||
fn draw_iter<Iter>(&mut self, pixels: Iter) -> Result<(), Self::Error>
|
||||
where
|
||||
Iter: IntoIterator<Item = Pixel<Self::Color>>,
|
||||
{
|
||||
let sz = self.size();
|
||||
for Pixel(Point { x, y }, color) in pixels {
|
||||
let x = x as u32;
|
||||
let y = y as u32;
|
||||
if x < sz.width && y < sz.height {
|
||||
self.set_pixel(x, y, color)
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "graphics")]
|
||||
impl<'a, I> OriginDimensions for GraphicDisplay<'a, I>
|
||||
where
|
||||
I: DisplayInterface,
|
||||
{
|
||||
fn size(&self) -> Size {
|
||||
match self.rotation() {
|
||||
Rotation::Rotate0 | Rotation::Rotate180 => {
|
||||
|
@ -163,7 +172,7 @@ where
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use self::embedded_graphics::{egrectangle, primitive_style};
|
||||
use self::embedded_graphics::primitives::{PrimitiveStyleBuilder, Rectangle};
|
||||
use super::*;
|
||||
use {Builder, Color, Dimensions, Display, DisplayInterface, GraphicDisplay, Rotation};
|
||||
|
||||
|
@ -265,10 +274,12 @@ mod tests {
|
|||
let mut display =
|
||||
GraphicDisplay::new(build_mock_display(), &mut black_buffer, &mut red_buffer);
|
||||
|
||||
egrectangle!(
|
||||
top_left = (0, 0),
|
||||
bottom_right = (2, 2),
|
||||
style = primitive_style!(stroke_color = Color::White, stroke_width = 1)
|
||||
Rectangle::with_corners(Point::new(0, 0), Point::new(2, 2))
|
||||
.into_styled(
|
||||
PrimitiveStyleBuilder::new()
|
||||
.stroke_color(Color::White)
|
||||
.stroke_width(1)
|
||||
.build(),
|
||||
)
|
||||
.draw(&mut display)
|
||||
.unwrap()
|
||||
|
@ -294,10 +305,12 @@ mod tests {
|
|||
let mut display =
|
||||
GraphicDisplay::new(build_mock_display(), &mut black_buffer, &mut red_buffer);
|
||||
|
||||
egrectangle!(
|
||||
top_left = (0, 0),
|
||||
bottom_right = (2, 2),
|
||||
style = primitive_style!(stroke_color = Color::Red, stroke_width = 1)
|
||||
Rectangle::with_corners(Point::new(0, 0), Point::new(2, 2))
|
||||
.into_styled(
|
||||
PrimitiveStyleBuilder::new()
|
||||
.stroke_color(Color::Red)
|
||||
.stroke_width(1)
|
||||
.build(),
|
||||
)
|
||||
.draw(&mut display)
|
||||
.unwrap();
|
||||
|
|
Loading…
Reference in a new issue