feat(block): add Block::bordered (#736)

This avoid creating a block with no borders and then settings Borders::ALL. i.e.

```diff
- Block::default().borders(Borders::ALL);
+ Block::bordered();
```
This commit is contained in:
Valentin271 2024-01-05 12:19:49 +01:00 committed by GitHub
parent 98bcf1c0a5
commit 23f6938498
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -267,6 +267,13 @@ impl<'a> Block<'a> {
} }
} }
/// Create a new block with [all borders](Borders::ALL) shown
pub const fn bordered() -> Self {
let mut block = Block::new();
block.borders = Borders::ALL;
block
}
/// Adds a title to the block. /// Adds a title to the block.
/// ///
/// The `title` function allows you to add a title to the block. You can call this function /// The `title` function allows you to add a title to the block. You can call this function
@ -820,6 +827,12 @@ mod tests {
style::{Color, Modifier, Stylize}, style::{Color, Modifier, Stylize},
}; };
#[test]
fn create_with_all_borders() {
let block = Block::bordered();
assert_eq!(block.borders, Borders::all());
}
#[test] #[test]
fn inner_takes_into_account_the_borders() { fn inner_takes_into_account_the_borders() {
// No borders // No borders