From c71bc381ab487f704a75adc2cca3e6fc4a212e89 Mon Sep 17 00:00:00 2001 From: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> Date: Wed, 4 Jan 2023 01:13:05 -0500 Subject: [PATCH] bug: fix CPU 'all' label missing on small sizes --- src/components/data_table/draw.rs | 6 +----- src/widgets/cpu_graph.rs | 6 +++--- src/widgets/disk_table.rs | 4 ++++ src/widgets/process_table/proc_widget_data.rs | 4 ++++ src/widgets/process_table/sort_table.rs | 10 +++++++++- src/widgets/temperature_table.rs | 4 ++++ 6 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/components/data_table/draw.rs b/src/components/data_table/draw.rs index f3b73ea04..3531d3d96 100644 --- a/src/components/data_table/draw.rs +++ b/src/components/data_table/draw.rs @@ -221,11 +221,7 @@ where .iter() .zip(&self.state.calculated_widths) .filter_map(|(column, &width)| { - if width > 0 { - data_row.to_cell(column.inner(), width) - } else { - None - } + data_row.to_cell(column.inner(), width) }), ); diff --git a/src/widgets/cpu_graph.rs b/src/widgets/cpu_graph.rs index b3d72c780..63e3e8161 100644 --- a/src/widgets/cpu_graph.rs +++ b/src/widgets/cpu_graph.rs @@ -77,7 +77,7 @@ impl CpuWidgetTableData { impl DataToCell for CpuWidgetTableData { fn to_cell<'a>(&'a self, column: &CpuWidgetColumn, calculated_width: u16) -> Option> { - const CPU_HIDE_BREAKPOINT: u16 = 5; + const CPU_TRUNCATE_BREAKPOINT: u16 = 5; // This is a bit of a hack, but apparently we can avoid having to do any fancy checks // of showing the "All" on a specific column if the other is hidden by just always @@ -88,7 +88,7 @@ impl DataToCell for CpuWidgetTableData { // it is too small. match &self { CpuWidgetTableData::All => match column { - CpuWidgetColumn::CPU => Some(truncate_to_text("All", calculated_width)), + CpuWidgetColumn::CPU => Some("All".into()), CpuWidgetColumn::Use => None, }, CpuWidgetTableData::Entry { @@ -103,7 +103,7 @@ impl DataToCell for CpuWidgetTableData { CpuDataType::Avg => Some(truncate_to_text("AVG", calculated_width)), CpuDataType::Cpu(index) => { let index_str = index.to_string(); - let text = if calculated_width < CPU_HIDE_BREAKPOINT { + let text = if calculated_width < CPU_TRUNCATE_BREAKPOINT { truncate_to_text(&index_str, calculated_width) } else { truncate_to_text( diff --git a/src/widgets/disk_table.rs b/src/widgets/disk_table.rs index b168ac919..1d0e0ce00 100644 --- a/src/widgets/disk_table.rs +++ b/src/widgets/disk_table.rs @@ -123,6 +123,10 @@ impl ColumnHeader for DiskWidgetColumn { impl DataToCell for DiskWidgetData { fn to_cell<'a>(&'a self, column: &DiskWidgetColumn, calculated_width: u16) -> Option> { + if calculated_width == 0 { + return None; + } + let text = match column { DiskWidgetColumn::Disk => truncate_to_text(&self.name, calculated_width), DiskWidgetColumn::Mount => truncate_to_text(&self.mount_point, calculated_width), diff --git a/src/widgets/process_table/proc_widget_data.rs b/src/widgets/process_table/proc_widget_data.rs index bcc7d5692..0dc95c95e 100644 --- a/src/widgets/process_table/proc_widget_data.rs +++ b/src/widgets/process_table/proc_widget_data.rs @@ -221,6 +221,10 @@ impl ProcWidgetData { impl DataToCell for ProcWidgetData { fn to_cell<'a>(&'a self, column: &ProcColumn, calculated_width: u16) -> Option> { + if calculated_width == 0 { + return None; + } + // TODO: Optimize the string allocations here... // TODO: Also maybe just pull in the to_string call but add a variable for the differences. Some(truncate_to_text( diff --git a/src/widgets/process_table/sort_table.rs b/src/widgets/process_table/sort_table.rs index 24febb29a..5be78bfb0 100644 --- a/src/widgets/process_table/sort_table.rs +++ b/src/widgets/process_table/sort_table.rs @@ -17,7 +17,11 @@ impl ColumnHeader for SortTableColumn { impl DataToCell for &'static str { fn to_cell<'a>(&'a self, _column: &SortTableColumn, calculated_width: u16) -> Option> { - Some(truncate_to_text(self, calculated_width)) + if calculated_width > 0 { + Some(truncate_to_text(self, calculated_width)) + } else { + None + } } fn column_widths>(data: &[Self], _columns: &[C]) -> Vec @@ -30,6 +34,10 @@ impl DataToCell for &'static str { impl DataToCell for Cow<'static, str> { fn to_cell<'a>(&'a self, _column: &SortTableColumn, calculated_width: u16) -> Option> { + if calculated_width == 0 { + return None; + } + Some(truncate_to_text(self, calculated_width)) } diff --git a/src/widgets/temperature_table.rs b/src/widgets/temperature_table.rs index 42103dd29..4db6567f7 100644 --- a/src/widgets/temperature_table.rs +++ b/src/widgets/temperature_table.rs @@ -49,6 +49,10 @@ impl TempWidgetData { impl DataToCell for TempWidgetData { fn to_cell<'a>(&'a self, column: &TempWidgetColumn, calculated_width: u16) -> Option> { + if calculated_width == 0 { + return None; + } + Some(match column { TempWidgetColumn::Sensor => truncate_to_text(&self.sensor, calculated_width), TempWidgetColumn::Temp => truncate_to_text(&self.temperature(), calculated_width),