2024-11-26 12:53:46 +01:00
|
|
|
use ratatui::style::{Style, Color};
|
2024-11-14 13:46:38 +01:00
|
|
|
use ratatui::widgets::block::BorderType;
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct StylePalette {
|
2024-11-26 12:53:46 +01:00
|
|
|
normal_style: Option<Style>,
|
|
|
|
hover_style: Option<Style>,
|
2024-11-14 13:46:38 +01:00
|
|
|
|
2024-11-26 12:53:46 +01:00
|
|
|
normal_border_style: Option<Style>,
|
|
|
|
hover_border_style: Option<Style>,
|
2024-11-14 13:46:38 +01:00
|
|
|
|
2024-11-26 12:53:46 +01:00
|
|
|
normal_title_style: Option<Style>,
|
|
|
|
hover_title_style: Option<Style>,
|
2024-11-14 13:46:38 +01:00
|
|
|
|
2024-11-26 12:53:46 +01:00
|
|
|
tagged_style: Option<Style>,
|
|
|
|
|
|
|
|
normal_border_type: BorderType,
|
|
|
|
hover_border_type: BorderType,
|
2024-11-14 13:46:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for StylePalette {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::new()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl StylePalette {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
Self {
|
2024-11-26 12:53:46 +01:00
|
|
|
normal_style: None,
|
|
|
|
hover_style: None,
|
|
|
|
normal_border_style: None,
|
|
|
|
hover_border_style: None,
|
|
|
|
normal_title_style: None,
|
|
|
|
hover_title_style: None,
|
|
|
|
tagged_style: None,
|
|
|
|
|
|
|
|
normal_border_type: BorderType::Plain,
|
|
|
|
hover_border_type: BorderType::Double,
|
2024-11-14 13:46:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-26 12:53:46 +01:00
|
|
|
pub fn with_normal_style(&mut self, normal_style: Option<Style>) {
|
|
|
|
self.normal_style = normal_style;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_hover_style(&mut self, hover_style: Option<Style>) {
|
|
|
|
self.hover_style = hover_style;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_normal_border_style(&mut self, normal_border_style: Option<Style>) {
|
|
|
|
self.normal_border_style = normal_border_style;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_hover_border_style(&mut self, hover_border_style: Option<Style>) {
|
|
|
|
self.hover_border_style = hover_border_style;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_normal_title_style(&mut self, normal_title_style: Option<Style>) {
|
|
|
|
self.normal_title_style = normal_title_style;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_hover_title_style(&mut self, hover_title_style: Option<Style>) {
|
|
|
|
self.hover_title_style = hover_title_style;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_tagged_style(&mut self, tagged_style: Option<Style>) {
|
|
|
|
self.tagged_style = tagged_style;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn create_tagged_style(&self) -> Style {
|
|
|
|
self.tagged_style.unwrap_or_default()
|
2024-11-14 13:46:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn create_text_style(&mut self, active: bool) -> Style {
|
2024-11-26 12:53:46 +01:00
|
|
|
if active {
|
|
|
|
self.hover_style.unwrap_or_default()
|
|
|
|
} else {
|
|
|
|
self.normal_style.unwrap_or_default()
|
2024-11-14 13:46:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn create_border_style(&self, active: bool) -> (Color, BorderType) {
|
|
|
|
if active {
|
|
|
|
(
|
2024-11-26 12:53:46 +01:00
|
|
|
self.hover_border_style.map(|style| style.fg).flatten().unwrap_or_default(),
|
|
|
|
self.hover_border_type,
|
2024-11-14 13:46:38 +01:00
|
|
|
)
|
|
|
|
} else {
|
|
|
|
(
|
2024-11-26 12:53:46 +01:00
|
|
|
self.normal_border_style.map(|style| style.fg).flatten().unwrap_or_default(),
|
|
|
|
self.normal_border_type,
|
2024-11-14 13:46:38 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-26 12:53:46 +01:00
|
|
|
pub fn create_title_style(&self, active: bool) -> Style {
|
|
|
|
if active {
|
|
|
|
self.normal_title_style.unwrap_or_default()
|
|
|
|
} else {
|
|
|
|
self.hover_title_style.unwrap_or_default()
|
2024-11-14 13:46:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|