104 lines
2.8 KiB
Rust
104 lines
2.8 KiB
Rust
|
use ratatui::style::{Style, Color, Modifier};
|
||
|
use ratatui::widgets::block::BorderType;
|
||
|
|
||
|
#[derive(Debug, Clone)]
|
||
|
pub struct StylePalette {
|
||
|
background: Option<Color>,
|
||
|
foreground: Option<Color>,
|
||
|
modifiers: Vec<Modifier>,
|
||
|
|
||
|
background_hover: Option<Color>,
|
||
|
foreground_hover: Option<Color>,
|
||
|
modifiers_hover: Vec<Modifier>,
|
||
|
|
||
|
border_color: Option<Color>,
|
||
|
title_color: Option<Color>,
|
||
|
border_type: BorderType,
|
||
|
|
||
|
border_color_hover: Option<Color>,
|
||
|
//title_color_hover: Option<Color>,
|
||
|
border_type_hover: BorderType,
|
||
|
}
|
||
|
|
||
|
impl Default for StylePalette {
|
||
|
fn default() -> Self {
|
||
|
Self::new()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl StylePalette {
|
||
|
// TODO: make read from the config by default
|
||
|
pub fn new() -> Self {
|
||
|
Self {
|
||
|
background: None,
|
||
|
foreground: None,
|
||
|
modifiers: Vec::new(),
|
||
|
|
||
|
background_hover: Some(Color::Blue),
|
||
|
foreground_hover: Some(Color::Yellow),
|
||
|
modifiers_hover: vec![
|
||
|
Modifier::ITALIC,
|
||
|
Modifier::BOLD,
|
||
|
],
|
||
|
|
||
|
border_color: Some(Color::Blue),
|
||
|
title_color: Some(Color::Blue),
|
||
|
border_type: BorderType::Plain,
|
||
|
|
||
|
border_color_hover: Some(Color::Blue),
|
||
|
//title_color_hover: Some(Color::Blue),
|
||
|
border_type_hover: BorderType::Double,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn foreground_hover(&self) -> Color {
|
||
|
self.foreground_hover.unwrap_or_default()
|
||
|
}
|
||
|
|
||
|
pub fn create_text_style(&mut self, active: bool) -> Style {
|
||
|
if active {
|
||
|
self.create_text_style_hover()
|
||
|
} else {
|
||
|
self.create_text_style_normal()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn create_border_style(&self, active: bool) -> (Color, BorderType) {
|
||
|
if active {
|
||
|
(
|
||
|
self.border_color_hover.unwrap_or_default(),
|
||
|
self.border_type_hover,
|
||
|
)
|
||
|
} else {
|
||
|
(
|
||
|
self.border_color.unwrap_or_default(),
|
||
|
self.border_type,
|
||
|
)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn create_title_style(&mut self) -> Style {
|
||
|
Style::default().fg(self.title_color.unwrap_or_default())
|
||
|
}
|
||
|
|
||
|
fn create_text_style_normal(&self) -> Style {
|
||
|
let mut style = Style::default()
|
||
|
.fg(self.foreground.unwrap_or_default())
|
||
|
.bg(self.background.unwrap_or_default());
|
||
|
for modifier in self.modifiers.iter() {
|
||
|
style = style.add_modifier(*modifier);
|
||
|
}
|
||
|
style
|
||
|
}
|
||
|
|
||
|
fn create_text_style_hover(&self) -> Style {
|
||
|
let mut style = Style::default()
|
||
|
.fg(self.foreground_hover.unwrap_or_default())
|
||
|
.bg(self.background_hover.unwrap_or_default());
|
||
|
for modifier in self.modifiers_hover.iter() {
|
||
|
style = style.add_modifier(*modifier);
|
||
|
}
|
||
|
style
|
||
|
}
|
||
|
}
|