summaryrefslogtreecommitdiffstats
path: root/src/components/data_table/data_type.rs
blob: 6fad3196d27a91b1066b6ab69d3fe472b124fb89 (plain)
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
use tui::{text::Text, widgets::Row};

use super::{ColumnHeader, DataTableColumn};
use crate::canvas::Painter;

pub trait DataToCell<H>
where
    H: ColumnHeader,
{
    /// Given data, a column, and its corresponding width, return what should be displayed in the [`DataTable`](super::DataTable).
    fn to_cell<'a>(&'a self, column: &H, calculated_width: u16) -> Option<Text<'a>>;

    /// Apply styling to the generated [`Row`] of cells.
    ///
    /// The default implementation just returns the `row` that is passed in.
    #[inline(always)]
    fn style_row<'a>(&self, row: Row<'a>, _painter: &Painter) -> Row<'a> {
        row
    }

    /// Returns the desired column widths in light of having seen data.
    fn column_widths<C: DataTableColumn<H>>(data: &[Self], columns: &[C]) -> Vec<u16>
    where
        Self: Sized;
}