2016-10-09 17:46:53 +00:00
|
|
|
mod block;
|
2016-11-06 17:49:57 +00:00
|
|
|
mod paragraph;
|
2016-10-11 17:54:35 +00:00
|
|
|
mod list;
|
2016-10-12 14:12:42 +00:00
|
|
|
mod gauge;
|
2016-10-12 17:43:39 +00:00
|
|
|
mod sparkline;
|
2016-10-14 17:44:52 +00:00
|
|
|
mod chart;
|
2016-10-22 10:51:41 +00:00
|
|
|
mod barchart;
|
2016-10-27 17:36:55 +00:00
|
|
|
mod tabs;
|
2016-11-01 14:59:33 +00:00
|
|
|
mod table;
|
2016-11-01 11:09:14 +00:00
|
|
|
pub mod canvas;
|
2016-10-09 17:46:53 +00:00
|
|
|
|
|
|
|
pub use self::block::Block;
|
2016-11-06 17:49:57 +00:00
|
|
|
pub use self::paragraph::Paragraph;
|
2016-11-07 10:56:08 +00:00
|
|
|
pub use self::list::{List, SelectableList};
|
2016-10-12 14:12:42 +00:00
|
|
|
pub use self::gauge::Gauge;
|
2016-10-12 17:43:39 +00:00
|
|
|
pub use self::sparkline::Sparkline;
|
2016-10-27 10:35:56 +00:00
|
|
|
pub use self::chart::{Chart, Axis, Dataset, Marker};
|
2016-10-22 10:51:41 +00:00
|
|
|
pub use self::barchart::BarChart;
|
2016-10-27 17:36:55 +00:00
|
|
|
pub use self::tabs::Tabs;
|
2016-11-01 14:59:33 +00:00
|
|
|
pub use self::table::Table;
|
2016-10-12 14:12:42 +00:00
|
|
|
|
2016-10-20 15:17:35 +00:00
|
|
|
use buffer::Buffer;
|
2016-10-15 22:38:20 +00:00
|
|
|
use layout::Rect;
|
2016-11-28 08:52:51 +00:00
|
|
|
use terminal::Terminal;
|
|
|
|
use backend::Backend;
|
2016-11-02 16:08:52 +00:00
|
|
|
use style::Color;
|
2016-10-09 17:46:53 +00:00
|
|
|
|
2016-11-03 22:59:04 +00:00
|
|
|
/// Bitflags that can be composed to set the visible borders essentially on the block widget.
|
2016-10-12 14:12:42 +00:00
|
|
|
pub mod border {
|
2016-10-09 17:46:53 +00:00
|
|
|
bitflags! {
|
|
|
|
pub flags Flags: u32 {
|
2016-11-04 18:27:19 +00:00
|
|
|
/// Show no border (default)
|
2016-10-09 17:46:53 +00:00
|
|
|
const NONE = 0b00000001,
|
2016-11-04 18:27:19 +00:00
|
|
|
/// Show the top border
|
2016-10-09 17:46:53 +00:00
|
|
|
const TOP = 0b00000010,
|
2016-11-04 18:27:19 +00:00
|
|
|
/// Show the right border
|
2016-10-09 17:46:53 +00:00
|
|
|
const RIGHT = 0b00000100,
|
2016-11-04 18:27:19 +00:00
|
|
|
/// Show the bottom border
|
2016-10-09 17:46:53 +00:00
|
|
|
const BOTTOM = 0b0001000,
|
2016-11-04 18:27:19 +00:00
|
|
|
/// Show the left border
|
2016-10-09 17:46:53 +00:00
|
|
|
const LEFT = 0b00010000,
|
2016-11-04 18:27:19 +00:00
|
|
|
/// Show all borders
|
2016-10-09 17:46:53 +00:00
|
|
|
const ALL = TOP.bits | RIGHT.bits | BOTTOM.bits | LEFT.bits,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-03 22:59:04 +00:00
|
|
|
/// Base requirements for a Widget
|
2016-10-26 12:32:45 +00:00
|
|
|
pub trait Widget {
|
2016-11-03 22:59:04 +00:00
|
|
|
/// Draws the current state of the widget in the given buffer. That the only method required to
|
|
|
|
/// implement a custom widget.
|
2017-09-03 09:58:39 +00:00
|
|
|
fn draw(&mut self, area: &Rect, buf: &mut Buffer);
|
2016-11-03 22:59:04 +00:00
|
|
|
/// Helper method to quickly set the background of all cells inside the specified area.
|
2016-11-02 16:08:52 +00:00
|
|
|
fn background(&self, area: &Rect, buf: &mut Buffer, color: Color) {
|
|
|
|
for y in area.top()..area.bottom() {
|
|
|
|
for x in area.left()..area.right() {
|
2016-11-06 17:49:57 +00:00
|
|
|
buf.get_mut(x, y).set_bg(color);
|
2016-11-02 16:08:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-03 22:59:04 +00:00
|
|
|
/// Helper method that can be chained with a widget's builder methods to render it.
|
2017-09-03 09:58:39 +00:00
|
|
|
fn render<B>(&mut self, t: &mut Terminal<B>, area: &Rect)
|
2016-11-05 18:18:48 +00:00
|
|
|
where Self: Sized,
|
|
|
|
B: Backend
|
2016-10-26 12:32:45 +00:00
|
|
|
{
|
|
|
|
t.render(self, area);
|
2016-10-11 17:54:35 +00:00
|
|
|
}
|
2016-10-09 17:46:53 +00:00
|
|
|
}
|