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
87
88
89
use super::{Coord, Size};
use rgb24::Rgb24;
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ViewCell {
pub character: Option<char>,
pub bold: Option<bool>,
pub underline: Option<bool>,
pub foreground: Option<Rgb24>,
pub background: Option<Rgb24>,
}
impl ViewCell {
pub fn new() -> Self {
Default::default()
}
pub fn with_character(mut self, character: char) -> Self {
self.character = Some(character);
self
}
pub fn with_bold(mut self, bold: bool) -> Self {
self.bold = Some(bold);
self
}
pub fn with_underline(mut self, underline: bool) -> Self {
self.underline = Some(underline);
self
}
pub fn with_foreground(mut self, foreground: Rgb24) -> Self {
self.foreground = Some(foreground);
self
}
pub fn with_background(mut self, background: Rgb24) -> Self {
self.background = Some(background);
self
}
pub fn set_character(&mut self, character: char) {
self.character = Some(character);
}
pub fn clear_character(&mut self) {
self.character = None;
}
pub fn set_bold(&mut self, bold: bool) {
self.bold = Some(bold);
}
pub fn clear_bold(&mut self) {
self.bold = None;
}
pub fn set_underline(&mut self, underline: bool) {
self.underline = Some(underline);
}
pub fn clear_underline(&mut self) {
self.underline = None;
}
pub fn set_foreground(&mut self, foreground: Rgb24) {
self.foreground = Some(foreground);
}
pub fn clear_foreground(&mut self) {
self.foreground = None;
}
pub fn set_background(&mut self, background: Rgb24) {
self.background = Some(background);
}
pub fn clear_background(&mut self) {
self.background = None;
}
}
pub trait ViewGrid {
fn set_cell(&mut self, coord: Coord, depth: i32, info: ViewCell);
}
pub trait View<T: ?Sized> {
fn view<G: ViewGrid>(&mut self, data: &T, offset: Coord, depth: i32, grid: &mut G);
}
pub trait ViewSize<T: ?Sized> {
fn size(&mut self, data: &T) -> Size;
}