forked from ratatui/ratatui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(block): support for having more than one title (ratatui#232)
- Loading branch information
Showing
7 changed files
with
510 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use crate::{layout::Alignment, text::Line}; | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub struct Title<'a> { | ||
pub content: Line<'a>, | ||
/// Defaults to Left if unset | ||
pub alignment: Option<Alignment>, | ||
|
||
/// Defaults to Top if unset | ||
pub position: Option<Position>, | ||
} | ||
|
||
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub enum Position { | ||
#[default] | ||
Top, | ||
Bottom, | ||
} | ||
|
||
impl<'a> Title<'a> { | ||
pub fn content<T>(mut self, content: T) -> Title<'a> | ||
where | ||
T: Into<Line<'a>>, | ||
{ | ||
self.content = content.into(); | ||
self | ||
} | ||
|
||
pub fn alignment(mut self, alignment: Alignment) -> Title<'a> { | ||
self.alignment = Some(alignment); | ||
self | ||
} | ||
|
||
pub fn position(mut self, position: Position) -> Title<'a> { | ||
self.position = Some(position); | ||
self | ||
} | ||
} | ||
|
||
impl<'a, T> From<T> for Title<'a> | ||
where | ||
T: Into<Line<'a>>, | ||
{ | ||
fn from(value: T) -> Self { | ||
Self::default().content(value.into()) | ||
} | ||
} | ||
|
||
impl<'a> Default for Title<'a> { | ||
fn default() -> Self { | ||
Self { | ||
content: Line::from(""), | ||
alignment: Some(Alignment::Left), | ||
position: Some(Position::Top), | ||
} | ||
} | ||
} |
Oops, something went wrong.