use crate::style::{CellAlignment, ColumnConstraint};
#[derive(Debug)]
pub struct Column {
pub index: usize,
pub(crate) padding: (u16, u16),
pub(crate) cell_alignment: Option<CellAlignment>,
pub(crate) max_content_width: u16,
pub(crate) constraint: Option<ColumnConstraint>,
}
impl Column {
pub fn new(index: usize) -> Self {
Column {
index: index,
padding: (1, 1),
constraint: None,
max_content_width: 0,
cell_alignment: None,
}
}
pub fn set_padding(&mut self, padding: (u16, u16)) -> &mut Self {
self.padding = padding;
self
}
pub fn get_max_content_width(&self) -> u16 {
self.max_content_width
}
pub fn set_constraint(&mut self, constraint: ColumnConstraint) -> &mut Self {
self.constraint = Some(constraint);
self
}
pub fn get_constraint(&self) -> Option<&ColumnConstraint> {
self.constraint.as_ref()
}
pub fn remove_constraint(&mut self) -> &mut Self{
self.constraint = None;
self
}
pub fn set_cell_alignment(&mut self, alignment: CellAlignment) {
self.cell_alignment = Some(alignment);
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_column() {
let mut column = Column::new(0);
column.set_padding((0, 0));
assert_eq!(column.get_max_content_width(), 0);
column.set_constraint(ColumnConstraint::ContentWidth);
assert_eq!(column.get_constraint(), Some(&ColumnConstraint::ContentWidth));
column.remove_constraint();
assert_eq!(column.get_constraint(), None);
}
}