tabled/features/style/
vertical_line.rsuse crate::{Table, TableOption};
use super::Line;
#[derive(Debug, Clone)]
pub struct VerticalLine {
pub(crate) index: usize,
pub(crate) line: Option<Line>,
}
impl VerticalLine {
pub const fn new(index: usize, line: Line) -> Self {
Self {
index,
line: Some(line),
}
}
pub fn empty(index: usize) -> Self {
Self { index, line: None }
}
pub const fn main(mut self, c: Option<char>) -> Self {
let mut line = match self.line {
Some(line) => line,
None => Line::empty(),
};
line.main = c;
self.line = Some(line);
self
}
pub const fn intersection(mut self, c: Option<char>) -> Self {
let mut line = match self.line {
Some(line) => line,
None => Line::empty(),
};
line.intersection = c;
self.line = Some(line);
self
}
pub const fn top(mut self, c: Option<char>) -> Self {
let mut line = match self.line {
Some(line) => line,
None => Line::empty(),
};
line.connector1 = c;
self.line = Some(line);
self
}
pub const fn bottom(mut self, c: Option<char>) -> Self {
let mut line = match self.line {
Some(line) => line,
None => Line::empty(),
};
line.connector2 = c;
self.line = Some(line);
self
}
pub const fn is_empty(&self) -> bool {
match &self.line {
Some(l) => l.is_empty(),
None => true,
}
}
}
impl<R> TableOption<R> for VerticalLine {
fn change(&mut self, table: &mut Table<R>) {
match &self.line {
Some(line) => table
.get_config_mut()
.set_vertical_line(self.index, papergrid::VerticalLine::from(*line)),
None => table.get_config_mut().remove_vertical_line(self.index),
}
}
}