Skip to content

Commit

Permalink
First sketch of 'better' list - support for paragraphs for each item
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thiel committed Jun 4, 2019
1 parent 0121a64 commit a5a7c06
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/interactive/widgets/list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use tui::buffer::Buffer;
use tui::layout::{Corner, Rect};
use tui::style::Style;
use tui::widgets::{Block, Paragraph, Text, Widget};

pub struct List<'b, 't, I, T>
where
I: IntoIterator<Item = Paragraph<'b, 't, T>>,
T: Iterator<Item = &'t Text<'t>>,
{
pub block: Option<Block<'b>>,
pub items: I,
pub style: Style,
pub start_corner: Corner,
}

impl<'b, 't, I, T> Widget for List<'b, 't, I, T>
where
I: IntoIterator<Item = Paragraph<'b, 't, T>>,
T: Iterator<Item = &'t Text<'t>>,
{
fn draw(&mut self, area: Rect, buf: &mut Buffer) {
// let list_area = match self.block {
// Some(ref mut b) => {
// b.draw(area, buf);
// b.inner(area)
// }
// None => area,
// };
//
// if list_area.width < 1 || list_area.height < 1 {
// return;
// }
//
// self.background(list_area, buf, self.style.bg);
//
// for (i, item) in self
// .items
// .by_ref()
// .enumerate()
// .take(list_area.height as usize)
// {
// let (x, y) = match self.start_corner {
// Corner::TopLeft => (list_area.left(), list_area.top() + i as u16),
// Corner::BottomLeft => (list_area.left(), list_area.bottom() - (i + 1) as u16),
// // Not supported
// _ => (list_area.left(), list_area.top() + i as u16),
// };
// match item {
// Text::Raw(ref v) => {
// buf.set_stringn(x, y, v, list_area.width as usize, Style::default());
// }
// Text::Styled(ref v, s) => {
// buf.set_stringn(x, y, v, list_area.width as usize, s);
// }
// };
// }
}
}
2 changes: 2 additions & 0 deletions src/interactive/widgets/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
mod entries;
mod footer;
mod list;
mod main;

pub use entries::*;
pub use footer::*;
pub use list::*;
pub use main::*;

0 comments on commit a5a7c06

Please sign in to comment.