diff --git a/examples/prototype.rs b/examples/prototype.rs index 959b9fcd..297013c9 100644 --- a/examples/prototype.rs +++ b/examples/prototype.rs @@ -26,6 +26,7 @@ struct App { fetching: bool, items: Vec, selected: usize, + show_episodes: bool, } enum Event { @@ -56,6 +57,7 @@ fn main() { fetching: false, items: ["1", "2", "3"].into_iter().map(|e| String::from(*e)).collect(), selected: 0, + show_episodes: false, }; let (tx, rx) = mpsc::channel(); @@ -94,6 +96,9 @@ fn main() { app.selected += 1; } } + event::Key::Char('t') => { + app.show_episodes = !app.show_episodes; + } _ => {} } } @@ -113,10 +118,15 @@ fn draw(terminal: &mut Terminal, app: &App) { .borders(Border::ALL) .title("Header") .render(&chunks[0])); + let sizes = if app.show_episodes { + vec![Size::Percent(50), Size::Percent(50)] + } else { + vec![Size::Percent(50), Size::Percent(50)] + }; tree.add(Group::default() .direction(Direction::Horizontal) .alignment(Alignment::Left) - .chunks(&[Size::Percent(50), Size::Percent(50)]) + .chunks(&sizes) .render(&chunks[1], |chunks, tree| { tree.add(List::default() .block(|b| { @@ -129,10 +139,12 @@ fn draw(terminal: &mut Terminal, app: &App) { format!("{} {}", prefix, i) }) .render(&chunks[0])); - tree.add(Block::default() - .borders(Border::ALL) - .title("Episodes") - .render(&chunks[1])); + if app.show_episodes { + tree.add(Block::default() + .borders(Border::ALL) + .title("Episodes") + .render(&chunks[1])); + } })); tree.add(Block::default().borders(Border::ALL).title("Footer").render(&chunks[2])); }); diff --git a/src/terminal.rs b/src/terminal.rs index 35d94ac4..8ff1124c 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -39,6 +39,7 @@ impl Terminal { } pub fn render(&mut self, ui: Tree) { + info!("Render"); let mut buffers: Vec = Vec::new(); let mut previous: HashMap<(WidgetType, u64), Rect> = HashMap::new(); for node in ui.into_iter() { @@ -55,6 +56,9 @@ impl Terminal { } previous.insert((node.widget_type, node.hash), area); } + for (_, area) in &self.previous { + buffers.insert(0, Buffer::empty(*area)); + } for buf in buffers { self.render_buffer(&buf); info!("{:?}", buf.area());