diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 5c8ad32a..32502c1a 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -1,14 +1,8 @@ mod scrolllist; pub mod style; -use scrolllist::ScrollableList; -use style::SharedTheme; -use tui::{ - backend::Backend, - layout::{Constraint, Direction, Layout, Rect}, - widgets::{Block, Borders, Text}, - Frame, -}; +pub use scrolllist::draw_list; +use tui::layout::{Constraint, Direction, Layout, Rect}; /// return the scroll position (line) necessary to have the `selection` in view if it is not already pub fn calc_scroll_top( @@ -84,26 +78,3 @@ pub fn centered_rect_absolute( height.min(r.height), ) } - -pub fn draw_list<'b, B: Backend, L>( - f: &mut Frame, - r: Rect, - title: &'b str, - items: L, - select: Option, - selected: bool, - theme: &SharedTheme, -) where - L: Iterator>, -{ - let list = ScrollableList::new(items) - .block( - Block::default() - .title(title) - .borders(Borders::ALL) - .title_style(theme.title(selected)) - .border_style(theme.block(selected)), - ) - .scroll(select.unwrap_or_default()); - f.render_widget(list, r) -} diff --git a/src/ui/scrolllist.rs b/src/ui/scrolllist.rs index ea2a5703..e7e12afb 100644 --- a/src/ui/scrolllist.rs +++ b/src/ui/scrolllist.rs @@ -1,13 +1,16 @@ +use super::style::SharedTheme; use std::iter::Iterator; use tui::{ + backend::Backend, buffer::Buffer, layout::Rect, style::Style, - widgets::{Block, List, Text, Widget}, + widgets::{Block, Borders, List, Text, Widget}, + Frame, }; /// -pub struct ScrollableList<'b, L> +struct ScrollableList<'b, L> where L: Iterator>, { @@ -24,7 +27,7 @@ impl<'b, L> ScrollableList<'b, L> where L: Iterator>, { - pub fn new(items: L) -> Self { + fn new(items: L) -> Self { Self { block: None, items, @@ -33,12 +36,12 @@ where } } - pub fn block(mut self, block: Block<'b>) -> Self { + fn block(mut self, block: Block<'b>) -> Self { self.block = Some(block); self } - pub fn scroll(mut self, index: usize) -> Self { + fn scroll(mut self, index: usize) -> Self { self.scroll = index; self } @@ -56,3 +59,26 @@ where .render(area, buf); } } + +pub fn draw_list<'b, B: Backend, L>( + f: &mut Frame, + r: Rect, + title: &'b str, + items: L, + select: Option, + selected: bool, + theme: &SharedTheme, +) where + L: Iterator>, +{ + let list = ScrollableList::new(items) + .block( + Block::default() + .title(title) + .borders(Borders::ALL) + .title_style(theme.title(selected)) + .border_style(theme.block(selected)), + ) + .scroll(select.unwrap_or_default()); + f.render_widget(list, r) +}