diff options
author | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-05 18:46:26 +0530 |
---|---|---|
committer | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-05 18:46:26 +0530 |
commit | 7549e82fa1afc3fd87af6e42c13757a1c11994ea (patch) | |
tree | 2b74c7d2113dd0e78f35661515cb65f8867269a4 /tui-react/src | |
parent | ae679ed0daed2f2faf1bd8b4db922bdf450f738a (diff) |
Finally, everything was properly ported to tui-react
Diffstat (limited to 'tui-react/src')
-rw-r--r-- | tui-react/src/list.rs | 2 | ||||
-rw-r--r-- | tui-react/src/terminal.rs | 20 |
2 files changed, 15 insertions, 7 deletions
diff --git a/tui-react/src/list.rs b/tui-react/src/list.rs index 05984e1..e61162e 100644 --- a/tui-react/src/list.rs +++ b/tui-react/src/list.rs @@ -17,7 +17,7 @@ pub fn fill_background_to_right(mut s: String, entire_width: u16) -> String { } } -#[derive(Default, Clone)] // TODO: remove Clone derive +#[derive(Default)] pub struct ReactList { /// The index at which the list last started. Used for scrolling offset: usize, diff --git a/tui-react/src/terminal.rs b/tui-react/src/terminal.rs index bc7c37b..d507f20 100644 --- a/tui-react/src/terminal.rs +++ b/tui-react/src/terminal.rs @@ -82,16 +82,15 @@ where Ok(()) } - pub fn render<C>(&mut self, component: &mut C, props: impl Borrow<C::Props>) -> io::Result<()> - where - C: ToplevelComponent, - { + /// Get ready for rendering and return the maximum display size as `Rect` + pub fn pre_render(&mut self) -> io::Result<Rect> { // Autoresize - otherwise we get glitches if shrinking or potential desync between widgets // and the terminal (if growing), which may OOB. self.autoresize()?; + Ok(self.known_size.clone()) + } - component.render(props, self.known_size, self.current_buffer_mut()); - + pub fn post_render(&mut self) -> io::Result<()> { self.reconcile_and_flush()?; self.buffers[1 - self.current].reset(); @@ -101,6 +100,15 @@ where Ok(()) } + pub fn render<C>(&mut self, component: &mut C, props: impl Borrow<C::Props>) -> io::Result<()> + where + C: ToplevelComponent, + { + self.pre_render()?; + component.render(props, self.known_size, self.current_buffer_mut()); + self.post_render() + } + pub fn hide_cursor(&mut self) -> io::Result<()> { self.backend.hide_cursor()?; self.hidden_cursor = true; |