Skip to main content

ppt_rs/generator/table/
row.rs

1//! Table row definition
2
3use super::cell::TableCell;
4
5/// Table row containing cells
6#[derive(Clone, Debug)]
7pub struct TableRow {
8    /// Cells in this row
9    pub cells: Vec<TableCell>,
10    /// Row height in EMU (optional)
11    pub height: Option<u32>,
12}
13
14impl TableRow {
15    /// Create a new table row with cells
16    pub fn new(cells: Vec<TableCell>) -> Self {
17        TableRow {
18            cells,
19            height: None,
20        }
21    }
22
23    /// Set row height in EMU
24    pub fn with_height(mut self, height: u32) -> Self {
25        self.height = Some(height);
26        self
27    }
28
29    /// Get the number of cells in this row
30    pub fn cell_count(&self) -> usize {
31        self.cells.len()
32    }
33}
34
35#[cfg(test)]
36mod tests {
37    use super::*;
38
39    #[test]
40    fn test_row_new() {
41        let row = TableRow::new(vec![
42            TableCell::new("A"),
43            TableCell::new("B"),
44        ]);
45        assert_eq!(row.cell_count(), 2);
46        assert!(row.height.is_none());
47    }
48
49    #[test]
50    fn test_row_with_height() {
51        let row = TableRow::new(vec![TableCell::new("A")])
52            .with_height(500000);
53        assert_eq!(row.height, Some(500000));
54    }
55}