From d80c2387fb70f6a2c1234b211cf677711e280cba Mon Sep 17 00:00:00 2001 From: ClementTsang Date: Sun, 8 Sep 2019 14:14:50 -0400 Subject: [PATCH] Setup layout. --- src/window/mod.rs | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/window/mod.rs b/src/window/mod.rs index 585767c0..bfb6a46f 100644 --- a/src/window/mod.rs +++ b/src/window/mod.rs @@ -13,7 +13,40 @@ pub fn create_terminal() -> Result<(), io::Error> { let mut terminal = Terminal::new(backend)?; terminal.clear()?; terminal.draw(|mut f| { - let size = f.size(); - Block::default().title("CPU Usage").borders(Borders::ALL).render(&mut f, size); + let vertical_chunks = Layout::default() + .direction(Direction::Vertical) + .margin(1) + .constraints([Constraint::Percentage(33), Constraint::Percentage(34), Constraint::Percentage(33)].as_ref()) + .split(f.size()); + let top_chunks = Layout::default() + .direction(Direction::Horizontal) + .margin(0) + .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref()) + .split(vertical_chunks[0]); + let middle_chunks = Layout::default() + .direction(Direction::Horizontal) + .margin(0) + .constraints([Constraint::Percentage(40), Constraint::Percentage(60)].as_ref()) + .split(vertical_chunks[1]); + let middle_divided_chunk = Layout::default() + .direction(Direction::Vertical) + .margin(0) + .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref()) + .split(middle_chunks[0]); + let bottom_chunks = Layout::default() + .direction(Direction::Horizontal) + .margin(0) + .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref()) + .split(vertical_chunks[2]); + + Block::default().title("CPU Usage").borders(Borders::ALL).render(&mut f, top_chunks[0]); + Block::default().title("Memory Usage").borders(Borders::ALL).render(&mut f, top_chunks[1]); + + Block::default().title("Temperatures").borders(Borders::ALL).render(&mut f, middle_divided_chunk[0]); + Block::default().title("Disk Usage").borders(Borders::ALL).render(&mut f, middle_divided_chunk[1]); + Block::default().title("IO Usage").borders(Borders::ALL).render(&mut f, middle_chunks[1]); + + Block::default().title("Network").borders(Borders::ALL).render(&mut f, bottom_chunks[0]); + Block::default().title("Processes").borders(Borders::ALL).render(&mut f, bottom_chunks[1]); }) }