use log::warn;
use kas::draw::{Colour, InputState, TextClass};
#[derive(Clone, Debug)]
pub struct ThemeColours {
pub background: Colour,
pub frame: Colour,
pub bg: Colour,
pub bg_disabled: Colour,
pub bg_error: Colour,
pub text: Colour,
pub text_sel: Colour,
pub text_sel_bg: Colour,
pub label_text: Colour,
pub button_text: Colour,
pub nav_focus: Colour,
pub button: Colour,
pub button_disabled: Colour,
pub button_highlighted: Colour,
pub button_depressed: Colour,
pub checkbox: Colour,
}
impl ThemeColours {
pub fn open(scheme: &str) -> Option<Self> {
Some(match scheme {
"default" | "white" => Self::new(),
"grey" => Self::grey(),
"light" => Self::light(),
"dark" => Self::dark(),
other => {
warn!("ThemeColours::open: scheme \"{}\" not found", other);
return None;
}
})
}
pub fn new() -> Self {
ThemeColours {
background: Colour::grey(1.0),
frame: Colour::grey(0.7),
bg: Colour::grey(1.0),
bg_disabled: Colour::grey(0.85),
bg_error: Colour::new(1.0, 0.5, 0.5),
text: Colour::grey(0.0),
text_sel: Colour::grey(1.0),
text_sel_bg: Colour::new(0.15, 0.525, 0.75),
label_text: Colour::grey(0.0),
button_text: Colour::grey(1.0),
nav_focus: Colour::new(1.0, 0.7, 0.5),
button: Colour::new(0.2, 0.7, 1.0),
button_disabled: Colour::grey(0.5),
button_highlighted: Colour::new(0.25, 0.8, 1.0),
button_depressed: Colour::new(0.15, 0.525, 0.75),
checkbox: Colour::new(0.2, 0.7, 1.0),
}
}
pub fn grey() -> Self {
let mut col = ThemeColours::new();
col.background = Colour::grey(0.8);
col
}
pub fn light() -> Self {
ThemeColours {
background: Colour::grey(0.9),
frame: Colour::new(0.8, 0.8, 0.9),
bg: Colour::grey(1.0),
bg_disabled: Colour::grey(0.85),
bg_error: Colour::new(1.0, 0.5, 0.5),
text: Colour::grey(0.0),
text_sel: Colour::grey(0.0),
text_sel_bg: Colour::new(0.8, 0.72, 0.24),
label_text: Colour::grey(0.0),
button_text: Colour::grey(0.0),
nav_focus: Colour::new(1.0, 0.7, 0.5),
button: Colour::new(1.0, 0.9, 0.3),
button_disabled: Colour::grey(0.6),
button_highlighted: Colour::new(1.0, 0.95, 0.6),
button_depressed: Colour::new(0.8, 0.72, 0.24),
checkbox: Colour::grey(0.4),
}
}
pub fn dark() -> Self {
ThemeColours {
background: Colour::grey(0.2),
frame: Colour::grey(0.4),
bg: Colour::grey(0.1),
bg_disabled: Colour::grey(0.3),
bg_error: Colour::new(1.0, 0.5, 0.5),
text: Colour::grey(1.0),
text_sel: Colour::grey(1.0),
text_sel_bg: Colour::new(0.6, 0.3, 0.1),
label_text: Colour::grey(1.0),
button_text: Colour::grey(1.0),
nav_focus: Colour::new(1.0, 0.7, 0.5),
button: Colour::new(0.5, 0.1, 0.1),
button_disabled: Colour::grey(0.7),
button_highlighted: Colour::new(0.6, 0.3, 0.1),
button_depressed: Colour::new(0.3, 0.1, 0.1),
checkbox: Colour::new(0.5, 0.1, 0.1),
}
}
pub fn bg_col(&self, state: InputState) -> Colour {
if state.disabled {
self.bg_disabled
} else if state.error {
self.bg_error
} else {
self.bg
}
}
pub fn nav_region(&self, state: InputState) -> Option<Colour> {
if state.nav_focus && !state.disabled {
Some(self.nav_focus)
} else {
None
}
}
pub fn button_state(&self, state: InputState) -> Colour {
if state.disabled {
self.button_disabled
} else if state.depress {
self.button_depressed
} else if state.hover {
self.button_highlighted
} else {
self.button
}
}
pub fn check_mark_state(&self, state: InputState, checked: bool) -> Option<Colour> {
Some(if checked {
if state.disabled {
self.button_disabled
} else if state.depress {
self.button_depressed
} else if state.hover {
self.button_highlighted
} else {
self.checkbox
}
} else if state.depress {
self.button_depressed
} else {
return None;
})
}
pub fn menu_entry(&self, state: InputState) -> Option<Colour> {
if state.depress || state.nav_focus {
Some(self.button_depressed)
} else if state.hover {
Some(self.button_highlighted)
} else {
None
}
}
#[inline]
pub fn scrollbar_state(&self, state: InputState) -> Colour {
self.button_state(state)
}
pub fn text_class(&self, class: TextClass) -> Colour {
match class {
TextClass::Label | TextClass::LabelSingle => self.label_text,
TextClass::Button => self.button_text,
TextClass::Edit | TextClass::EditMulti => self.text,
}
}
}