Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rewrite column algorithm #227

Merged
merged 12 commits into from
Sep 10, 2020
Prev Previous commit
Next Next commit
More tweaking, this will now need left/right movement to look okay...
  • Loading branch information
ClementTsang committed Sep 9, 2020
commit a62e2e4af887f0d5d72351b49d7d178fcd7d7251
2 changes: 2 additions & 0 deletions src/app/data_harvester/disks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub async fn get_sysinfo_io_usage_list(
std::collections::HashMap::new();
Ok(Some(io_hash))

// TODO: Rename these functions to be like "get_arm_io_usage_list"

// TODO: Sysinfo disk I/O usage.
// ...sadly, this cannot be done as of now (other than me writing my own), it requires further
// work. See https://github.com/GuillaumeGomez/sysinfo/issues/304.
Expand Down
33 changes: 17 additions & 16 deletions src/canvas/drawing_utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::app;
use std::cmp::min;
use std::cmp::{max, min};

/// Return a (hard)-width vector for column widths.
///
Expand All @@ -23,18 +23,17 @@ pub fn get_column_widths(
soft_widths_max: &[Option<f64>], soft_widths_desired: &[Option<u16>],
spacing_priority: &[usize],
) -> Vec<u16> {
let initial_width = total_width.saturating_sub(hard_widths.len() as u16) + 1 - 2;
let initial_width = total_width - 2;
let mut total_width_left = initial_width;
let mut column_widths: Vec<u16> = vec![0; hard_widths.len()];

for itx in spacing_priority {
if let Some(Some(hard_width)) = hard_widths.get(*itx) {
// Hard width...
let space_taken = min(total_width_left, *hard_width);
if space_taken >= *hard_width {
column_widths[*itx] = space_taken;
total_width_left -= space_taken;
}
let space_taken = min(*hard_width, total_width_left);
column_widths[*itx] = space_taken;
total_width_left -= space_taken;
total_width_left = total_width_left.saturating_sub(1);
} else if let (
Some(Some(soft_width_max)),
Some(Some(soft_width_min)),
Expand All @@ -45,16 +44,18 @@ pub fn get_column_widths(
soft_widths_desired.get(*itx),
) {
// Soft width...
let soft_limit = if soft_width_max.is_sign_negative() {
*soft_width_desired
} else {
(*soft_width_max * initial_width as f64).ceil() as u16
};
let soft_limit = max(
if soft_width_max.is_sign_negative() {
*soft_width_desired
} else {
(*soft_width_max * initial_width as f64).ceil() as u16
},
*soft_width_min,
);
let space_taken = min(min(soft_limit, *soft_width_desired), total_width_left);
if space_taken >= *soft_width_min {
column_widths[*itx] = space_taken;
total_width_left -= space_taken;
}
column_widths[*itx] = space_taken;
total_width_left -= space_taken;
total_width_left = total_width_left.saturating_sub(1);
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/canvas/widgets/process_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,15 @@ impl ProcessTableWidget for Painter {
.collect::<Vec<_>>()),
&column_bias,
);

debug!(
"DCW: {:?}",
proc_widget_state.table_width_state.desired_column_widths
);
debug!(
"CCW: {:?}",
proc_widget_state.table_width_state.calculated_column_widths
);
}

let ccw = &proc_widget_state.table_width_state.calculated_column_widths;
Expand Down
2 changes: 1 addition & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ pub const DEFAULT_BATTERY_LAYOUT: &str = r##"
pub const DEFAULT_CONFIG_FILE_PATH: &str = "bottom/bottom.toml";

// Default config file
// FIXME: Update the default config
// FIXME [CHORE]: Update the default config
pub const DEFAULT_CONFIG_CONTENT: &str = r##"
# This is a default config file for bottom. All of the settings are commented
# out by default; if you wish to change them uncomment and modify as you see
Expand Down