Skip to content

Commit d854ed4

Browse files
committed
refactor(helix-tui): split widgets.rs into submodules
1 parent 786d3fd commit d854ed4

File tree

6 files changed

+87
-73
lines changed

6 files changed

+87
-73
lines changed

helix-tui/src/layout.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ pub use layout::Layout;
1212

1313
mod alignment;
1414
pub use alignment::Alignment;
15+
16+
mod corner;
17+
pub use corner::Corner;

helix-tui/src/widgets.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 borders;
13+
pub use borders::{BorderType, Borders};
14+
15+
mod widget;
16+
pub use widget::Widget;
17+
18+
mod block;
19+
pub use block::Block;
20+
21+
// mod list;
22+
// pub use self::list::{List, ListItem, ListState};
23+
24+
mod paragraph;
25+
pub use paragraph::{Paragraph, Wrap};
26+
27+
mod reflow;
28+
29+
mod table;
30+
pub use table::{Cell, Row, Table, TableState};

helix-tui/src/widgets/block.rs

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,13 @@
11
use crate::{
22
buffer::Buffer,
3-
symbols::line,
43
text::Spans,
5-
widgets::{Borders, Widget},
4+
widgets::{
5+
borders::{BorderType, Borders},
6+
Widget,
7+
},
68
};
79
use helix_view::graphics::{Rect, Style};
810

9-
/// Border render type. Defaults to [`BorderType::Plain`].
10-
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
11-
pub enum BorderType {
12-
#[default]
13-
Plain,
14-
Rounded,
15-
Double,
16-
Thick,
17-
}
18-
19-
impl BorderType {
20-
pub fn line_symbols(border_type: Self) -> line::Set {
21-
match border_type {
22-
Self::Plain => line::NORMAL,
23-
Self::Rounded => line::ROUNDED,
24-
Self::Double => line::DOUBLE,
25-
Self::Thick => line::THICK,
26-
}
27-
}
28-
}
29-
3011
/// Base widget to be used with all upper level ones. It may be used to display a box border around
3112
/// the widget and/or add a title.
3213
///

helix-tui/src/widgets/borders.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use bitflags::bitflags;
2+
3+
use crate::symbols::line;
4+
5+
bitflags! {
6+
/// Bitflags that can be composed to set the visible borders essentially on the block widget.
7+
#[derive(Debug, PartialEq, Eq, Clone, Copy, Default)]
8+
pub struct Borders: u8 {
9+
/// Show the top border
10+
const TOP = 0b0000_0001;
11+
/// Show the right border
12+
const RIGHT = 0b0000_0010;
13+
/// Show the bottom border
14+
const BOTTOM = 0b000_0100;
15+
/// Show the left border
16+
const LEFT = 0b0000_1000;
17+
/// Show all borders
18+
const ALL = Self::TOP.bits() | Self::RIGHT.bits() | Self::BOTTOM.bits() | Self::LEFT.bits();
19+
}
20+
}
21+
22+
/// Border render type. Defaults to [`BorderType::Plain`].
23+
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
24+
pub enum BorderType {
25+
#[default]
26+
Plain,
27+
Rounded,
28+
Double,
29+
Thick,
30+
}
31+
32+
impl BorderType {
33+
pub fn line_symbols(border_type: Self) -> line::Set {
34+
match border_type {
35+
Self::Plain => line::NORMAL,
36+
Self::Rounded => line::ROUNDED,
37+
Self::Double => line::DOUBLE,
38+
Self::Thick => line::THICK,
39+
}
40+
}
41+
}

helix-tui/src/widgets/mod.rs

Lines changed: 0 additions & 50 deletions
This file was deleted.

helix-tui/src/widgets/widget.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use crate::buffer::Buffer;
2+
use helix_view::graphics::Rect;
3+
4+
/// Base requirements for a Widget
5+
pub trait Widget {
6+
/// Draws the current state of the widget in the given buffer. That the only method required to
7+
/// implement a custom widget.
8+
fn render(self, area: Rect, buf: &mut Buffer);
9+
}

0 commit comments

Comments
 (0)