summaryrefslogtreecommitdiffstats
path: root/src/ui/scrolllist.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/scrolllist.rs')
-rw-r--r--src/ui/scrolllist.rs112
1 files changed, 56 insertions, 56 deletions
diff --git a/src/ui/scrolllist.rs b/src/ui/scrolllist.rs
index 6fe8017e..adc04bb3 100644
--- a/src/ui/scrolllist.rs
+++ b/src/ui/scrolllist.rs
@@ -1,87 +1,87 @@
use super::style::SharedTheme;
use std::iter::Iterator;
use tui::{
- backend::Backend,
- buffer::Buffer,
- layout::Rect,
- style::Style,
- text::Span,
- widgets::{Block, Borders, List, ListItem, Widget},
- Frame,
+ backend::Backend,
+ buffer::Buffer,
+ layout::Rect,
+ style::Style,
+ text::Span,
+ widgets::{Block, Borders, List, ListItem, Widget},
+ Frame,
};
///
struct ScrollableList<'b, L>
where
- L: Iterator<Item = Span<'b>>,
+ L: Iterator<Item = Span<'b>>,
{
- block: Option<Block<'b>>,
- /// Items to be displayed
- items: L,
- /// Base style of the widget
- style: Style,
+ block: Option<Block<'b>>,
+ /// Items to be displayed
+ items: L,
+ /// Base style of the widget
+ style: Style,
}
impl<'b, L> ScrollableList<'b, L>
where
- L: Iterator<Item = Span<'b>>,
+ L: Iterator<Item = Span<'b>>,
{
- fn new(items: L) -> Self {
- Self {
- block: None,
- items,
- style: Style::default(),
- }
- }
+ fn new(items: L) -> Self {
+ Self {
+ block: None,
+ items,
+ style: Style::default(),
+ }
+ }
- fn block(mut self, block: Block<'b>) -> Self {
- self.block = Some(block);
- self
- }
+ fn block(mut self, block: Block<'b>) -> Self {
+ self.block = Some(block);
+ self
+ }
}
impl<'b, L> Widget for ScrollableList<'b, L>
where
- L: Iterator<Item = Span<'b>>,
+ L: Iterator<Item = Span<'b>>,
{
- fn render(self, area: Rect, buf: &mut Buffer) {
- // Render items
- List::new(
- self.items.map(ListItem::new).collect::<Vec<ListItem>>(),
- )
- .block(self.block.unwrap_or_default())
- .style(self.style)
- .render(area, buf);
- }
+ fn render(self, area: Rect, buf: &mut Buffer) {
+ // Render items
+ List::new(
+ self.items.map(ListItem::new).collect::<Vec<ListItem>>(),
+ )
+ .block(self.block.unwrap_or_default())
+ .style(self.style)
+ .render(area, buf);
+ }
}
pub fn draw_list<'b, B: Backend, L>(
- f: &mut Frame<B>,
- r: Rect,
- title: &'b str,
- items: L,
- selected: bool,
- theme: &SharedTheme,
+ f: &mut Frame<B>,
+ r: Rect,
+ title: &'b str,
+ items: L,
+ selected: bool,
+ theme: &SharedTheme,
) where
- L: Iterator<Item = Span<'b>>,
+ L: Iterator<Item = Span<'b>>,
{
- let list = ScrollableList::new(items).block(
- Block::default()
- .title(Span::styled(title, theme.title(selected)))
- .borders(Borders::ALL)
- .border_style(theme.block(selected)),
- );
- f.render_widget(list, r);
+ let list = ScrollableList::new(items).block(
+ Block::default()
+ .title(Span::styled(title, theme.title(selected)))
+ .borders(Borders::ALL)
+ .border_style(theme.block(selected)),
+ );
+ f.render_widget(list, r);
}
pub fn draw_list_block<'b, B: Backend, L>(
- f: &mut Frame<B>,
- r: Rect,
- block: Block<'b>,
- items: L,
+ f: &mut Frame<B>,
+ r: Rect,
+ block: Block<'b>,
+ items: L,
) where
- L: Iterator<Item = Span<'b>>,
+ L: Iterator<Item = Span<'b>>,
{
- let list = ScrollableList::new(items).block(block);
- f.render_widget(list, r);
+ let list = ScrollableList::new(items).block(block);
+ f.render_widget(list, r);
}