use crate::column::Column;
use crate::style::{CellAlignment, ColumnConstraint};
#[derive(Debug)]
pub struct ColumnDisplayInfo {
pub padding: (u16, u16),
pub delimiter: Option<char>,
pub max_content_width: u16,
pub content_width: u16,
pub fixed: bool,
pub constraint: Option<ColumnConstraint>,
pub cell_alignment: Option<CellAlignment>,
pub needs_splitting: bool,
}
impl ColumnDisplayInfo {
pub fn new(column: &Column) -> Self {
ColumnDisplayInfo {
padding: column.padding,
delimiter: column.delimiter,
max_content_width: column.max_content_width,
content_width: 0,
fixed: false,
constraint: None::<ColumnConstraint>,
cell_alignment: column.cell_alignment,
needs_splitting: false,
}
}
pub fn padding_width(&self) -> u16 {
self.padding.0 + self.padding.1
}
pub fn content_width(&self) -> u16 {
self.content_width
}
pub fn set_content_width(&mut self, width: u16) {
if width == 0 {
self.content_width = 1;
return;
}
self.content_width = width;
}
pub fn max_width(&self) -> u16 {
self.max_content_width + self.padding.0 + self.padding.1
}
pub fn width(&self) -> u16 {
self.content_width + self.padding.0 + self.padding.1
}
pub fn is_hidden(&self) -> bool {
if let Some(constraint) = self.constraint {
return constraint == ColumnConstraint::Hidden;
}
false
}
pub fn without_padding(&self, width: u16) -> u16 {
let padding = self.padding_width();
if padding >= width {
return 1;
}
width - padding
}
}