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.rs50
1 files changed, 24 insertions, 26 deletions
diff --git a/helix-tui/src/widgets/block.rs b/helix-tui/src/widgets/block.rs
index ee7aa757..a6fdde4c 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::Spans,
+ text::{Span, Spans},
widgets::{Borders, Widget},
};
use helix_view::graphics::{Rect, Style};
@@ -58,22 +58,6 @@ 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>>,
@@ -82,22 +66,34 @@ impl<'a> Block<'a> {
self
}
- pub const fn border_style(mut self, style: Style) -> Block<'a> {
+ #[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> {
self.border_style = style;
self
}
- pub const fn style(mut self, style: Style) -> Block<'a> {
+ pub fn style(mut self, style: Style) -> Block<'a> {
self.style = style;
self
}
- pub const fn borders(mut self, flag: Borders) -> Block<'a> {
+ pub fn borders(mut self, flag: Borders) -> Block<'a> {
self.borders = flag;
self
}
- pub const fn border_type(mut self, border_type: BorderType) -> Block<'a> {
+ pub fn border_type(mut self, border_type: BorderType) -> Block<'a> {
self.border_type = border_type;
self
}
@@ -123,7 +119,7 @@ impl<'a> Block<'a> {
}
}
-impl Widget for Block<'_> {
+impl<'a> Widget for Block<'a> {
fn render(self, area: Rect, buf: &mut Buffer) {
if area.area() == 0 {
return;
@@ -417,7 +413,9 @@ mod tests {
// All borders
assert_eq!(
- Block::bordered().inner(Rect::default()),
+ Block::default()
+ .borders(Borders::ALL)
+ .inner(Rect::default()),
Rect {
x: 0,
y: 0,
@@ -427,7 +425,7 @@ mod tests {
"all borders, width=0, height=0"
);
assert_eq!(
- Block::bordered().inner(Rect {
+ Block::default().borders(Borders::ALL).inner(Rect {
x: 0,
y: 0,
width: 1,
@@ -442,7 +440,7 @@ mod tests {
"all borders, width=1, height=1"
);
assert_eq!(
- Block::bordered().inner(Rect {
+ Block::default().borders(Borders::ALL).inner(Rect {
x: 0,
y: 0,
width: 2,
@@ -457,7 +455,7 @@ mod tests {
"all borders, width=2, height=2"
);
assert_eq!(
- Block::bordered().inner(Rect {
+ Block::default().borders(Borders::ALL).inner(Rect {
x: 0,
y: 0,
width: 3,