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
Fix bug w/ filtering
  • Loading branch information
ClementTsang committed Sep 10, 2020
commit f3eb760b52d8b5a8a70067e31671eb9bc22a9b66
24 changes: 14 additions & 10 deletions src/app/states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,16 +342,20 @@ impl ProcColumn {
}

if mapping.enabled {
Some(if proc_sorting_type == column_type {
format!(
"{}{}{}",
column_type.to_string(),
command_str.as_str(),
if sort_reverse { DOWN_ARROW } else { UP_ARROW }
)
} else {
format!("{}{}", column_type.to_string(), command_str.as_str(),)
})
Some(format!(
"{}{}{}",
column_type.to_string(),
command_str.as_str(),
if proc_sorting_type == column_type {
if sort_reverse {
DOWN_ARROW
} else {
UP_ARROW
}
} else {
' '
}
))
} else {
None
}
Expand Down
2 changes: 2 additions & 0 deletions src/canvas/drawing_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ pub fn get_column_widths(

// TODO [COLUMN MOVEMENT]: Remove this
if *soft_width_min > space_taken {
debug!("soft_width_min: {}", soft_width_min);
debug!("space_taken: {}", space_taken);
break;
}

Expand Down
5 changes: 4 additions & 1 deletion src/canvas/widgets/cpu_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,10 @@ impl CpuGraphWidget for Painter {
cpu_widget_state.table_width_state.calculated_column_widths = get_column_widths(
draw_loc.width,
&[None, None],
&[Some(3), Some(4)],
&(CPU_LEGEND_HEADER_LENS
.iter()
.map(|width| Some(*width))
.collect::<Vec<_>>()),
&[Some(0.5), Some(0.5)],
&(cpu_widget_state
.table_width_state
Expand Down
30 changes: 22 additions & 8 deletions src/canvas/widgets/process_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,20 @@ impl ProcessTableWidget for Painter {
if recalculate_column_widths {
let mut column_widths = process_headers
.iter()
.map(|entry| std::cmp::max(entry.len(), 5) as u16)
.map(|entry| entry.len() as u16)
.collect::<Vec<_>>();
let soft_widths_min = column_widths
.iter()
.map(|width| Some(*width))
.collect::<Vec<_>>();

proc_widget_state.table_width_state.desired_column_widths = {
for (row, _disabled) in processed_sliced_vec.clone() {
for (col, entry) in row.iter().enumerate() {
if let Some(col_width) = column_widths.get_mut(col) {
if entry.len() as u16 > *col_width {
*col_width = entry.len() as u16;
let grapheme_len = UnicodeWidthStr::width_cjk(entry.as_str());
if grapheme_len as u16 > *col_width {
*col_width = grapheme_len as u16;
}
}
}
Expand All @@ -273,6 +278,8 @@ impl ProcessTableWidget for Painter {
let soft_widths_max = if proc_widget_state.is_grouped {
if proc_widget_state.is_using_command {
vec![None, Some(0.6), None, None, None, None, None, None]
} else if proc_widget_state.is_tree_mode {
vec![None, Some(0.5), None, None, None, None, None, None]
} else {
vec![None, Some(0.4), None, None, None, None, None, None]
}
Expand All @@ -288,6 +295,18 @@ impl ProcessTableWidget for Painter {
None,
Some(0.2),
]
} else if proc_widget_state.is_tree_mode {
vec![
None,
Some(0.5),
None,
None,
None,
None,
None,
None,
Some(0.2),
]
} else {
vec![
None,
Expand All @@ -301,11 +320,6 @@ impl ProcessTableWidget for Painter {
Some(0.2),
]
};
let soft_widths_min = if proc_widget_state.is_grouped {
vec![None, Some(8), None, None, None, None, None, None]
} else {
vec![None, Some(8), None, None, None, None, None, None, Some(5)]
};

proc_widget_state.table_width_state.calculated_column_widths =
get_column_widths(
Expand Down