use papergrid::Entity;
use crate::{CellOption, Table, TableOption};
pub use papergrid::{AlignmentHorizontal, AlignmentVertical};
#[derive(Debug, Clone)]
pub enum Alignment {
Horizontal(AlignmentHorizontal),
Vertical(AlignmentVertical),
}
impl Alignment {
pub fn left() -> Self {
Self::horizontal(AlignmentHorizontal::Left)
}
pub fn right() -> Self {
Self::horizontal(AlignmentHorizontal::Right)
}
pub fn center() -> Self {
Self::horizontal(AlignmentHorizontal::Center)
}
pub fn top() -> Self {
Self::vertical(AlignmentVertical::Top)
}
pub fn bottom() -> Self {
Self::vertical(AlignmentVertical::Bottom)
}
pub fn center_vertical() -> Self {
Self::vertical(AlignmentVertical::Center)
}
fn horizontal(alignment: AlignmentHorizontal) -> Self {
Self::Horizontal(alignment)
}
fn vertical(alignment: AlignmentVertical) -> Self {
Self::Vertical(alignment)
}
}
impl<R> CellOption<R> for Alignment {
fn change_cell(&mut self, table: &mut Table<R>, entity: Entity) {
match *self {
Self::Horizontal(a) => table.get_config_mut().set_alignment_horizontal(entity, a),
Self::Vertical(a) => table.get_config_mut().set_alignment_vertical(entity, a),
};
}
}
impl<R> TableOption<R> for Alignment {
fn change(&mut self, table: &mut Table<R>) {
let cfg = table.get_config_mut();
match self {
Alignment::Horizontal(a) => cfg.set_alignment_horizontal(Entity::Global, *a),
Alignment::Vertical(a) => cfg.set_alignment_vertical(Entity::Global, *a),
}
}
}