Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-tui/src/widgets/block.rs')
| -rw-r--r-- | helix-tui/src/widgets/block.rs | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/helix-tui/src/widgets/block.rs b/helix-tui/src/widgets/block.rs index a6fdde4c..8b8141ea 100644 --- a/helix-tui/src/widgets/block.rs +++ b/helix-tui/src/widgets/block.rs @@ -1,7 +1,7 @@ use crate::{ buffer::Buffer, symbols::line, - text::{Span, Spans}, + text::Spans, widgets::{Borders, Widget}, }; use helix_view::graphics::{Rect, Style}; @@ -58,6 +58,22 @@ pub struct Block<'a> { } impl<'a> Block<'a> { + pub const fn new() -> Self { + Self { + title: None, + borders: Borders::empty(), + border_style: Style::new(), + border_type: BorderType::Plain, + style: Style::new(), + } + } + + pub const fn bordered() -> Self { + let mut block = Self::new(); + block.borders = Borders::ALL; + block + } + pub fn title<T>(mut self, title: T) -> Block<'a> where T: Into<Spans<'a>>, @@ -66,34 +82,22 @@ impl<'a> Block<'a> { self } - #[deprecated( - since = "0.10.0", - note = "You should use styling capabilities of `text::Spans` given as argument of the `title` method to apply styling to the title." - )] - pub fn title_style(mut self, style: Style) -> Block<'a> { - if let Some(t) = self.title { - let title = String::from(&t); - self.title = Some(Spans::from(Span::styled(title, style))); - } - self - } - - pub fn border_style(mut self, style: Style) -> Block<'a> { + pub const fn border_style(mut self, style: Style) -> Block<'a> { self.border_style = style; self } - pub fn style(mut self, style: Style) -> Block<'a> { + pub const fn style(mut self, style: Style) -> Block<'a> { self.style = style; self } - pub fn borders(mut self, flag: Borders) -> Block<'a> { + pub const fn borders(mut self, flag: Borders) -> Block<'a> { self.borders = flag; self } - pub fn border_type(mut self, border_type: BorderType) -> Block<'a> { + pub const fn border_type(mut self, border_type: BorderType) -> Block<'a> { self.border_type = border_type; self } @@ -413,9 +417,7 @@ mod tests { // All borders assert_eq!( - Block::default() - .borders(Borders::ALL) - .inner(Rect::default()), + Block::bordered().inner(Rect::default()), Rect { x: 0, y: 0, @@ -425,7 +427,7 @@ mod tests { "all borders, width=0, height=0" ); assert_eq!( - Block::default().borders(Borders::ALL).inner(Rect { + Block::bordered().inner(Rect { x: 0, y: 0, width: 1, @@ -440,7 +442,7 @@ mod tests { "all borders, width=1, height=1" ); assert_eq!( - Block::default().borders(Borders::ALL).inner(Rect { + Block::bordered().inner(Rect { x: 0, y: 0, width: 2, @@ -455,7 +457,7 @@ mod tests { "all borders, width=2, height=2" ); assert_eq!( - Block::default().borders(Borders::ALL).inner(Rect { + Block::bordered().inner(Rect { x: 0, y: 0, width: 3, |