use egui::{Color32, Frame, style::Style};
const PANIC_MSG: &str = "Custom theme not supported, use Theme::from_custom() instead";
pub mod editor;
pub mod hsla;
pub mod themes;
pub mod utils;
pub mod window;
pub use editor::ThemeEditor;
use themes::*;
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, PartialEq)]
pub enum ThemeKind {
Dark,
Light,
Custom,
}
impl ThemeKind {
pub fn to_str(&self) -> &str {
match self {
ThemeKind::Dark => "Dark",
ThemeKind::Light => "Light",
ThemeKind::Custom => "Custom",
}
}
pub fn to_vec() -> Vec<Self> {
vec![Self::Dark, Self::Light]
}
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone)]
pub struct Theme {
pub dark_mode: bool,
pub image_tint_recommended: bool,
pub kind: ThemeKind,
pub style: Style,
pub colors: ThemeColors,
pub text_sizes: TextSizes,
pub window_frame: Frame,
pub frame1: Frame,
pub frame2: Frame,
pub frame1_visuals: FrameVisuals,
pub frame2_visuals: FrameVisuals,
}
impl Theme {
pub fn new(kind: ThemeKind) -> Self {
let theme = match kind {
ThemeKind::Dark => dark::theme(),
ThemeKind::Light => light::theme(),
ThemeKind::Custom => panic!("{}", PANIC_MSG),
};
theme
}
pub fn set_window_frame_colors(&mut self) {
match self.kind {
ThemeKind::Dark => self.window_frame = dark::window_frame(&self.colors),
ThemeKind::Light => self.window_frame = light::window_frame(&self.colors),
ThemeKind::Custom => panic!("{}", PANIC_MSG),
}
}
pub fn set_frame1_colors(&mut self) {
match self.kind {
ThemeKind::Dark => self.frame1 = dark::frame1(&self.colors),
ThemeKind::Light => self.frame1 = light::frame1(&self.colors),
ThemeKind::Custom => panic!("{}", PANIC_MSG),
}
}
pub fn set_frame2_colors(&mut self) {
match self.kind {
ThemeKind::Dark => self.frame2 = dark::frame2(&self.colors),
ThemeKind::Light => self.frame2 = light::frame2(&self.colors),
ThemeKind::Custom => panic!("{}", PANIC_MSG),
}
}
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone)]
pub struct ThemeColors {
pub bg: Color32,
pub bg2: Color32,
pub bg3: Color32,
pub bg4: Color32,
pub text: Color32,
pub text_muted: Color32,
pub highlight: Color32,
pub border: Color32,
pub primary: Color32,
pub secondary: Color32,
pub error: Color32,
pub warning: Color32,
pub success: Color32,
pub info: Color32,
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Default, Debug)]
pub struct TextSizes {
pub very_small: f32,
pub small: f32,
pub normal: f32,
pub large: f32,
pub very_large: f32,
pub heading: f32,
}
impl TextSizes {
pub fn new(
very_small: f32,
small: f32,
normal: f32,
large: f32,
very_large: f32,
heading: f32,
) -> Self {
Self {
very_small,
small,
normal,
large,
very_large,
heading,
}
}
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Copy, Debug)]
pub struct FrameVisuals {
pub bg_on_hover: Color32,
pub bg_on_click: Color32,
pub border_on_hover: (f32, Color32),
pub border_on_click: (f32, Color32),
}