diff options
author | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-06 08:08:15 +0530 |
---|---|---|
committer | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-06 08:08:15 +0530 |
commit | 7bef5974e86de825dcb0b3507df16a80b6986d88 (patch) | |
tree | 965fa139b9b56d0adba0a21cf180741c01ea3bea /tui-react | |
parent | 982446ad0ef9a475274c9a0f05a32147fcafd061 (diff) |
refactor
Diffstat (limited to 'tui-react')
-rw-r--r-- | tui-react/src/lib.rs | 16 | ||||
-rw-r--r-- | tui-react/src/list.rs | 23 |
2 files changed, 17 insertions, 22 deletions
diff --git a/tui-react/src/lib.rs b/tui-react/src/lib.rs index af8f6ac..e44e39f 100644 --- a/tui-react/src/lib.rs +++ b/tui-react/src/lib.rs @@ -4,12 +4,18 @@ mod terminal; pub use list::*; pub use terminal::*; -/// re-export our exact version, in case it matters to someone -pub use tui; +use std::iter::repeat; +use tui::{self, buffer::Buffer, layout::Rect, style::Color}; -use tui::buffer::Buffer; -use tui::layout::Rect; -use tui::style::Color; +pub fn fill_background_to_right(mut s: String, entire_width: u16) -> String { + match (s.len(), entire_width as usize) { + (x, y) if x >= y => s, + (x, y) => { + s.extend(repeat(' ').take(y - x)); + s + } + } +} /// Helper method to quickly set the background of all cells inside the specified area. pub fn fill_background(area: Rect, buf: &mut Buffer, color: Color) { diff --git a/tui-react/src/list.rs b/tui-react/src/list.rs index d9510ff..45976dd 100644 --- a/tui-react/src/list.rs +++ b/tui-react/src/list.rs @@ -1,27 +1,16 @@ -use std::iter::repeat; use tui::{ buffer::Buffer, layout::Rect, widgets::{Block, Paragraph, Text, Widget}, }; -pub fn fill_background_to_right(mut s: String, entire_width: u16) -> String { - match (s.len(), entire_width as usize) { - (x, y) if x >= y => s, - (x, y) => { - s.extend(repeat(' ').take(y - x)); - s - } - } -} - #[derive(Default)] -pub struct ReactList { +pub struct List { /// The index at which the list last started. Used for scrolling offset: usize, } -impl ReactList { +impl List { fn list_offset_for(&self, entry_in_view: Option<usize>, height: usize) -> usize { match entry_in_view { Some(pos) => match height as usize { @@ -35,20 +24,20 @@ impl ReactList { } #[derive(Default)] -pub struct ReactListProps<'b> { +pub struct ListProps<'b> { pub block: Option<Block<'b>>, pub entry_in_view: Option<usize>, } -impl ReactList { +impl List { pub fn render<'a, 't>( &mut self, - props: ReactListProps<'a>, + props: ListProps<'a>, items: impl IntoIterator<Item = Vec<Text<'t>>>, area: Rect, buf: &mut Buffer, ) { - let ReactListProps { + let ListProps { block, entry_in_view, } = props; |