diff --git a/examples/prototype.rs b/examples/prototype.rs index b76db03..bf1d508 100644 --- a/examples/prototype.rs +++ b/examples/prototype.rs @@ -22,8 +22,8 @@ use log4rs::config::{Appender, Config, Root}; use tui::Terminal; use tui::widgets::{Widget, Block, List, Gauge, Sparkline, Text, border, Chart, Axis, Dataset, - BarChart, Marker, Tabs}; -use tui::widgets::canvas::{Canvas, Shape, Line, Map, MapResolution}; + BarChart, Marker, Tabs, Table}; +use tui::widgets::canvas::{Canvas, Line, Map, MapResolution}; use tui::layout::{Group, Direction, Size, Rect}; use tui::style::Color; @@ -287,19 +287,24 @@ fn draw(t: &mut Terminal, app: &App) { draw_main(t, app, &chunks[1]); } 1 => { - Canvas::default() - .block(Block::default().title("World").borders(border::ALL)) - .layers(&[&[Map::default().resolution(MapResolution::High)], - &[&Line { - x1: 0.0, - y1: 0.0, - x2: 10.0, - y2: 10.0, - color: Color::Red, - }]]) - .x_bounds([180.0, 0.0]) - .y_bounds([0.0, 90.0]) - .render(&chunks[1], t); + Group::default() + .direction(Direction::Vertical) + .sizes(&[Size::Percent(50), Size::Percent(50)]) + .render(t, &chunks[1], |t, chunks| { + Table::default() + .block(Block::default().title("Servers").borders(border::ALL)) + .titles(&["Server", "Location", "Status"]) + .widths(&[20, 20, 20]) + .rows(&[&["Europe#1", "Paris", "Up"], + &["Europe#2", "Berlin", "Up"]]) + .render(&chunks[0], t); + Canvas::default() + .block(Block::default().title("World").borders(border::ALL)) + .layers(&[&[Map::default().resolution(MapResolution::High)]]) + .x_bounds([180.0, -180.0]) + .y_bounds([-90.0, 90.0]) + .render(&chunks[1], t); + }) } _ => {} }; diff --git a/src/lib.rs b/src/lib.rs index 18deaa0..f9cefb7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,10 +15,4 @@ pub mod widgets; pub mod style; pub mod layout; -pub use self::terminal::Terminal; - -#[cfg(test)] -mod tests { - #[test] - fn it_works() {} -} +pub use self::terminal::Terminal; \ No newline at end of file diff --git a/src/widgets/block.rs b/src/widgets/block.rs index 23eb565..8b8877d 100644 --- a/src/widgets/block.rs +++ b/src/widgets/block.rs @@ -1,4 +1,3 @@ - use buffer::Buffer; use layout::Rect; use style::Color; @@ -119,17 +118,27 @@ impl<'a> Widget for Block<'a> { if self.borders.contains(border::RIGHT | border::BOTTOM) { buf.set_symbol(area.right() - 1, area.bottom() - 1, line::BOTTOM_RIGHT); } - if let Some(title) = self.title { - let dx = if self.borders.intersects(border::LEFT) { - 1 - } else { - 0 - }; - buf.set_string(area.left() + dx, - area.top(), - title, - self.title_color, - self.bg); + + if area.width > 2 { + if let Some(title) = self.title { + let lx = if self.borders.intersects(border::LEFT) { + 1 + } else { + 0 + }; + let rx = if self.borders.intersects(border::RIGHT) { + 1 + } else { + 0 + }; + let width = area.width - lx - rx; + buf.set_stringn(area.left() + lx, + area.top(), + title, + width as usize, + self.title_color, + self.bg); + } } } } diff --git a/src/widgets/list.rs b/src/widgets/list.rs index 4343e01..e5e1110 100644 --- a/src/widgets/list.rs +++ b/src/widgets/list.rs @@ -95,19 +95,24 @@ impl<'a> Widget for List<'a> { Some(s) => (s.width() + 1) as u16 + list_area.left(), None => list_area.left(), }; - for i in 0..bound { - let index = i + offset; - let item = self.items[index]; - let color = if index == self.selected { - self.selection_color - } else { - self.color - }; - buf.set_string(x, - list_area.top() + i as u16, - item, - color, - self.background_color); + + if x < list_area.right() { + let width = (list_area.right() - x) as usize; + for i in 0..bound { + let index = i + offset; + let item = self.items[index]; + let color = if index == self.selected { + self.selection_color + } else { + self.color + }; + buf.set_stringn(x, + list_area.top() + i as u16, + item, + width, + color, + self.background_color); + } } if let Some(s) = self.selection_symbol { buf.set_string(list_area.left(), diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs index 13b6eed..8e5092b 100644 --- a/src/widgets/mod.rs +++ b/src/widgets/mod.rs @@ -6,6 +6,7 @@ mod sparkline; mod chart; mod barchart; mod tabs; +mod table; pub mod canvas; pub use self::block::Block; @@ -16,6 +17,7 @@ pub use self::sparkline::Sparkline; pub use self::chart::{Chart, Axis, Dataset, Marker}; pub use self::barchart::BarChart; pub use self::tabs::Tabs; +pub use self::table::Table; use buffer::Buffer; use layout::Rect;