Module embedded_graphics::pixelcolor
source · Expand description
Pixel color trait
Driver implementers should implement PixelColor
for the struct used to store pixels for the
target display. An example can be found in
the simulator. A simpler example looks like this:
use embedded_graphics::drawable::Pixel;
use embedded_graphics::unsignedcoord::UnsignedCoord;
use embedded_graphics::pixelcolor::PixelColor;
// `Copy` and `Clone` are bounds on `PixelColor` and are required.
// `PartialEq` is for the `assert_eq!()` later in this example.
// `Debug` is for convenience :)
#[derive(Copy, Clone, PartialEq, Debug)]
struct CustomPixelColor {
pub value: u16,
}
impl CustomPixelColor {
fn new(color: u16) -> Self {
CustomPixelColor { value: color }
}
}
impl PixelColor for CustomPixelColor {}
// `From<u8>` is a bound on `PixelColor` so must be implemented for your pixel colour type
impl From<u8> for CustomPixelColor {
fn from(other: u8) -> Self {
CustomPixelColor {
value: other as u16,
}
}
}
fn main() {
let colour = CustomPixelColor::new(127u16);
assert_eq!(colour.value, 127u16);
}
Structs
Pixel wrapper around
u8
typePixel wrapper around
u16
typePixel wrapper around
u32
typeTraits
Pixel color