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
86
use embedded_graphics::{
    prelude::{DrawTarget, PixelColor},
    primitives::StyledDrawable,
};
use embedded_layout::{
    object_chain::ChainElement,
    prelude::{Chain, Link},
};

use crate::{
    interaction::InteractionController,
    selection_indicator::{style::IndicatorStyle, SelectionIndicatorController},
    MenuStyle,
};

pub trait StyledMenuItem<C, S, IT, P>:
    StyledDrawable<MenuStyle<C, S, IT, P>, Color = C, Output = ()>
where
    C: PixelColor,
    S: IndicatorStyle,
    IT: InteractionController,
    P: SelectionIndicatorController,
{
}
impl<T, C, S, IT, P> StyledMenuItem<C, S, IT, P> for T
where
    T: StyledDrawable<MenuStyle<C, S, IT, P>, Color = C, Output = ()>,
    C: PixelColor,
    S: IndicatorStyle,
    IT: InteractionController,
    P: SelectionIndicatorController,
{
}

impl<C, S, V, VC, IT, P> StyledDrawable<MenuStyle<C, S, IT, P>> for Link<V, VC>
where
    C: PixelColor,
    V: StyledMenuItem<C, S, IT, P>,
    VC: ChainElement + StyledMenuItem<C, S, IT, P>,
    S: IndicatorStyle,
    IT: InteractionController,
    P: SelectionIndicatorController,
{
    type Color = C;
    type Output = ();

    #[inline]
    fn draw_styled<D>(
        &self,
        style: &MenuStyle<Self::Color, S, IT, P>,
        display: &mut D,
    ) -> Result<(), D::Error>
    where
        D: DrawTarget<Color = Self::Color>,
    {
        self.object.draw_styled(style, display)?;
        self.parent.draw_styled(style, display)?;

        Ok(())
    }
}

impl<C, S, V, IT, P> StyledDrawable<MenuStyle<C, S, IT, P>> for Chain<V>
where
    C: PixelColor,
    V: StyledMenuItem<C, S, IT, P>,
    S: IndicatorStyle,
    IT: InteractionController,
    P: SelectionIndicatorController,
{
    type Color = C;
    type Output = ();

    #[inline]
    fn draw_styled<D>(
        &self,
        style: &MenuStyle<Self::Color, S, IT, P>,
        display: &mut D,
    ) -> Result<(), D::Error>
    where
        D: DrawTarget<Color = Self::Color>,
    {
        self.object.draw_styled(style, display)?;
        Ok(())
    }
}