tui-rs/src/widgets/mod.rs

69 lines
2.0 KiB
Rust
Raw Normal View History

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;
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;
mod tabs;
2016-11-01 14:59:33 +00:00
mod table;
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;
pub use self::list::{List, SelectableList};
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;
pub use self::tabs::Tabs;
2016-11-01 14:59:33 +00:00
pub use self::table::Table;
2016-10-20 15:17:35 +00:00
use buffer::Buffer;
use layout::Rect;
use terminal::Terminal;
use backend::Backend;
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.
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
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.
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.
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-03 22:59:04 +00:00
/// Helper method that can be chained with a widget's builder methods to render it.
fn render<B>(&mut self, t: &mut Terminal<B>, area: &Rect)
where Self: Sized,
B: Backend
{
t.render(self, area);
2016-10-11 17:54:35 +00:00
}
2016-10-09 17:46:53 +00:00
}