console_display/pixel/
color_pixel.rs

1use crate::{
2    color::{
3        Color,
4        TerminalColor,
5    },
6    impl_from_color_pixel_for_datacell,
7    impl_getters,
8    impl_getters_mut,
9    impl_new,
10    pixel::{
11        Pixel,
12        monochrome_pixel::{
13            HexPixel,
14            OctPixel,
15            QuadPixel,
16        },
17    },
18    widget::DataCell,
19};
20
21/// Represents a singular pixel implementing the [`Pixel`] trait.
22#[derive(Clone, Copy)]
23pub struct ColorSinglePixel {
24    pixels: [TerminalColor; 1],
25}
26
27impl Pixel for ColorSinglePixel {
28    type U = TerminalColor;
29
30    const WIDTH: usize = 1;
31
32    const HEIGHT: usize = 1;
33
34    impl_getters!(pixels: [Self::U; Self::WIDTH * Self::HEIGHT]);
35
36    impl_getters_mut!(pixels: [Self::U; Self::WIDTH * Self::HEIGHT]);
37
38    impl_new!(Self, pixels: [Self::U; 1]);
39}
40
41impl From<ColorSinglePixel> for DataCell {
42    fn from(val: ColorSinglePixel) -> Self {
43        Self {
44            character: '█',
45            foreground: val.pixels[0],
46            background: val.pixels[0],
47        }
48    }
49}
50
51#[derive(Clone, Copy)]
52pub struct ColorDualPixel {
53    pixels: [TerminalColor; 2],
54}
55
56impl Pixel for ColorDualPixel {
57    type U = TerminalColor;
58
59    const WIDTH: usize = 1;
60
61    const HEIGHT: usize = 2;
62
63    impl_getters!(pixels: [Self::U; Self::WIDTH * Self::HEIGHT]);
64
65    impl_getters_mut!(pixels: [Self::U; Self::WIDTH * Self::HEIGHT]);
66
67    impl_new!(Self, pixels: [Self::U; 2]);
68}
69
70impl From<ColorDualPixel> for DataCell {
71    fn from(val: ColorDualPixel) -> Self {
72        Self {
73            character: '▀',
74            foreground: val.pixels[0],
75            background: val.pixels[1],
76        }
77    }
78}
79
80#[derive(Clone, Copy)]
81pub struct ColorQuadPixel {
82    pixels: [TerminalColor; 4],
83}
84
85impl Pixel for ColorQuadPixel {
86    type U = TerminalColor;
87
88    const WIDTH: usize = 2;
89
90    const HEIGHT: usize = 2;
91
92    impl_getters!(pixels: [Self::U; Self::WIDTH * Self::HEIGHT]);
93
94    impl_getters_mut!(pixels: [Self::U; Self::WIDTH * Self::HEIGHT]);
95
96    impl_new!(Self, pixels: [Self::U; 4]);
97}
98
99impl_from_color_pixel_for_datacell!(ColorQuadPixel, QuadPixel);
100
101#[derive(Clone, Copy)]
102pub struct ColorHexPixel {
103    pixels: [TerminalColor; 6],
104}
105
106impl Pixel for ColorHexPixel {
107    type U = TerminalColor;
108
109    const WIDTH: usize = 2;
110
111    const HEIGHT: usize = 3;
112
113    impl_getters!(pixels: [Self::U; Self::WIDTH * Self::HEIGHT]);
114
115    impl_getters_mut!(pixels: [Self::U; Self::WIDTH * Self::HEIGHT]);
116
117    impl_new!(Self, pixels: [Self::U; 6]);
118}
119
120impl_from_color_pixel_for_datacell!(ColorHexPixel, HexPixel);
121
122#[derive(Clone, Copy)]
123pub struct ColorOctPixel {
124    pixels: [TerminalColor; 8],
125}
126
127impl Pixel for ColorOctPixel {
128    type U = TerminalColor;
129
130    const WIDTH: usize = 2;
131
132    const HEIGHT: usize = 4;
133
134    impl_getters!(pixels: [Self::U; Self::WIDTH * Self::HEIGHT]);
135
136    impl_getters_mut!(pixels: [Self::U; Self::WIDTH * Self::HEIGHT]);
137
138    impl_new!(Self, pixels: [Self::U; 8]);
139}
140
141impl_from_color_pixel_for_datacell!(ColorOctPixel, OctPixel);