| 1 | use std::{borrow::Cow, num::NonZeroU16}; |
| 2 | |
| 3 | use crate::canvas::components::data_table::{ColumnHeader, DataTableColumn, DataToCell}; |
| 4 | |
| 5 | pub struct SortTableColumn; |
| 6 | |
| 7 | impl ColumnHeader for SortTableColumn { |
| 8 | fn text(&self) -> Cow<'static, str> { |
| 9 | "Sort By".into() |
| 10 | } |
| 11 | } |
| 12 | |
| 13 | impl DataToCell<SortTableColumn> for &'static str { |
| 14 | fn to_cell_text( |
| 15 | &self, _column: &SortTableColumn, _calculated_width: NonZeroU16, |
| 16 | ) -> Option<Cow<'static, str>> { |
| 17 | Some(Cow::Borrowed(self)) |
| 18 | } |
| 19 | |
| 20 | fn column_widths<C: DataTableColumn<SortTableColumn>>(data: &[Self], _columns: &[C]) -> Vec<u16> |
| 21 | where |
| 22 | Self: Sized, |
| 23 | { |
| 24 | vec![data.iter().map(|d| d.len() as u16).max().unwrap_or(0)] |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | impl DataToCell<SortTableColumn> for Cow<'static, str> { |
| 29 | fn to_cell_text( |
| 30 | &self, _column: &SortTableColumn, _calculated_width: NonZeroU16, |
| 31 | ) -> Option<Cow<'static, str>> { |
| 32 | Some(self.clone()) |
| 33 | } |
| 34 | |
| 35 | fn column_widths<C: DataTableColumn<SortTableColumn>>(data: &[Self], _columns: &[C]) -> Vec<u16> |
| 36 | where |
| 37 | Self: Sized, |
| 38 | { |
| 39 | vec![data.iter().map(|d| d.len() as u16).max().unwrap_or(0)] |
| 40 | } |
| 41 | } |