Fixed column organization, need to refactor CPU side to remove any redundant code.

This commit is contained in:
ClementTsang 2020-03-01 17:41:45 -05:00
parent 227af7654f
commit 63f2ead48b
2 changed files with 85 additions and 69 deletions

View file

@ -244,7 +244,6 @@ pub struct App {
pub update_process_gui: bool,
pub app_scroll_positions: AppScrollState,
pub current_widget_selected: WidgetPosition,
pub data: data_harvester::Data,
awaiting_second_char: bool,
second_char: Option<char>,
pub dd_err: Option<String>,
@ -279,7 +278,6 @@ impl App {
update_process_gui: false,
current_widget_selected,
app_scroll_positions: AppScrollState::default(),
data: data_harvester::Data::default(),
awaiting_second_char: false,
second_char: None,
dd_err: None,

View file

@ -423,10 +423,19 @@ impl Painter {
// Basic mode. This basically removes all graphs but otherwise
// the same info.
let cpu_height = (app_state.canvas_data.cpu_data.len() / 4) as u16
+ (
if app_state.canvas_data.cpu_data.len() % 4 == 0 {
0
} else {
1
}
);
debug!("C: {}", cpu_height);
let vertical_chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Length(6),
Constraint::Length(cpu_height),
Constraint::Length(3),
Constraint::Min(5),
].as_ref())
@ -1581,27 +1590,21 @@ impl Painter {
let num_cpus = cpu_data.len();
if draw_loc.height > 0 {
let remaining_height = draw_loc.height as usize;
let required_columns = (num_cpus / remaining_height)
+ (if num_cpus % remaining_height == 0 {
0
} else {
1
});
let required_columns = 4;
if required_columns > 0 {
let chunk_vec =
vec![Constraint::Percentage((100 / required_columns) as u16); required_columns];
let chunks = Layout::default()
.constraints(chunk_vec.as_ref())
.direction(Direction::Horizontal)
.horizontal_margin(1)
.split(draw_loc);
let num_spaces = 2;
// +10 due to 4 + 4 + 2 columns for the name & space + percentage + bar bounds
// +9 due to 3 + 4 + 2 columns for the name & space + percentage + bar bounds
let margin_space = 2;
let remaining_width = max(
0,
draw_loc.width as i64 - ((num_spaces + 10) * required_columns) as i64,
draw_loc.width as i64
- ((9 + margin_space) * required_columns - margin_space) as i64,
) as usize;
let bar_length = remaining_width / required_columns;
@ -1646,10 +1649,16 @@ impl Painter {
)
})
.collect::<Vec<_>>();
let margined_loc = Layout::default()
.direction(Direction::Horizontal)
.constraints([Constraint::Percentage(100)].as_ref())
.horizontal_margin(1)
.split(*chunk);
Paragraph::new(cpu_column.iter())
.block(Block::default())
.render(f, *chunk);
}
.render(f, margined_loc[0]);
}
}
}
@ -1712,12 +1721,23 @@ impl Painter {
fn draw_basic_network<B: Backend>(
&self, f: &mut Frame<'_, B>, app_state: &mut app::App, draw_loc: Rect,
) {
let margined_loc = Layout::default()
let divided_loc = Layout::default()
.direction(Direction::Horizontal)
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
.horizontal_margin(1)
.split(draw_loc);
let net_loc = Layout::default()
.direction(Direction::Horizontal)
.constraints([Constraint::Percentage(100)].as_ref())
.horizontal_margin(1)
.split(divided_loc[0]);
let total_loc = Layout::default()
.direction(Direction::Horizontal)
.constraints([Constraint::Percentage(100)].as_ref())
.horizontal_margin(1)
.split(divided_loc[1]);
if let WidgetPosition::Network = app_state.current_widget_selected {
Block::default()
.borders(*SIDE_BORDERS)
@ -1741,13 +1761,11 @@ impl Painter {
];
Paragraph::new(net_text.iter())
.alignment(Alignment::Center)
.block(Block::default())
.render(f, margined_loc[0]);
.render(f, net_loc[0]);
Paragraph::new(total_net_text.iter())
.alignment(Alignment::Center)
.block(Block::default())
.render(f, margined_loc[1]);
.render(f, total_loc[0]);
}
}