use papergrid::{Entity, Indent};
use crate::{
table::{CellOption, Table},
TableOption,
};
#[derive(Debug)]
pub struct Padding(papergrid::Padding);
impl Padding {
pub fn new(left: usize, right: usize, top: usize, bottom: usize) -> Self {
Self(papergrid::Padding {
top: Indent::spaced(top),
bottom: Indent::spaced(bottom),
left: Indent::spaced(left),
right: Indent::spaced(right),
})
}
pub fn zero() -> Self {
let indent = Indent::spaced(0);
Self(papergrid::Padding {
top: indent,
bottom: indent,
left: indent,
right: indent,
})
}
pub fn set_fill(mut self, left: char, right: char, top: char, bottom: char) -> Self {
self.0.left.fill = left;
self.0.right.fill = right;
self.0.top.fill = top;
self.0.bottom.fill = bottom;
self
}
}
impl<R> CellOption<R> for Padding {
fn change_cell(&mut self, table: &mut Table<R>, entity: Entity) {
table.get_config_mut().set_padding(entity, self.0);
table.destroy_width_cache();
}
}
impl<R> TableOption<R> for Padding {
fn change(&mut self, table: &mut Table<R>) {
table.get_config_mut().set_padding(Entity::Global, self.0);
table.destroy_width_cache();
}
}