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.
pull/2530/head
Ivan Tham 3 years ago committed by Blaž Hrastnik
parent bfc4ff4dcf
commit 1837b5e4a6

@ -6,6 +6,7 @@ use crate::{
}; };
use helix_view::graphics::{Rect, Style}; use helix_view::graphics::{Rect, Style};
/// Border render type. Defaults to [`BorderType::Plain`].
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub enum BorderType { pub enum BorderType {
Plain, Plain,
@ -25,6 +26,12 @@ impl BorderType {
} }
} }
impl Default for BorderType {
fn default() -> BorderType {
BorderType::Plain
}
}
/// Base widget to be used with all upper level ones. It may be used to display a box border around /// Base widget to be used with all upper level ones. It may be used to display a box border around
/// the widget and/or add a title. /// the widget and/or add a title.
/// ///
@ -40,7 +47,7 @@ impl BorderType {
/// .border_type(BorderType::Rounded) /// .border_type(BorderType::Rounded)
/// .style(Style::default().bg(Color::Black)); /// .style(Style::default().bg(Color::Black));
/// ``` /// ```
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Default, Clone, PartialEq)]
pub struct Block<'a> { pub struct Block<'a> {
/// Optional title place on the upper left of the block /// Optional title place on the upper left of the block
title: Option<Spans<'a>>, title: Option<Spans<'a>>,
@ -55,18 +62,6 @@ pub struct Block<'a> {
style: Style, style: Style,
} }
impl<'a> Default for Block<'a> {
fn default() -> Block<'a> {
Block {
title: None,
borders: Borders::NONE,
border_style: Default::default(),
border_type: BorderType::Plain,
style: Default::default(),
}
}
}
impl<'a> Block<'a> { impl<'a> Block<'a> {
pub fn title<T>(mut self, title: T) -> Block<'a> pub fn title<T>(mut self, title: T) -> Block<'a>
where where

@ -27,17 +27,16 @@ use helix_view::graphics::Rect;
bitflags! { bitflags! {
/// Bitflags that can be composed to set the visible borders essentially on the block widget. /// Bitflags that can be composed to set the visible borders essentially on the block widget.
#[derive(Default)]
pub struct Borders: u32 { pub struct Borders: u32 {
/// Show no border (default)
const NONE = 0b0000_0001;
/// Show the top border /// Show the top border
const TOP = 0b0000_0010; const TOP = 0b0000_0001;
/// Show the right border /// Show the right border
const RIGHT = 0b0000_0100; const RIGHT = 0b0000_0010;
/// Show the bottom border /// Show the bottom border
const BOTTOM = 0b000_1000; const BOTTOM = 0b000_0100;
/// Show the left border /// Show the left border
const LEFT = 0b0001_0000; const LEFT = 0b0000_1000;
/// Show all borders /// Show all borders
const ALL = Self::TOP.bits | Self::RIGHT.bits | Self::BOTTOM.bits | Self::LEFT.bits; const ALL = Self::TOP.bits | Self::RIGHT.bits | Self::BOTTOM.bits | Self::LEFT.bits;
} }

Loading…
Cancel
Save