Files
aligned
app
arrayvec
as_slice
bare_metal
byteorder
cfg_if
cortex_m
cortex_m_rt
cstr_core
cty
druid
druid_shell
embedded_graphics
embedded_hal
generic_array
hash32
heapless
introsort
kurbo
libchip8
libm
log
memchr
mynewt
nb
num_traits
piet
piet_common
piet_embedded_graphics
r0
st7735_lcd
stable_deref_trait
typenum
unicode_segmentation
vcell
void
volatile_register
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use crate::drawable::{Dimensions, Pixel};
use crate::prelude::*;
use crate::{Drawing, SizedDrawing};

/// Mock display for use in tests and some doc examples. Do not use directly!
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Copy, Clone)]
pub struct MockDisplay<P>(pub [[P; 24]; 16]);

impl MockDisplay<u8> {
    pub fn new(bytes: [[u8; 24]; 16]) -> Self {
        Self(bytes)
    }
}

impl MockDisplay<u16> {
    pub fn new(bytes: [[u16; 24]; 16]) -> Self {
        Self(bytes)
    }
}

impl MockDisplay<u32> {
    pub fn new(bytes: [[u32; 24]; 16]) -> Self {
        Self(bytes)
    }
}

impl Default for MockDisplay<u8> {
    fn default() -> Self {
        MockDisplay::<u8>::new([[0; 24]; 16])
    }
}

impl Default for MockDisplay<u16> {
    fn default() -> Self {
        MockDisplay::<u16>::new([[0u16; 24]; 16])
    }
}

impl Default for MockDisplay<u32> {
    fn default() -> Self {
        MockDisplay::<u32>::new([[0u32; 24]; 16])
    }
}

impl<P> Drawing<P> for MockDisplay<P>
where
    P: PixelColor,
{
    fn draw<T>(&mut self, item_pixels: T)
    where
        T: IntoIterator<Item = Pixel<P>>,
    {
        for Pixel(coord, color) in item_pixels {
            if coord[0] >= 24 || coord[1] >= 16 {
                continue;
            }
            self.0[coord[1] as usize][coord[0] as usize] = color;
        }
    }
}

impl<P> SizedDrawing<P> for MockDisplay<P>
where
    P: PixelColor,
{
    fn draw_sized<T>(&mut self, item: T)
    where
        T: IntoIterator<Item = Pixel<P>> + Dimensions,
    {
        // Use `top_left()`, `size()`, etc methods defined on Dimensions to set draw area here

        let offs = item.top_left().to_unsigned();

        for Pixel(coord, color) in item {
            // Undo any translations applied to this object
            let coord_untransformed = coord - offs;

            self.0[coord_untransformed[1] as usize][coord_untransformed[0] as usize] = color;
        }
    }
}

pub type Display = MockDisplay<u8>;
pub type Display16Bpp = MockDisplay<u16>;
pub type Display32Bpp = MockDisplay<u32>;