use papergrid::{records::Records, Entity};
use crate::{object::Object, CellOption, Table, TableOption};
#[derive(Debug)]
pub struct Modify<O> {
obj: O,
}
impl<O> Modify<O>
where
O: Object,
{
pub fn new(obj: O) -> Self {
Self { obj }
}
pub fn with<M>(self, s: M) -> ModifyList<O, M> {
ModifyList {
obj: self.obj,
modifiers: s,
}
}
}
#[derive(Debug)]
pub struct ModifyList<O, S> {
obj: O,
modifiers: S,
}
impl<O, M1> ModifyList<O, M1>
where
O: Object,
{
pub fn with<M2>(self, s: M2) -> ModifyList<O, CellSettingsList<M1, M2>> {
ModifyList {
obj: self.obj,
modifiers: CellSettingsList {
s1: self.modifiers,
s2: s,
},
}
}
}
impl<O, M, R> TableOption<R> for ModifyList<O, M>
where
O: Object,
M: CellOption<R>,
R: Records,
{
fn change(&mut self, table: &mut Table<R>) {
for entity in self.obj.cells(table) {
self.modifiers.change_cell(table, entity);
}
}
}
#[derive(Debug)]
pub struct CellSettingsList<S1, S2> {
s1: S1,
s2: S2,
}
impl<M1, M2, R> CellOption<R> for CellSettingsList<M1, M2>
where
M1: CellOption<R>,
M2: CellOption<R>,
{
fn change_cell(&mut self, table: &mut Table<R>, entity: Entity) {
self.s1.change_cell(table, entity);
self.s2.change_cell(table, entity);
}
}
pub trait ModifyObject: Object {
fn modify(self) -> Modify<Self> {
Modify::new(self)
}
}
impl<O> ModifyObject for O where O: Object {}