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