rumatui_tui/widgets/
mod.rs1use bitflags::bitflags;
2use std::borrow::Cow;
3
4mod barchart;
5mod block;
6pub mod canvas;
7mod chart;
8mod gauge;
9mod list;
10mod paragraph;
11mod reflow;
12mod scroll;
13mod sparkline;
14mod table;
15mod tabs;
16
17pub use self::barchart::BarChart;
18pub use self::block::{Block, BorderType};
19pub use self::chart::{Axis, Chart, Dataset, GraphType, Marker};
20pub use self::gauge::Gauge;
21pub use self::list::{List, ListState};
22pub use self::paragraph::Paragraph;
23pub use self::sparkline::Sparkline;
24pub use self::table::{Row, Table, TableState};
25pub use self::tabs::Tabs;
26
27use crate::buffer::Buffer;
28use crate::layout::Rect;
29use crate::style::Style;
30
31bitflags! {
32 pub struct Borders: u32 {
34 const NONE = 0b0000_0001;
36 const TOP = 0b0000_0010;
38 const RIGHT = 0b0000_0100;
40 const BOTTOM = 0b000_1000;
42 const LEFT = 0b0001_0000;
44 const ALL = Self::TOP.bits | Self::RIGHT.bits | Self::BOTTOM.bits | Self::LEFT.bits;
46 }
47}
48
49#[derive(Clone, Debug, PartialEq)]
50pub enum Text<'b> {
51 Raw(Cow<'b, str>),
52 Styled(Cow<'b, str>, Style),
53}
54
55impl<'b> Text<'b> {
56 pub fn raw<D: Into<Cow<'b, str>>>(data: D) -> Text<'b> {
57 Text::Raw(data.into())
58 }
59
60 pub fn styled<D: Into<Cow<'b, str>>>(data: D, style: Style) -> Text<'b> {
61 Text::Styled(data.into(), style)
62 }
63}
64
65pub trait Widget {
67 fn render(self, area: Rect, buf: &mut Buffer);
70}
71
72pub trait StatefulWidget {
73 type State;
74 fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State);
75}