on master help sign in
Refactor Block with Default and bitflags

Specifying empty for bitflags is not recommended, it is now removed and added Default. For BorderType, it now defaults to plain.

commit1837b5e4a61f0230b3cd382ed487fa09be7b2b68 authorIvan Tham <pickfire@riseup.net> dateSat 14 May 2022, 22:28 (4 years ago) parentbfc4ff4
2 files changed+13−19
helix-tui/src/widgets/block.rs+8−13 helix-tui/src/widgets/mod.rs+5−6
helix-tui/src/widgets/block.rs+8−13
@@ -6,6 +6,7 @@ use crate::{
66};
77use helix_view::graphics::{Rect, Style};
88
9+/// Border render type. Defaults to [`BorderType::Plain`].
910#[derive(Debug, Clone, Copy, PartialEq)]
1011pub enum BorderType {
1112 Plain,
@@ -25,6 +26,12 @@ impl BorderType {
2526 }
2627}
2728
29+impl Default for BorderType {
30+ fn default() -> BorderType {
31+ BorderType::Plain
32+ }
33+}
34+
2835/// Base widget to be used with all upper level ones. It may be used to display a box border around
2936/// the widget and/or add a title.
3037///
@@ -40,7 +47,7 @@ impl BorderType {
4047/// .border_type(BorderType::Rounded)
4148/// .style(Style::default().bg(Color::Black));
4249/// ```
43−#[derive(Debug, Clone, PartialEq)]
50+#[derive(Debug, Default, Clone, PartialEq)]
4451pub struct Block<'a> {
4552 /// Optional title place on the upper left of the block
4653 title: Option<Spans<'a>>,
@@ -55,18 +62,6 @@ pub struct Block<'a> {
5562 style: Style,
5663}
5764
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−
7065impl<'a> Block<'a> {
7166 pub fn title<T>(mut self, title: T) -> Block<'a>
7267 where
helix-tui/src/widgets/mod.rs+5−6
@@ -27,17 +27,16 @@ use helix_view::graphics::Rect;
2727
2828bitflags! {
2929 /// Bitflags that can be composed to set the visible borders essentially on the block widget.
30+ #[derive(Default)]
3031 pub struct Borders: u32 {
31− /// Show no border (default)
32− const NONE = 0b0000_0001;
3332 /// Show the top border
34− const TOP = 0b0000_0010;
33+ const TOP = 0b0000_0001;
3534 /// Show the right border
36− const RIGHT = 0b0000_0100;
35+ const RIGHT = 0b0000_0010;
3736 /// Show the bottom border
38− const BOTTOM = 0b000_1000;
37+ const BOTTOM = 0b000_0100;
3938 /// Show the left border
40− const LEFT = 0b0001_0000;
39+ const LEFT = 0b0000_1000;
4140 /// Show all borders
4241 const ALL = Self::TOP.bits | Self::RIGHT.bits | Self::BOTTOM.bits | Self::LEFT.bits;
4342 }