tabled/features/style/
horizontal_line.rsuse crate::{Table, TableOption};
use super::Line;
#[derive(Debug, Clone)]
pub struct HorizontalLine {
pub(crate) index: usize,
pub(crate) line: Option<Line>,
}
impl HorizontalLine {
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 left(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 right(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 HorizontalLine {
fn change(&mut self, table: &mut Table<R>) {
match &self.line {
Some(line) => table
.get_config_mut()
.set_horizontal_line(self.index, papergrid::HorizontalLine::from(*line)),
None => table.get_config_mut().remove_horizontal_line(self.index),
}
}
}