1use crate::grid::color::StaticColor;
2use crate::grid::config::{
3 AlignmentHorizontal, AlignmentVertical, Borders, CompactConfig, Indent, Line, Sides,
4};
5
6/// A [`CompactConfig`] configuration plus vertical alignment.
7#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
8pub struct CompactMultilineConfig {
9 config: CompactConfig,
10 alignment_vertical: AlignmentVertical,
11 formatting: Formatting,
12}
13
14impl CompactMultilineConfig {
15 /// Create a new colored config.
16 pub fn new(config: CompactConfig) -> Self {
17 Self::from(config)
18 }
19
20 /// Set a horizontal alignment.
21 pub const fn set_alignment_vertical(mut self, alignment: AlignmentVertical) -> Self {
22 self.alignment_vertical = alignment;
23 self
24 }
25
26 /// Get a alignment horizontal.
27 pub const fn get_alignment_vertical(&self) -> AlignmentVertical {
28 self.alignment_vertical
29 }
30
31 /// Set grid margin.
32 pub const fn set_margin(mut self, margin: Sides<Indent>) -> Self {
33 self.config = self.config.set_margin(margin);
34 self
35 }
36
37 /// Returns a grid margin.
38 pub const fn get_margin(&self) -> &Sides<Indent> {
39 self.config.get_margin()
40 }
41
42 /// Set the [`Borders`] value as correct one.
43 pub const fn set_borders(mut self, borders: Borders<char>) -> Self {
44 self.config = self.config.set_borders(borders);
45 self
46 }
47
48 /// Set the first horizontal line.
49 ///
50 /// It ignores the [`Borders`] horizontal value if set for 1st row.
51 pub const fn set_first_horizontal_line(mut self, line: Line<char>) -> Self {
52 self.config = self.config.set_first_horizontal_line(line);
53 self
54 }
55
56 /// Set the first horizontal line.
57 ///
58 /// It ignores the [`Borders`] horizontal value if set for 1st row.
59 pub const fn get_first_horizontal_line(&self) -> Option<Line<char>> {
60 self.config.get_first_horizontal_line()
61 }
62
63 /// Returns a current [`Borders`] structure.
64 pub const fn get_borders(&self) -> &Borders<char> {
65 self.config.get_borders()
66 }
67
68 /// Returns a current [`Borders`] structure.
69 pub const fn get_borders_color(&self) -> &Borders<StaticColor> {
70 self.config.get_borders_color()
71 }
72
73 /// Set a padding to a given cells.
74 pub const fn set_padding(mut self, padding: Sides<Indent>) -> Self {
75 self.config = self.config.set_padding(padding);
76 self
77 }
78
79 /// Get a padding for a given.
80 pub const fn get_padding(&self) -> &Sides<Indent> {
81 self.config.get_padding()
82 }
83
84 /// Set a horizontal alignment.
85 pub const fn set_alignment_horizontal(mut self, alignment: AlignmentHorizontal) -> Self {
86 self.config = self.config.set_alignment_horizontal(alignment);
87 self
88 }
89
90 /// Get a alignment horizontal.
91 pub const fn get_alignment_horizontal(&self) -> AlignmentHorizontal {
92 self.config.get_alignment_horizontal()
93 }
94
95 /// Sets colors of border carcass on the grid.
96 pub const fn set_borders_color(mut self, borders: Borders<StaticColor>) -> Self {
97 self.config = self.config.set_borders_color(borders);
98 self
99 }
100
101 /// Set colors for a margin.
102 pub const fn set_margin_color(mut self, color: Sides<StaticColor>) -> Self {
103 self.config = self.config.set_margin_color(color);
104 self
105 }
106
107 /// Returns a margin color.
108 pub const fn get_margin_color(&self) -> Sides<StaticColor> {
109 self.config.get_margin_color()
110 }
111
112 /// Set a padding color to all cells.
113 pub const fn set_padding_color(mut self, color: Sides<StaticColor>) -> Self {
114 self.config = self.config.set_padding_color(color);
115 self
116 }
117
118 /// get a padding color.
119 pub const fn get_padding_color(&self) -> Sides<StaticColor> {
120 self.config.get_padding_color()
121 }
122
123 /// Set formatting.
124 pub const fn set_formatting(mut self, formatting: Formatting) -> Self {
125 self.formatting = formatting;
126 self
127 }
128
129 /// Get formatting.
130 pub const fn get_formatting(&self) -> Formatting {
131 self.formatting
132 }
133}
134
135impl Default for CompactMultilineConfig {
136 fn default() -> Self {
137 Self {
138 config: Default::default(),
139 alignment_vertical: AlignmentVertical::Top,
140 formatting: Formatting::default(),
141 }
142 }
143}
144
145impl From<CompactConfig> for CompactMultilineConfig {
146 fn from(config: CompactConfig) -> Self {
147 Self {
148 config,
149 alignment_vertical: AlignmentVertical::Top,
150 formatting: Formatting::default(),
151 }
152 }
153}
154
155impl AsRef<CompactConfig> for CompactMultilineConfig {
156 fn as_ref(&self) -> &CompactConfig {
157 &self.config
158 }
159}
160
161impl AsMut<CompactConfig> for CompactMultilineConfig {
162 fn as_mut(&mut self) -> &mut CompactConfig {
163 &mut self.config
164 }
165}
166
167#[cfg(feature = "std")]
168impl From<CompactMultilineConfig> for crate::grid::config::SpannedConfig {
169 fn from(compact: CompactMultilineConfig) -> Self {
170 use crate::grid::config::Entity;
171
172 let mut cfg: SpannedConfig = crate::grid::config::SpannedConfig::from(compact.config);
173 cfg.set_alignment_vertical(Entity::Global, compact.alignment_vertical);
174 cfg.set_formatting(Entity::Global, formatting:compact.formatting.into());
175
176 cfg
177 }
178}
179
180/// Formatting represent a logic of formatting of a cell.
181#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
182pub struct Formatting {
183 /// An setting to allow horizontal trim.
184 pub horizontal_trim: bool,
185 /// An setting to allow vertical trim.
186 pub vertical_trim: bool,
187 /// An setting to allow alignment per line.
188 pub allow_lines_alignment: bool,
189}
190
191impl Formatting {
192 /// Creates a new [`Formatting`] structure.
193 pub fn new(horizontal_trim: bool, vertical_trim: bool, allow_lines_alignment: bool) -> Self {
194 Self {
195 horizontal_trim,
196 vertical_trim,
197 allow_lines_alignment,
198 }
199 }
200}
201
202#[cfg(feature = "std")]
203impl From<Formatting> for crate::grid::config::Formatting {
204 fn from(val: Formatting) -> Self {
205 crate::grid::config::Formatting {
206 allow_lines_alignment: val.allow_lines_alignment,
207 horizontal_trim: val.horizontal_trim,
208 vertical_trim: val.vertical_trim,
209 }
210 }
211}
212