From 8f9097b90cfba6fd3c1d4033f5cf7b24f4cd5270 Mon Sep 17 00:00:00 2001 From: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> Date: Wed, 4 Jan 2023 01:55:46 -0500 Subject: [PATCH] bug: fix CPU 'all' label missing on small sizes (#953) Fixes the "All" label being missing on small windows. --- CHANGELOG.md | 1 + src/components/data_table/draw.rs | 6 +--- src/widgets/cpu_graph.rs | 30 +++++++++---------- src/widgets/disk_table.rs | 4 +++ src/widgets/process_table/proc_widget_data.rs | 4 +++ src/widgets/process_table/sort_table.rs | 8 +++++ src/widgets/temperature_table.rs | 4 +++ 7 files changed, 37 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7e1ba9cc..f8c1cb0c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Bug Fixes - [#952](https://github.com/ClementTsang/bottom/pull/952): Partially fix battery text getting cut off in small windows. +- [#953](https://github.com/ClementTsang/bottom/pull/953): Fix CPU widget's 'all' label being missing on small sizes. ## Changes 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..3d68b8899 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,22 +88,22 @@ 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 { data_type, last_entry, - } => match column { - CpuWidgetColumn::CPU => { - if calculated_width == 0 { - None - } else { - match data_type { + } => { + if calculated_width == 0 { + None + } else { + match column { + CpuWidgetColumn::CPU => match data_type { 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( @@ -114,14 +114,14 @@ impl DataToCell for CpuWidgetTableData { Some(text) } - } + }, + CpuWidgetColumn::Use => Some(truncate_to_text( + &format!("{:.0}%", last_entry.round()), + calculated_width, + )), } } - CpuWidgetColumn::Use => Some(truncate_to_text( - &format!("{:.0}%", last_entry.round()), - calculated_width, - )), - }, + } } } 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..507a4cb78 100644 --- a/src/widgets/process_table/sort_table.rs +++ b/src/widgets/process_table/sort_table.rs @@ -17,6 +17,10 @@ impl ColumnHeader for SortTableColumn { impl DataToCell for &'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)) } @@ -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),