1use crate::utils::from_lines;
2
3#[derive(Clone)]
4pub struct AsciiChar {
5 index: u16, pub width: usize,
7 lines: Vec<Vec<u16>>
8}
9
10impl AsciiChar {
11
12 pub fn new(c: u16, a: Vec<u16>) -> Self {
13 let lines: Vec<Vec<u16>> = a.split(|c| *c == '\n' as u16).map(|l| l.to_vec()).collect();
14
15 AsciiChar {
16 index: c,
17 width: lines[0].len(),
18 lines
19 }
20 }
21
22 pub fn to_string(&self) -> String {
23 from_lines(&self.lines)
24 }
25
26 pub fn render(&self, buffer: &mut Vec<Vec<u16>>, x_offset: &mut usize, monospace: bool) {
27
28 if monospace && self.width == 2 {
29
30 for x in 0..2 {
31
32 for y in 0..4 {
33 buffer[y][x + *x_offset + 1] = self.lines[y][x];
34 }
35
36 }
37
38 *x_offset += 3;
39 }
40
41 else {
42
43 for x in 0..self.width {
44
45 for y in 0..4 {
46 buffer[y][x + *x_offset] = self.lines[y][x];
47 }
48
49 }
50
51 *x_offset += self.width;
52 }
53
54 }
55
56}