92 lines
2.6 KiB
Rust
92 lines
2.6 KiB
Rust
|
pub struct UserPrefs {
|
||
|
theme: ThemePref,
|
||
|
font: FontPref,
|
||
|
}
|
||
|
|
||
|
pub enum ThemePref {
|
||
|
Light,
|
||
|
Dark,
|
||
|
Auto,
|
||
|
}
|
||
|
|
||
|
pub enum FontPref {
|
||
|
NerdFont,
|
||
|
OpenDyslexic,
|
||
|
}
|
||
|
|
||
|
impl UserPrefs {
|
||
|
pub fn new() -> UserPrefs {
|
||
|
UserPrefs {
|
||
|
theme: ThemePref::Auto,
|
||
|
font: FontPref::OpenDyslexic,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn get_theme(&self, is_button: bool) -> String {
|
||
|
match &self.theme {
|
||
|
ThemePref::Light => Self::light_theme_classes(is_button),
|
||
|
ThemePref::Dark => Self::dark_theme_classes(is_button),
|
||
|
ThemePref::Auto => Self::auto_theme_classes(is_button),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn set_theme(mut self, theme: ThemePref) {
|
||
|
self.theme = theme;
|
||
|
}
|
||
|
|
||
|
pub fn get_font(&self) -> String {
|
||
|
match &self.font {
|
||
|
FontPref::OpenDyslexic => "...".to_string(),
|
||
|
FontPref::NerdFont => "...".to_string(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn set_font(mut self, font: FontPref) {
|
||
|
self.font = font;
|
||
|
}
|
||
|
|
||
|
pub fn get_prefs(&self, is_button: bool) -> (String, String) {
|
||
|
let theme = self.get_theme(is_button).clone();
|
||
|
let font = self.get_font().clone();
|
||
|
(theme, font)
|
||
|
}
|
||
|
|
||
|
pub fn set_prefs(mut self, prefs: UserPrefs) {
|
||
|
self.theme = prefs.theme;
|
||
|
self.font = prefs.font;
|
||
|
}
|
||
|
|
||
|
fn light_theme_classes(is_button: bool) -> String {
|
||
|
let base_classes = "bg-alice-werefox-grey-lightest ring-alice-werefox-red-dark text-alice-werefox-grey-dark"
|
||
|
.to_string();
|
||
|
let button_classes = "hover:text-alice-werefox-blue-dark hover:ring-alice-werefox-blue hover:animate-yip transition".to_string();
|
||
|
if is_button {
|
||
|
return format!("{base_classes} {button_classes}");
|
||
|
}
|
||
|
base_classes
|
||
|
}
|
||
|
fn dark_theme_classes(is_button: bool) -> String {
|
||
|
let base_classes =
|
||
|
"bg-alice-werefox-grey-dark ring-alice-werefox-red text-alice-werefox-grey-light"
|
||
|
.to_string();
|
||
|
let button_classes = "hover:text-alice-werefox-blue-light hover:ring-alice-werefox-blue hover:animate-yip transition".to_string();
|
||
|
if is_button {
|
||
|
return format!("{base_classes} {button_classes}");
|
||
|
}
|
||
|
base_classes
|
||
|
}
|
||
|
fn auto_theme_classes(is_button: bool) -> String {
|
||
|
format!(
|
||
|
"{}{}",
|
||
|
Self::light_theme_classes(is_button)
|
||
|
.split(" ")
|
||
|
.map(|c| if c == "transition" { "" } else { c })
|
||
|
.collect::<String>(),
|
||
|
Self::dark_theme_classes(is_button)
|
||
|
.split(" ")
|
||
|
.map(|c| format!(" dark:{c}"))
|
||
|
.collect::<String>()
|
||
|
)
|
||
|
}
|
||
|
}
|