Debian Codegraph @

helix-tui/src/widgets/mod.rs

raw symbols SCIP
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 // //! - [`List`]
9 // //! - [`Table`]
10 //! - [`Paragraph`]
11
12 mod block;
13 // mod list;
14 mod paragraph;
15 mod reflow;
16 mod table;
17
18 pub use self::block::{Block, BorderType};
19 // pub use self::list::{List, ListItem, ListState};
20 pub use self::paragraph::{Paragraph, Wrap};
21 pub use self::table::{Cell, Row, Table, TableState};
22
23 use crate::buffer::Buffer;
24 use bitflags::bitflags;
25
26 use helix_view::graphics::Rect;
27
28 bitflags! {
29 /// Bitflags that can be composed to set the visible borders essentially on the block widget.
30 #[derive(Debug, PartialEq, Eq, Clone, Copy, Default)]
31 pub struct Borders: u8 {
32 /// Show the top border
33 const TOP = 0b0000_0001;
34 /// Show the right border
35 const RIGHT = 0b0000_0010;
36 /// Show the bottom border
37 const BOTTOM = 0b000_0100;
38 /// Show the left border
39 const LEFT = 0b0000_1000;
40 /// Show all borders
41 const ALL = Self::TOP.bits() | Self::RIGHT.bits() | Self::BOTTOM.bits() | Self::LEFT.bits();
42 }
43 }
44
45 /// Base requirements for a Widget
46 pub trait Widget {
47 /// Draws the current state of the widget in the given buffer. That the only method required to
48 /// implement a custom widget.
49 fn render(self, area: Rect, buf: &mut Buffer);
50 }