macro_rules! impl_traits_for_canvas {
($i:ident[ $( $a:tt $(: $b:tt)? ),* ]) => {
impl<$($a $(: $b)?),*> std::ops::Index<Pad> for $i<$($a),*> {
type Output = Color;
fn index(&self, pad: Pad) -> &Color {
let (x, y) = pad.to_u32().expect("Pad coordinates out of bounds");
self.low_level_get(x, y).expect("Pad coordinates out of bounds")
}
}
impl<$($a $(: $b)?),*> std::ops::IndexMut<Pad> for $i<$($a),*> {
fn index_mut(&mut self, pad: Pad) -> &mut Color {
let (x, y) = pad.to_u32().expect("Pad coordinates out of bounds");
self.low_level_get_pending_mut(x, y).expect("Pad coordinates out of bounds")
}
}
#[cfg(feature = "embedded-graphics")]
mod eg {
pub use embedded_graphics::{
prelude::*,
draw_target::DrawTarget,
geometry::Dimensions,
pixelcolor::{Rgb888, RgbColor},
primitives::rectangle::Rectangle,
};
}
#[cfg(feature = "embedded-graphics")]
impl<$($a $(: $b)?),*> eg::Dimensions for $i<$($a),*> {
fn bounding_box(&self) -> eg::Rectangle {
eg::Rectangle::new(
eg::Point::new(0, 0),
eg::Size::from(Canvas::bounding_box(self)),
)
}
}
#[cfg(feature = "embedded-graphics")]
impl<$($a $(: $b)?),*> eg::DrawTarget for $i<$($a),*> {
type Color = eg::Rgb888;
type Error = std::convert::Infallible;
fn draw_iter<I: IntoIterator<Item = eg::Pixel<Self::Color>>>(
&mut self,
pixels: I,
) -> Result<(), std::convert::Infallible> {
for eg::Pixel(coord, color) in pixels.into_iter() {
let _ = self.set(Pad { x: coord.x, y: coord.y }, color.into());
}
Ok(())
}
}
}
}
mod iterator;
pub use iterator::*;
mod layout;
pub use layout::*;
mod generic;
pub use generic::*;
mod color;
pub use color::*;
#[allow(clippy::module_inception)]
mod canvas;
pub use canvas::*;
mod padded;
pub use padded::*;
mod pad;
pub use pad::*;
mod mock;
pub use mock::*;