ghost-eye/src/palette.rs

115 lines
3.2 KiB
Rust
Raw Normal View History

use ratatui::style::{Style, Color};
use ratatui::widgets::block::BorderType;
#[derive(Debug, Clone)]
pub struct StylePalette {
normal_style: Option<Style>,
hover_style: Option<Style>,
normal_border_style: Option<Style>,
hover_border_style: Option<Style>,
normal_title_style: Option<Style>,
hover_title_style: Option<Style>,
highlight_style: Option<Style>,
scrollbar_style: Option<Style>,
normal_border_type: BorderType,
hover_border_type: BorderType,
}
impl Default for StylePalette {
fn default() -> Self {
Self::new()
}
}
impl StylePalette {
pub fn new() -> Self {
Self {
normal_style: None,
hover_style: None,
normal_border_style: None,
hover_border_style: None,
normal_title_style: None,
hover_title_style: None,
highlight_style: None,
scrollbar_style: None,
normal_border_type: BorderType::Plain,
hover_border_type: BorderType::Double,
}
}
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_highlight_style(&mut self, highlight_style: Option<Style>) {
self.highlight_style = highlight_style;
}
pub fn with_scrollbar_style(&mut self, scrollbar_style: Option<Style>) {
self.scrollbar_style = scrollbar_style;
}
pub fn create_scrollbar_style(&mut self) -> Style {
self.scrollbar_style.unwrap_or_default()
}
pub fn create_highlight_style(&self) -> Style {
self.highlight_style.unwrap_or_default()
}
pub fn create_basic_style(&mut self, active: bool) -> Style {
if active {
self.hover_style.unwrap_or_default()
} else {
self.normal_style.unwrap_or_default()
}
}
pub fn create_border_style(&self, active: bool) -> (Color, BorderType) {
if active {
(
self.hover_border_style.map(|style| style.fg).flatten().unwrap_or_default(),
self.hover_border_type,
)
} else {
(
self.normal_border_style.map(|style| style.fg).flatten().unwrap_or_default(),
self.normal_border_type,
)
}
}
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()
}
}
}