1 | //! A module which contains configuration of a [`CompactGrid`] which is responsible for grid configuration. |
2 | //! |
3 | //! [`CompactGrid`]: crate::grid::compact::CompactGrid |
4 | |
5 | use crate::color::StaticColor; |
6 | |
7 | use crate::config::{AlignmentHorizontal, Borders, Indent, Line, Sides}; |
8 | |
9 | /// This structure represents a settings of a grid. |
10 | /// |
11 | /// grid: crate::Grid. |
12 | #[derive (Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] |
13 | pub struct CompactConfig { |
14 | borders: Borders<char>, |
15 | horizontal_line1: Option<Line<char>>, |
16 | border_colors: Borders<StaticColor>, |
17 | margin: Sides<Indent>, |
18 | margin_color: Sides<StaticColor>, |
19 | padding: Sides<Indent>, |
20 | padding_color: Sides<StaticColor>, |
21 | halignment: AlignmentHorizontal, |
22 | } |
23 | |
24 | impl Default for CompactConfig { |
25 | fn default() -> Self { |
26 | Self::empty() |
27 | } |
28 | } |
29 | |
30 | impl CompactConfig { |
31 | /// Returns an standard config. |
32 | pub const fn empty() -> Self { |
33 | Self { |
34 | halignment: AlignmentHorizontal::Left, |
35 | horizontal_line1: None, |
36 | borders: Borders::empty(), |
37 | border_colors: Borders::empty(), |
38 | margin: Sides::filled(Indent::zero()), |
39 | margin_color: Sides::filled(StaticColor::new("" , "" )), |
40 | padding: Sides::new( |
41 | Indent::spaced(1), |
42 | Indent::spaced(1), |
43 | Indent::zero(), |
44 | Indent::zero(), |
45 | ), |
46 | padding_color: Sides::filled(StaticColor::new("" , "" )), |
47 | } |
48 | } |
49 | |
50 | /// Set grid margin. |
51 | pub const fn set_margin(mut self, margin: Sides<Indent>) -> Self { |
52 | self.margin = margin; |
53 | self |
54 | } |
55 | |
56 | /// Returns a grid margin. |
57 | pub const fn get_margin(&self) -> &Sides<Indent> { |
58 | &self.margin |
59 | } |
60 | |
61 | /// Set the [`Borders`] value as correct one. |
62 | pub const fn set_borders(mut self, borders: Borders<char>) -> Self { |
63 | self.borders = borders; |
64 | self |
65 | } |
66 | |
67 | /// Set the first horizontal line. |
68 | /// |
69 | /// It ignores the [`Borders`] horizontal value if set for 1st row. |
70 | pub const fn set_first_horizontal_line(mut self, line: Line<char>) -> Self { |
71 | self.horizontal_line1 = Some(line); |
72 | self |
73 | } |
74 | |
75 | /// Set the first horizontal line. |
76 | /// |
77 | /// It ignores the [`Borders`] horizontal value if set for 1st row. |
78 | pub const fn get_first_horizontal_line(&self) -> Option<Line<char>> { |
79 | self.horizontal_line1 |
80 | } |
81 | |
82 | /// Returns a current [`Borders`] structure. |
83 | pub const fn get_borders(&self) -> &Borders<char> { |
84 | &self.borders |
85 | } |
86 | |
87 | /// Returns a current [`Borders`] structure. |
88 | pub const fn get_borders_color(&self) -> &Borders<StaticColor> { |
89 | &self.border_colors |
90 | } |
91 | |
92 | /// Set a padding to a given cells. |
93 | pub const fn set_padding(mut self, padding: Sides<Indent>) -> Self { |
94 | self.padding = padding; |
95 | self |
96 | } |
97 | |
98 | /// Get a padding for a given. |
99 | pub const fn get_padding(&self) -> &Sides<Indent> { |
100 | &self.padding |
101 | } |
102 | |
103 | /// Set a horizontal alignment. |
104 | pub const fn set_alignment_horizontal(mut self, alignment: AlignmentHorizontal) -> Self { |
105 | self.halignment = alignment; |
106 | self |
107 | } |
108 | |
109 | /// Get a alignment horizontal. |
110 | pub const fn get_alignment_horizontal(&self) -> AlignmentHorizontal { |
111 | self.halignment |
112 | } |
113 | |
114 | /// Sets colors of border carcass on the grid. |
115 | pub const fn set_borders_color(mut self, borders: Borders<StaticColor>) -> Self { |
116 | self.border_colors = borders; |
117 | self |
118 | } |
119 | |
120 | /// Set colors for a margin. |
121 | pub const fn set_margin_color(mut self, color: Sides<StaticColor>) -> Self { |
122 | self.margin_color = color; |
123 | self |
124 | } |
125 | |
126 | /// Returns a margin color. |
127 | pub const fn get_margin_color(&self) -> Sides<StaticColor> { |
128 | self.margin_color |
129 | } |
130 | |
131 | /// Set a padding to a given cells. |
132 | pub const fn set_padding_color(mut self, color: Sides<StaticColor>) -> Self { |
133 | self.padding_color = color; |
134 | self |
135 | } |
136 | |
137 | /// Set a padding to a given cells. |
138 | pub const fn get_padding_color(&self) -> Sides<StaticColor> { |
139 | self.padding_color |
140 | } |
141 | } |
142 | |