#![allow(dead_code)]
pub const DEFAULT_COLSPAN: usize = 1;
pub const DEFAULT_H_ALIGN: HAlign = HAlign::Left;
pub const DEFAULT_V_ALIGN: VAlign = VAlign::Top;
pub const DEFAULT_BLANK_CHAR: char = '\x20';
#[derive(Clone, Copy)]
pub enum HAlign {
Left,
Right,
Center,
Fill,
}
#[derive(Clone, Copy)]
pub enum VAlign {
Top,
Bottom,
Middle,
}
pub struct Cell {
pub content: String,
pub col_span: Option<usize>,
pub h_align: Option<HAlign>,
pub v_align: Option<VAlign>,
pub blank_char: Option<char>,
}
impl Cell {
pub fn new(content: String, col_span: usize) -> Self {
if col_span == 0 {
panic!("Column span cannot be 0");
}
Self {
content,
col_span: Some(col_span),
h_align: None,
v_align: None,
blank_char: None,
}
}
pub fn new_fill(content: String, col_span: usize) -> Self {
Cell::builder(content, col_span).h_align(HAlign::Fill).build()
}
pub fn new_empty(col_span: usize) -> Self {
Cell::new("".into(), col_span)
}
pub fn builder(content: String, col_span: usize) -> CellBuilder {
CellBuilder {
inner: Cell::new(content, col_span),
}
}
}
pub struct CellBuilder {
inner: Cell,
}
impl CellBuilder {
pub fn build(self) -> Cell {
self.inner
}
pub fn content(mut self, content: String) -> Self {
self.inner.content = content;
self
}
pub fn col_span(mut self, col_span: usize) -> Self {
self.inner.col_span = Some(col_span);
self
}
pub fn h_align(mut self, h_align: HAlign) -> Self {
self.inner.h_align = Some(h_align);
self
}
pub fn v_align(mut self, v_align: VAlign) -> Self {
self.inner.v_align = Some(v_align);
self
}
pub fn blank_char(mut self, blank_char: char) -> Self {
self.inner.blank_char = Some(blank_char);
self
}
}