1use crate::{
2 color::TerminalColor,
3 impl_from_mono_chrome_pixel_for_datacell,
4 pixel::Pixel,
5};
6
7use crate::{
8 impl_getters,
9 impl_getters_mut,
10 impl_new,
11 widget::DataCell,
12};
13
14#[derive(Clone, Copy)]
16pub struct SinglePixel {
17 pixels: [bool; 1],
18}
19
20impl SinglePixel {
21 #[must_use]
50 pub const fn character(self) -> char {
51 if self.pixels[0] { '█' } else { ' ' }
52 }
53}
54
55impl Pixel for SinglePixel {
56 type U = bool;
57
58 const WIDTH: usize = 1;
59
60 const HEIGHT: usize = 1;
61
62 impl_getters!(pixels: [bool; 1]);
63
64 impl_getters_mut!(pixels: [bool; 1]);
65
66 impl_new!(SinglePixel, pixels: [bool; 1]);
67}
68
69impl_from_mono_chrome_pixel_for_datacell!(SinglePixel);
70
71#[derive(Clone, Copy)]
73pub struct DualPixel {
74 pixels: [bool; 2],
75}
76
77#[rustfmt::skip]
81impl DualPixel {
82 #[rustfmt::skip]
83 const CHARS: [char; 4] = [
84 ' ', '▀',
85 '▄', '█',
86 ];
87
88 #[rustfmt::skip]
89 const fn index(self) -> usize {
90 (self.pixels[0] as usize) |
91 (self.pixels[1] as usize) << 1
92 }
93
94 #[must_use]
124 pub const fn character(self) -> char {
125 Self::CHARS[self.index()]
126 }
127}
128
129impl Pixel for DualPixel {
130 type U = bool;
131
132 const WIDTH: usize = 1;
133
134 const HEIGHT: usize = 2;
135
136 impl_getters!(pixels: [bool; 2]);
137
138 impl_getters_mut!(pixels: [bool; 2]);
139
140 impl_new!(DualPixel, pixels: [bool; 2]);
141}
142
143impl_from_mono_chrome_pixel_for_datacell!(DualPixel);
144
145#[derive(Clone, Copy)]
147pub struct QuadPixel {
148 pixels: [bool; 4],
149}
150
151#[rustfmt::skip]
155impl QuadPixel {
156 #[rustfmt::skip]
157 const CHARS: [char; 16] = [
158 ' ', '▘', '▝', '▀',
159 '▖', '▌', '▞', '▛',
160 '▗', '▚', '▐', '▜',
161 '▄', '▙', '▟', '█',
162 ];
163
164 #[rustfmt::skip]
165 const fn index(self) -> usize {
166 (self.pixels[0] as usize) |
167 (self.pixels[1] as usize) << 1 |
168 (self.pixels[2] as usize) << 2 |
169 (self.pixels[3] as usize) << 3
170 }
171
172 #[must_use]
193 pub const fn character(self) -> char {
194 Self::CHARS[self.index()]
195 }
196}
197
198impl Pixel for QuadPixel {
199 type U = bool;
200
201 const WIDTH: usize = 2;
202
203 const HEIGHT: usize = 2;
204
205 impl_getters!(pixels: [bool; 4]);
206
207 impl_getters_mut!(pixels: [bool; 4]);
208
209 impl_new!(QuadPixel, pixels: [bool; 4]);
210}
211
212impl_from_mono_chrome_pixel_for_datacell!(QuadPixel);
213
214#[derive(Clone, Copy)]
216pub struct HexPixel {
217 pixels: [bool; 6],
218}
219
220#[rustfmt::skip]
224impl HexPixel {
225 #[rustfmt::skip]
226 const CHARS: [char; 64] = [
227 ' ', '🬀', '🬁', '🬂', '🬃', '🬄', '🬅', '🬆', '🬇', '🬈', '🬉', '🬊', '🬋', '🬌', '🬍', '🬎',
228 '🬏', '🬐', '🬑', '🬒', '🬓', '▌', '🬔', '🬕', '🬖', '🬗', '🬘', '🬙', '🬚', '🬛', '🬜', '🬝',
229 '🬞', '🬟', '🬠', '🬡', '🬢', '🬣', '🬤', '🬥', '🬦', '🬧', '▐', '🬨', '🬩', '🬪', '🬫', '🬬',
230 '🬭', '🬮', '🬯', '🬰', '🬱', '🬲', '🬳', '🬴', '🬵', '🬶', '🬷', '🬸', '🬹', '🬺', '🬻', '█'
231 ];
232
233 #[rustfmt::skip]
234 const fn index(self) -> usize {
235 (self.pixels[0] as usize) |
236 (self.pixels[1] as usize) << 1 |
237 (self.pixels[2] as usize) << 2 |
238 (self.pixels[3] as usize) << 3 |
239 (self.pixels[4] as usize) << 4 |
240 (self.pixels[5] as usize) << 5
241 }
242
243 #[must_use]
265 pub const fn character(self) -> char {
266 Self::CHARS[self.index()]
267 }
268}
269
270impl Pixel for HexPixel {
271 type U = bool;
272
273 const WIDTH: usize = 2;
274
275 const HEIGHT: usize = 3;
276
277 impl_getters!(pixels: [bool; 6]);
278
279 impl_getters_mut!(pixels: [bool; 6]);
280
281 impl_new!(HexPixel, pixels: [bool; 6]);
282}
283
284impl_from_mono_chrome_pixel_for_datacell!(HexPixel);
285
286#[derive(Clone, Copy)]
288pub struct OctPixel {
289 pixels: [bool; 8],
290}
291
292#[rustfmt::skip]
296impl OctPixel {
297 #[rustfmt::skip]
298 const CHARS: [char; 256] = [
299 ' ', '', '', '🮂', '', '▘', '', '', '', '', '▝', '', '', '', '', '▀',
300 '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
301 '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
302 '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '🮅',
303 '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
304 '▖', '', '', '', '', '▌', '', '', '', '', '▞', '', '', '', '', '▛',
305 '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
306 '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
307 '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
308 '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
309 '▗', '', '', '', '', '▚', '', '', '', '', '▐', '', '', '', '', '▜',
310 '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
311 '▂', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
312 '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
313 '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
314 '▄', '', '', '', '', '▙', '', '', '', '', '▟', '', '▆', '', '', '█',
315 ];
316
317 #[rustfmt::skip]
318 const fn index(self) -> usize {
319 (self.pixels[0] as usize) |
320 (self.pixels[1] as usize) << 1 |
321 (self.pixels[2] as usize) << 2 |
322 (self.pixels[3] as usize) << 3 |
323 (self.pixels[4] as usize) << 4 |
324 (self.pixels[5] as usize) << 5 |
325 (self.pixels[6] as usize) << 6 |
326 (self.pixels[7] as usize) << 7
327 }
328
329 #[must_use]
352 pub const fn character(self) -> char {
353 Self::CHARS[self.index()]
354 }
355}
356
357impl Pixel for OctPixel {
358 type U = bool;
359
360 const WIDTH: usize = 2;
361
362 const HEIGHT: usize = 4;
363
364 impl_getters!(pixels: [bool; 8]);
365
366 impl_getters_mut!(pixels: [bool; 8]);
367
368 impl_new!(OctPixel, pixels: [bool; 8]);
369}
370
371impl_from_mono_chrome_pixel_for_datacell!(OctPixel);
372
373#[derive(Clone, Copy)]
375pub struct BrailleOctPixel {
376 pixels: [bool; 8],
377}
378
379impl BrailleOctPixel {
380 #[rustfmt::skip]
381 const CHARS: [char; 256] = [
382 '⠀', '⠁', '⠈', '⠉', '⠂', '⠃', '⠊', '⠋', '⠐', '⠑', '⠘', '⠙', '⠒', '⠓', '⠚', '⠛',
383 '⠄', '⠅', '⠌', '⠍', '⠆', '⠇', '⠎', '⠏', '⠔', '⠕', '⠜', '⠝', '⠖', '⠗', '⠞', '⠟',
384 '⠠', '⠡', '⠨', '⠩', '⠢', '⠣', '⠪', '⠫', '⠰', '⠱', '⠸', '⠹', '⠲', '⠳', '⠺', '⠻',
385 '⠤', '⠥', '⠬', '⠭', '⠦', '⠧', '⠮', '⠯', '⠴', '⠵', '⠼', '⠽', '⠶', '⠷', '⠾', '⠿',
386 '⡀', '⡁', '⡈', '⡉', '⡂', '⡃', '⡊', '⡋', '⡐', '⡑', '⡘', '⡙', '⡒', '⡓', '⡚', '⡛',
387 '⡄', '⡅', '⡌', '⡍', '⡆', '⡇', '⡎', '⡏', '⡔', '⡕', '⡜', '⡝', '⡖', '⡗', '⡞', '⡟',
388 '⡠', '⡡', '⡨', '⡩', '⡢', '⡣', '⡪', '⡫', '⡰', '⡱', '⡸', '⡹', '⡲', '⡳', '⡺', '⡻',
389 '⡤', '⡥', '⡬', '⡭', '⡦', '⡧', '⡮', '⡯', '⡴', '⡵', '⡼', '⡽', '⡶', '⡷', '⡾', '⡿',
390 '⢀', '⢁', '⢈', '⢉', '⢂', '⢃', '⢊', '⢋', '⢐', '⢑', '⢘', '⢙', '⢒', '⢓', '⢚', '⢛',
391 '⢄', '⢅', '⢌', '⢍', '⢆', '⢇', '⢎', '⢏', '⢔', '⢕', '⢜', '⢝', '⢖', '⢗', '⢞', '⢟',
392 '⢠', '⢡', '⢨', '⢩', '⢢', '⢣', '⢪', '⢫', '⢰', '⢱', '⢸', '⢹', '⢲', '⢳', '⢺', '⢻',
393 '⢤', '⢥', '⢬', '⢭', '⢦', '⢧', '⢮', '⢯', '⢴', '⢵', '⢼', '⢽', '⢶', '⢷', '⢾', '⢿',
394 '⣀', '⣁', '⣈', '⣉', '⣂', '⣃', '⣊', '⣋', '⣐', '⣑', '⣘', '⣙', '⣒', '⣓', '⣚', '⣛',
395 '⣄', '⣅', '⣌', '⣍', '⣆', '⣇', '⣎', '⣏', '⣔', '⣕', '⣜', '⣝', '⣖', '⣗', '⣞', '⣟',
396 '⣠', '⣡', '⣨', '⣩', '⣢', '⣣', '⣪', '⣫', '⣰', '⣱', '⣸', '⣹', '⣲', '⣳', '⣺', '⣻',
397 '⣤', '⣥', '⣬', '⣭', '⣦', '⣧', '⣮', '⣯', '⣴', '⣵', '⣼', '⣽', '⣶', '⣷', '⣾', '⣿',
398 ];
399
400 #[rustfmt::skip]
401 const fn index(self) -> usize {
402 (self.pixels[0] as usize) |
403 (self.pixels[1] as usize) << 1 |
404 (self.pixels[2] as usize) << 2 |
405 (self.pixels[3] as usize) << 3 |
406 (self.pixels[4] as usize) << 4 |
407 (self.pixels[5] as usize) << 5 |
408 (self.pixels[6] as usize) << 6 |
409 (self.pixels[7] as usize) << 7
410 }
411
412 #[must_use]
435 pub const fn character(self) -> char {
436 Self::CHARS[self.index()]
437 }
438}
439
440impl Pixel for BrailleOctPixel {
441 type U = bool;
442
443 const WIDTH: usize = 2;
444
445 const HEIGHT: usize = 4;
446
447 impl_getters!(pixels: [bool; 8]);
448
449 impl_getters_mut!(pixels: [bool; 8]);
450
451 impl_new!(BrailleOctPixel, pixels: [bool; 8]);
452}
453
454impl_from_mono_chrome_pixel_for_datacell!(BrailleOctPixel);