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