1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use getset::{Getters, MutGetters, Setters};


#[derive(Debug, Clone, Default)]
pub enum TableCellAlignment {
    Left,
    #[default] Center,
    Right
}



#[derive(Debug, Clone, Default)]
pub enum TableCell {
    #[default] None,
    ContentCell{content: String, alignment: TableCellAlignment}
}



#[derive(Debug, Clone, Getters, MutGetters, Setters)]
pub struct Table {

    #[getset(get = "pub", set = "pub")]
    header: Option<Vec<TableCell>>,

    #[getset(get = "pub", get_mut = "pub", set = "pub")]
    body: Vec<Vec<TableCell>>,

    #[getset(get = "pub", set = "pub")]
    footer: Option<Vec<TableCell>>
}

impl Table {
    pub fn new() -> Self {
        Self {
            header: None,
            body: Vec::new(),
            footer: None
        }
    }

    pub fn append_to_body(&mut self, row: Vec<TableCell>) {
        
        self.body.push(row);
    }

    pub fn shift_first_body_row_to_header(&mut self) {

        let first_row = self.body.remove(0);

        self.header = Some(first_row.clone());

    }

    pub fn shift_last_body_row_to_footer(&mut self) {

        let last_row = self.body.remove(self.body.len() - 1);

        self.footer = Some(last_row.clone());

    }
}