Skip to main content

altui_core/widgets/
mod.rs

1//! `widgets` is a collection of types that implement [`Widget`].
2//!
3//! All widgets are implemented using the builder pattern and are consumable objects. They are not
4//! meant to be stored but used as *commands* to draw common figures in the UI.
5//!
6//! The available widgets are:
7//! - [`Block`]
8//! - [`Tabs`]
9//! - [`List`]
10//! - [`Table`]
11//! - [`Paragraph`]
12//! - [`Chart`]
13//! - [`BarChart`]
14//! - [`Gauge`]
15//! - [`Sparkline`]
16//! - [`Clear`]
17
18mod barchart;
19mod block;
20pub mod canvas;
21mod chart;
22mod clear;
23mod gauge;
24mod list;
25mod paragraph;
26mod reflow;
27mod scrollbar;
28mod sparkline;
29mod table;
30mod tabs;
31
32pub use self::barchart::BarChart;
33pub use self::block::{Block, BorderType};
34pub use self::chart::{Axis, Chart, Dataset, GraphType};
35pub use self::clear::Clear;
36pub use self::gauge::{Gauge, LineGauge};
37pub use self::list::{List, ListItem};
38pub use self::paragraph::{Paragraph, Wrap};
39pub use self::scrollbar::{
40    ScrollDirection, Scrollbar, ScrollbarOrientation, DOUBLE_HORIZONTAL, DOUBLE_VERTICAL,
41    HORIZONTAL, VERTICAL,
42};
43pub use self::sparkline::Sparkline;
44pub use self::table::{Cell, Row, Table};
45pub use self::tabs::Tabs;
46
47use crate::{buffer::Buffer, layout::Rect};
48use bitflags::bitflags;
49
50bitflags! {
51    /// Bitflags that can be composed to set the visible borders essentially on the block widget.
52    #[derive(Debug, Clone, Copy, PartialEq, Eq)]
53    pub struct Borders: u32 {
54        /// Show no border (default)
55        const NONE  = 0b0000_0001;
56        /// Show the top border
57        const TOP   = 0b0000_0010;
58        /// Show the right border
59        const RIGHT = 0b0000_0100;
60        /// Show the bottom border
61        const BOTTOM = 0b000_1000;
62        /// Show the left border
63        const LEFT = 0b0001_0000;
64        /// Show all borders
65        const ALL = Self::TOP.bits() | Self::RIGHT.bits() | Self::BOTTOM.bits() | Self::LEFT.bits();
66    }
67}
68
69/// Base requirements for a Widget
70pub trait Widget {
71    /// Draws the current state of the widget in the given buffer. That is the only method required
72    /// to implement a custom widget.
73    fn render(&mut self, area: Rect, buf: &mut Buffer);
74}