summaryrefslogtreecommitdiffstats
path: root/src/canvas
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2020-11-02 22:39:02 -0500
committerGitHub <noreply@github.com>2020-11-02 22:39:02 -0500
commite8358f8f47f707b2af99e3b69dd1d7c3d2ca0ef3 (patch)
tree6e783692e52373ecf81d32a557ee596a25171801 /src/canvas
parent9e858713fda0c622e74b47bca14bf985655273da (diff)
bug: fix incorrect basic cpu spacing (#291)
Fixes a bug with CPU spacing on basic mode.
Diffstat (limited to 'src/canvas')
-rw-r--r--src/canvas/widgets/cpu_basic.rs8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/canvas/widgets/cpu_basic.rs b/src/canvas/widgets/cpu_basic.rs
index c42350cc..8e6b332f 100644
--- a/src/canvas/widgets/cpu_basic.rs
+++ b/src/canvas/widgets/cpu_basic.rs
@@ -26,7 +26,7 @@ impl CpuBasicWidget for Painter {
&self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
) {
// Skip the first element, it's the "all" element
- if !app_state.canvas_data.cpu_data.is_empty() {
+ if app_state.canvas_data.cpu_data.len() > 1 {
let cpu_data: &[ConvertedCpuData] = &app_state.canvas_data.cpu_data[1..];
// This is a bit complicated, but basically, we want to draw SOME number
@@ -64,7 +64,7 @@ impl CpuBasicWidget for Painter {
// +9 due to 3 + 4 + 2 columns for the name & space + percentage + bar bounds
const MARGIN_SPACE: usize = 2;
let remaining_width = usize::from(draw_loc.width)
- .saturating_sub((9 + MARGIN_SPACE) * REQUIRED_COLUMNS - MARGIN_SPACE);
+ .saturating_sub((9 + MARGIN_SPACE) * REQUIRED_COLUMNS);
let bar_length = remaining_width / REQUIRED_COLUMNS;
@@ -100,7 +100,8 @@ impl CpuBasicWidget for Painter {
let mut row_counter = num_cpus;
let mut start_index = 0;
for (itx, chunk) in chunks.iter().enumerate() {
- // Explicitly check... don't want an accidental DBZ or underflow
+ // Explicitly check... don't want an accidental DBZ or underflow, this ensures
+ // to_divide is > 0
if REQUIRED_COLUMNS > itx {
let to_divide = REQUIRED_COLUMNS - itx;
let how_many_cpus = min(
@@ -110,6 +111,7 @@ impl CpuBasicWidget for Painter {
);
row_counter -= how_many_cpus;
let end_index = min(start_index + how_many_cpus, num_cpus);
+
let cpu_column = (start_index..end_index)
.map(|cpu_index| {
Spans::from(Span {