summaryrefslogtreecommitdiffstats
path: root/src/canvas/components/data_table/sortable.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/canvas/components/data_table/sortable.rs')
-rw-r--r--src/canvas/components/data_table/sortable.rs35
1 files changed, 17 insertions, 18 deletions
diff --git a/src/canvas/components/data_table/sortable.rs b/src/canvas/components/data_table/sortable.rs
index f6c3b502..7b548309 100644
--- a/src/canvas/components/data_table/sortable.rs
+++ b/src/canvas/components/data_table/sortable.rs
@@ -1,4 +1,4 @@
-use std::{borrow::Cow, marker::PhantomData};
+use std::{borrow::Cow, marker::PhantomData, num::NonZeroU16};
use concat_string::concat_string;
use itertools::Itertools;
@@ -52,18 +52,17 @@ pub struct Sortable {
/// and therefore only [`Unsortable`] and [`Sortable`] can implement it.
pub trait SortType: private::Sealed {
/// Constructs the table header.
- fn build_header<H, C>(&self, columns: &[C], widths: &[u16]) -> Row<'_>
+ fn build_header<H, C>(&self, columns: &[C], widths: &[NonZeroU16]) -> Row<'_>
where
H: ColumnHeader,
C: DataTableColumn<H>,
{
- Row::new(columns.iter().zip(widths).filter_map(|(c, &width)| {
- if width == 0 {
- None
- } else {
- Some(truncate_to_text(&c.header(), width))
- }
- }))
+ Row::new(
+ columns
+ .iter()
+ .zip(widths)
+ .map(|(c, &width)| truncate_to_text(&c.header(), width.get())),
+ )
}
}
@@ -79,7 +78,7 @@ mod private {
impl SortType for Unsortable {}
impl SortType for Sortable {
- fn build_header<H, C>(&self, columns: &[C], widths: &[u16]) -> Row<'_>
+ fn build_header<H, C>(&self, columns: &[C], widths: &[NonZeroU16]) -> Row<'_>
where
H: ColumnHeader,
C: DataTableColumn<H>,
@@ -92,17 +91,17 @@ impl SortType for Sortable {
.iter()
.zip(widths)
.enumerate()
- .filter_map(|(index, (c, &width))| {
- if width == 0 {
- None
- } else if index == self.sort_index {
+ .map(|(index, (c, &width))| {
+ if index == self.sort_index {
let arrow = match self.order {
SortOrder::Ascending => UP_ARROW,
SortOrder::Descending => DOWN_ARROW,
};
- Some(truncate_to_text(&concat_string!(c.header(), arrow), width))
+ // TODO: I think I can get away with removing the truncate_to_text call since
+ // I almost always bind to at least the header size...
+ truncate_to_text(&concat_string!(c.header(), arrow), width.get())
} else {
- Some(truncate_to_text(&c.header(), width))
+ truncate_to_text(&c.header(), width.get())
}
}),
)
@@ -331,7 +330,7 @@ where
.iter()
.map(|width| {
let entry_start = start;
- start += width + 1; // +1 for the gap b/w cols.
+ start += width.get() + 1; // +1 for the gap b/w cols.
entry_start
})
@@ -361,7 +360,7 @@ mod test {
impl DataToCell<ColumnType> for TestType {
fn to_cell(
- &self, _column: &ColumnType, _calculated_width: u16,
+ &self, _column: &ColumnType, _calculated_width: NonZeroU16,
) -> Option<tui::text::Text<'_>> {
None
}