use bitflags::bitflags;
use std::borrow::Cow;
mod block;
mod list;
mod paragraph;
mod reflow;
mod table;
mod tabs;
mod button;
pub use self::{
block::Block,
button::Button,
list::{List, SelectableList},
paragraph::Paragraph,
table::{Row, Table},
tabs::Tabs,
};
use crate::{
backend::Backend,
buffer::Buffer,
layout::Rect,
style::{Color, Style},
terminal::Frame,
};
bitflags! {
pub struct Borders: u32 {
const NONE = 0b0000_0001;
const TOP = 0b0000_0010;
const RIGHT = 0b0000_0100;
const BOTTOM = 0b000_1000;
const LEFT = 0b0001_0000;
const ALL = Self::TOP.bits | Self::RIGHT.bits | Self::BOTTOM.bits | Self::LEFT.bits;
}
}
#[derive(Clone, Debug, PartialEq)]
pub enum Text<'b> {
Raw(Cow<'b, str>),
Styled(Cow<'b, str>, Style),
}
impl<'b> Text<'b> {
pub fn raw<D: Into<Cow<'b, str>>>(data: D) -> Text<'b> {
Text::Raw(data.into())
}
pub fn styled<D: Into<Cow<'b, str>>>(data: D, style: Style) -> Text<'b> {
Text::Styled(data.into(), style)
}
}
pub trait Widget {
fn draw(&mut self, buf: &mut Buffer);
fn background(&self, buf: &mut Buffer, color: Color) {
for y in self.top()..self.bottom() {
for x in self.left()..self.right() {
buf.get_mut(x, y).set_bg(color);
}
}
}
fn render<B>(&mut self, f: &mut Frame<B>)
where
Self: Sized,
B: Backend,
{
f.render(self);
}
fn get_area(&self) -> Rect;
fn top(&self) -> u16 {
self.get_area().top()
}
fn bottom(&self) -> u16 {
self.get_area().bottom()
}
fn left(&self) -> u16 {
self.get_area().left()
}
fn right(&self) -> u16 {
self.get_area().right()
}
}