use crate::text::{Appearance, Color, Intensity, Outline, TextStyle};
use crate::widget::BorderStyle;
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum WidgetGroup {
Normal,
Button,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum StyleGroup {
Enabled,
Disabled,
Primary,
Hovered,
Focused,
Interacted,
LightShadow,
DarkShadow,
}
#[derive(Clone, Debug, PartialEq)]
pub struct Theme {
pub background: Color,
pub foreground: Color,
pub primary: Color,
pub focused: Color,
pub interacting: Color,
pub dark_shadow: Color,
pub light_shadow: Color,
pub normal_border: BorderStyle,
pub button_border: BorderStyle,
}
impl Default for Theme {
fn default() -> Self {
let background = Color::Blue(Intensity::Normal);
let foreground = Color::White(Intensity::Bright);
let primary = Color::Yellow(Intensity::Normal);
let focused = Color::Cyan(Intensity::Bright);
let interacting = Color::Yellow(Intensity::Bright);
let dark_shadow = Color::Black(Intensity::Bright);
let light_shadow = Color::White(Intensity::Normal);
let normal_border = BorderStyle::Simple(Outline::default());
let button_border = BorderStyle::Bevel(Outline::default());
Self {
background,
foreground,
primary,
focused,
interacting,
dark_shadow,
light_shadow,
normal_border,
button_border,
}
}
}
impl Theme {
pub fn with_background(mut self, clr: Color) -> Self {
self.background = clr;
self
}
pub fn with_foreground(mut self, clr: Color) -> Self {
self.foreground = clr;
self
}
pub fn with_primary(mut self, clr: Color) -> Self {
self.primary = clr;
self
}
pub fn with_focused(mut self, clr: Color) -> Self {
self.focused = clr;
self
}
pub fn with_interacting(mut self, clr: Color) -> Self {
self.interacting = clr;
self
}
pub fn style(&self, group: StyleGroup) -> TextStyle {
let style = TextStyle::default().with_background(self.background);
match group {
StyleGroup::Disabled => style.with_foreground(self.light_shadow),
StyleGroup::Primary => style.with_foreground(self.primary),
StyleGroup::Hovered => style.with_foreground(self.interacting),
StyleGroup::Focused => style
.with_foreground(self.focused)
.with_appearance(Appearance::default().with_reverse(true)),
StyleGroup::Interacted => style
.with_foreground(self.interacting)
.with_appearance(Appearance::default().with_reverse(true)),
StyleGroup::LightShadow => style.with_foreground(self.light_shadow),
StyleGroup::DarkShadow => style.with_foreground(self.dark_shadow),
_ => style.with_foreground(self.foreground),
}
}
pub fn border_style(&self, group: WidgetGroup) -> BorderStyle {
match group {
WidgetGroup::Normal => self.normal_border,
WidgetGroup::Button => self.button_border,
}
}
}