Skip to content

Commit

Permalink
bug: fix CPU 'all' label missing on small sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementTsang committed Jan 4, 2023
1 parent 0093a45 commit 4a8feb3
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
6 changes: 1 addition & 5 deletions src/components/data_table/draw.rs
Expand Up @@ -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)
}),
);

Expand Down
30 changes: 15 additions & 15 deletions src/widgets/cpu_graph.rs
Expand Up @@ -77,7 +77,7 @@ impl CpuWidgetTableData {

impl DataToCell<CpuWidgetColumn> for CpuWidgetTableData {
fn to_cell<'a>(&'a self, column: &CpuWidgetColumn, calculated_width: u16) -> Option<Text<'a>> {
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
Expand All @@ -88,22 +88,22 @@ impl DataToCell<CpuWidgetColumn> 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(
Expand All @@ -114,14 +114,14 @@ impl DataToCell<CpuWidgetColumn> 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,
)),
},
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/widgets/disk_table.rs
Expand Up @@ -123,6 +123,10 @@ impl ColumnHeader for DiskWidgetColumn {

impl DataToCell<DiskWidgetColumn> for DiskWidgetData {
fn to_cell<'a>(&'a self, column: &DiskWidgetColumn, calculated_width: u16) -> Option<Text<'a>> {
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),
Expand Down
4 changes: 4 additions & 0 deletions src/widgets/process_table/proc_widget_data.rs
Expand Up @@ -221,6 +221,10 @@ impl ProcWidgetData {

impl DataToCell<ProcColumn> for ProcWidgetData {
fn to_cell<'a>(&'a self, column: &ProcColumn, calculated_width: u16) -> Option<Text<'a>> {
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(
Expand Down
8 changes: 8 additions & 0 deletions src/widgets/process_table/sort_table.rs
Expand Up @@ -17,6 +17,10 @@ impl ColumnHeader for SortTableColumn {

impl DataToCell<SortTableColumn> for &'static str {
fn to_cell<'a>(&'a self, _column: &SortTableColumn, calculated_width: u16) -> Option<Text<'a>> {
if calculated_width == 0 {
return None;
}

Some(truncate_to_text(self, calculated_width))
}

Expand All @@ -30,6 +34,10 @@ impl DataToCell<SortTableColumn> for &'static str {

impl DataToCell<SortTableColumn> for Cow<'static, str> {
fn to_cell<'a>(&'a self, _column: &SortTableColumn, calculated_width: u16) -> Option<Text<'a>> {
if calculated_width == 0 {
return None;
}

Some(truncate_to_text(self, calculated_width))
}

Expand Down
4 changes: 4 additions & 0 deletions src/widgets/temperature_table.rs
Expand Up @@ -49,6 +49,10 @@ impl TempWidgetData {

impl DataToCell<TempWidgetColumn> for TempWidgetData {
fn to_cell<'a>(&'a self, column: &TempWidgetColumn, calculated_width: u16) -> Option<Text<'a>> {
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),
Expand Down

0 comments on commit 4a8feb3

Please sign in to comment.