on master help sign in
Refactor Block with Default and bitflags
1837b5eIvan Tham
helix-tui/src/widgets/block.rs+8−13
@@ -6,6 +6,7 @@ use crate::{
6};
6};
7use helix_view::graphics::{Rect, Style};
7use helix_view::graphics::{Rect, Style};
8
8
9+/// Border render type. Defaults to [`BorderType::Plain`].
9#[derive(Debug, Clone, Copy, PartialEq)]
10#[derive(Debug, Clone, Copy, PartialEq)]
10pub enum BorderType {
11pub enum BorderType {
11 Plain,
12 Plain,
@@ -25,6 +26,12 @@ impl BorderType {
25 }
26 }
26}
27}
27
28
29+impl Default for BorderType {
30+ fn default() -> BorderType {
31+ BorderType::Plain
32+ }
33+}
34+
28/// Base widget to be used with all upper level ones. It may be used to display a box border around
35/// Base widget to be used with all upper level ones. It may be used to display a box border around
29/// the widget and/or add a title.
36/// the widget and/or add a title.
30///
37///
@@ -40,7 +47,7 @@ impl BorderType {
40/// .border_type(BorderType::Rounded)
47/// .border_type(BorderType::Rounded)
41/// .style(Style::default().bg(Color::Black));
48/// .style(Style::default().bg(Color::Black));
42/// ```
49/// ```
43−#[derive(Debug, Clone, PartialEq)]
50+#[derive(Debug, Default, Clone, PartialEq)]
44pub struct Block<'a> {
51pub struct Block<'a> {
45 /// Optional title place on the upper left of the block
52 /// Optional title place on the upper left of the block
46 title: Option<Spans<'a>>,
53 title: Option<Spans<'a>>,
@@ -55,18 +62,6 @@ pub struct Block<'a> {
55 style: Style,
62 style: Style,
56}
63}
57
64
58−impl<'a> Default for Block<'a> {
59− fn default() -> Block<'a> {
60− Block {
61− title: None,
62− borders: Borders::NONE,
63− border_style: Default::default(),
64− border_type: BorderType::Plain,
65− style: Default::default(),
66− }
67− }
68−}
69−
70impl<'a> Block<'a> {
65impl<'a> Block<'a> {
71 pub fn title<T>(mut self, title: T) -> Block<'a>
66 pub fn title<T>(mut self, title: T) -> Block<'a>
72 where
67 where
helix-tui/src/widgets/mod.rs+5−6
@@ -27,17 +27,16 @@ use helix_view::graphics::Rect;
27
27
28bitflags! {
28bitflags! {
29 /// Bitflags that can be composed to set the visible borders essentially on the block widget.
29 /// Bitflags that can be composed to set the visible borders essentially on the block widget.
30+ #[derive(Default)]
30 pub struct Borders: u32 {
31 pub struct Borders: u32 {
31− /// Show no border (default)
32− const NONE = 0b0000_0001;
33 /// Show the top border
32 /// Show the top border
34− const TOP = 0b0000_0010;
33+ const TOP = 0b0000_0001;
35 /// Show the right border
34 /// Show the right border
36− const RIGHT = 0b0000_0100;
35+ const RIGHT = 0b0000_0010;
37 /// Show the bottom border
36 /// Show the bottom border
38− const BOTTOM = 0b000_1000;
37+ const BOTTOM = 0b000_0100;
39 /// Show the left border
38 /// Show the left border
40− const LEFT = 0b0001_0000;
39+ const LEFT = 0b0000_1000;
41 /// Show all borders
40 /// Show all borders
42 const ALL = Self::TOP.bits | Self::RIGHT.bits | Self::BOTTOM.bits | Self::LEFT.bits;
41 const ALL = Self::TOP.bits | Self::RIGHT.bits | Self::BOTTOM.bits | Self::LEFT.bits;
43 }
42 }