tabled/features/height/
height_list.rs

1use std::iter::FromIterator;
2
3use papergrid::records::Records;
4
5use crate::{Table, TableOption};
6
7/// A structure used to set [`Table`] height via a list of rows heights.
8#[derive(Debug)]
9pub struct HeightList {
10    list: Vec<usize>,
11}
12
13impl HeightList {
14    /// Creates a new object.
15    pub fn new(list: Vec<usize>) -> Self {
16        Self { list }
17    }
18}
19
20impl From<Vec<usize>> for HeightList {
21    fn from(list: Vec<usize>) -> Self {
22        Self::new(list)
23    }
24}
25
26impl FromIterator<usize> for HeightList {
27    fn from_iter<T>(iter: T) -> Self
28    where
29        T: IntoIterator<Item = usize>,
30    {
31        Self::new(iter.into_iter().collect())
32    }
33}
34
35impl<R> TableOption<R> for HeightList
36where
37    R: Records,
38{
39    fn change(&mut self, table: &mut Table<R>) {
40        if self.list.len() < table.count_rows() {
41            return;
42        }
43
44        table.cache_height(self.list.clone());
45        table.destroy_width_cache();
46    }
47}