pub mod base {
use druid::{Color, Key};
pub const LOW: Key<Color> = Key::new("net.stevexmh.scl.fluent.color.light.base.low");
pub const MEDIUM_LOW: Key<Color> =
Key::new("net.stevexmh.scl.fluent.color.light.base.medium-low");
pub const MEDIUM: Key<Color> = Key::new("net.stevexmh.scl.fluent.color.light.base.medium");
pub const MEDIUM_HIGH: Key<Color> =
Key::new("net.stevexmh.scl.fluent.color.light.base.medium-high");
pub const HIGH: Key<Color> = Key::new("net.stevexmh.scl.fluent.color.light.base.high");
}
pub mod alt {
use druid::{Color, Key};
pub const LOW: Key<Color> = Key::new("net.stevexmh.scl.fluent.color.light.alt.low");
pub const MEDIUM_LOW: Key<Color> =
Key::new("net.stevexmh.scl.fluent.color.light.alt.medium-low");
pub const MEDIUM: Key<Color> = Key::new("net.stevexmh.scl.fluent.color.light.alt.medium");
pub const MEDIUM_HIGH: Key<Color> =
Key::new("net.stevexmh.scl.fluent.color.light.alt.medium-high");
pub const HIGH: Key<Color> = Key::new("net.stevexmh.scl.fluent.color.light.alt.high");
}
pub mod chrome {
use druid::{Color, Key};
pub const WHITE_HIGH: Key<Color> = Key::new("net.stevexmh.scl.fluent.color.chrome.white-high");
pub const MEDIUM_LOW: Key<Color> = Key::new("net.stevexmh.scl.fluent.color.chrome.medium-low");
pub const LOW: Key<Color> = Key::new("net.stevexmh.scl.fluent.color.chrome.low");
pub const DISABLED_HIGH: Key<Color> =
Key::new("net.stevexmh.scl.fluent.color.chrome.disabled-high");
pub const MEDIUM: Key<Color> = Key::new("net.stevexmh.scl.fluent.color.chrome.medium");
pub const HIGH: Key<Color> = Key::new("net.stevexmh.scl.fluent.color.chrome.high");
pub const BLACK_LOW: Key<Color> = Key::new("net.stevexmh.scl.fluent.color.chrome.black-low");
pub const BLACK_MEDIUM_LOW: Key<Color> =
Key::new("net.stevexmh.scl.fluent.color.chrome.black-medium-low");
pub const DISABLED_LOW: Key<Color> =
Key::new("net.stevexmh.scl.fluent.color.chrome.disabled-low");
pub const BLACK_MEDIUM: Key<Color> =
Key::new("net.stevexmh.scl.fluent.color.chrome.black-medium");
pub const ALT_LOW: Key<Color> = Key::new("net.stevexmh.scl.fluent.color.chrome.alt-low");
pub const BLACK_HIGH: Key<Color> = Key::new("net.stevexmh.scl.fluent.color.chrome.black-high");
pub const WHITE: Key<Color> = Key::new("net.stevexmh.scl.fluent.color.chrome.white");
}
pub mod list {
use druid::{Color, Key};
pub const ACCENT_HIGH: Key<Color> =
Key::new("net.stevexmh.scl.fluent.color.chrome.accent-high");
pub const ACCENT_MEDIUM: Key<Color> =
Key::new("net.stevexmh.scl.fluent.color.chrome.accent-medium");
pub const ACCENT_LOW: Key<Color> = Key::new("net.stevexmh.scl.fluent.color.chrome.accent-low");
pub const LIST_LOW: Key<Color> = Key::new("net.stevexmh.scl.fluent.color.chrome.list-low");
pub const LIST_MEDIUM: Key<Color> =
Key::new("net.stevexmh.scl.fluent.color.chrome.list-medium");
}
pub mod border {
use druid::{Color, Key};
pub const EDGE_HIGHTLIGHT: Key<Color> =
Key::new("net.stevexmh.scl.fluent.color.chrome.edge-hightlight");
pub const TRANSIENT: Key<Color> = Key::new("net.stevexmh.scl.fluent.color.chrome.transient");
}
pub mod accent {
use druid::{Color, Key};
pub const ACCENT: Key<Color> = Key::new("net.stevexmh.scl.fluent.color.chrome.accent");
pub const ACCENT_1: Key<Color> = Key::new("net.stevexmh.scl.fluent.color.chrome.accent-1");
pub const ACCENT_DARK_1: Key<Color> =
Key::new("net.stevexmh.scl.fluent.color.chrome.accent-dark-1");
pub const ACCENT_LIGHT_1: Key<Color> =
Key::new("net.stevexmh.scl.fluent.color.chrome.accent-light-1");
}
pub mod typography {
use druid::{Color, FontDescriptor, Key};
pub const FONT_COLOR: Key<Color> =
Key::new("net.stevexmh.scl.fluent.color.typography.font-color");
pub const SUBHEADER: Key<FontDescriptor> =
Key::new("net.stevexmh.scl.fluent.color.typography.subheader");
pub const HEADER: Key<FontDescriptor> =
Key::new("net.stevexmh.scl.fluent.color.typography.header");
pub const TITLE: Key<FontDescriptor> =
Key::new("net.stevexmh.scl.fluent.color.typography.title");
pub const CAPTION: Key<FontDescriptor> =
Key::new("net.stevexmh.scl.fluent.color.typography.caption");
pub const CAPTION_ALT: Key<FontDescriptor> =
Key::new("net.stevexmh.scl.fluent.color.typography.caption-alt");
pub const BODY: Key<FontDescriptor> = Key::new("net.stevexmh.scl.fluent.color.typography.body");
pub const SUBTITLE_ALT: Key<FontDescriptor> =
Key::new("net.stevexmh.scl.fluent.color.typography.subtitle-alt");
pub const SUBTITLE: Key<FontDescriptor> =
Key::new("net.stevexmh.scl.fluent.color.typography.subtitle");
pub const BASE: Key<FontDescriptor> = Key::new("net.stevexmh.scl.fluent.color.typography.base");
pub const BASE_ALT: Key<FontDescriptor> =
Key::new("net.stevexmh.scl.fluent.color.typography.base-alt");
}
pub mod main {
use druid::{Color, Key};
pub const PRIMARY: Key<Color> = Key::new("net.stevexmh.scl.primary");
pub const SECONDARY: Key<Color> = Key::new("net.stevexmh.scl.secondary");
pub const TITLE_BAR: Key<Color> = Key::new("net.stevexmh.scl.titlebar");
pub const IS_DARK: Key<bool> = Key::new("net.stevexmh.scl.is-dark");
}
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
pub enum Theme {
Light,
Dark,
}
impl Default for Theme {
fn default() -> Self {
Self::Light
}
}
use druid::{Color, Env, FontDescriptor, FontFamily, FontStyle, FontWeight};
#[cfg(target_os = "windows")]
fn get_font() -> FontFamily {
use druid::piet::{D2DText, DwriteFactory, Text};
let dwrite = DwriteFactory::new().unwrap();
let mut text = D2DText::new_with_shared_fonts(dwrite, None);
text.font_family("微软雅黑")
.or_else(|| text.font_family("Segoe WPC"))
.or_else(|| text.font_family("Segoe UI"))
.or_else(|| text.font_family("Garamond"))
.unwrap_or(FontFamily::SYSTEM_UI)
}
#[cfg(not(target_os = "windows"))]
fn get_font() -> FontFamily {
FontFamily::SYSTEM_UI
}
fn set_light_theme(env: &mut Env, _theme: Theme, font: FontFamily) {
env.set(base::LOW, Color::BLACK.with_alpha(0.2));
env.set(base::MEDIUM_LOW, Color::BLACK.with_alpha(0.4));
env.set(base::MEDIUM, Color::BLACK.with_alpha(0.6));
env.set(base::MEDIUM_HIGH, Color::BLACK.with_alpha(0.8));
env.set(base::HIGH, Color::BLACK);
env.set(alt::LOW, Color::WHITE.with_alpha(0.2));
env.set(alt::MEDIUM_LOW, Color::WHITE.with_alpha(0.4));
env.set(alt::MEDIUM, Color::WHITE.with_alpha(0.6));
env.set(alt::MEDIUM_HIGH, Color::WHITE.with_alpha(0.8));
env.set(alt::HIGH, Color::WHITE);
env.set(chrome::WHITE_HIGH, Color::Rgba32(0xFFFFFFFF));
env.set(chrome::MEDIUM_LOW, Color::Rgba32(0xF2F2F2FF));
env.set(chrome::LOW, Color::Rgba32(0xF2F2F2FF));
env.set(chrome::DISABLED_HIGH, Color::Rgba32(0xCCCCCCFF));
env.set(chrome::MEDIUM, Color::Rgba32(0xE6E6E6FF));
env.set(chrome::HIGH, Color::Rgba32(0xCCCCCCFF));
env.set(chrome::BLACK_LOW, Color::BLACK.with_alpha(0.2));
env.set(chrome::BLACK_MEDIUM_LOW, Color::BLACK.with_alpha(0.4));
env.set(chrome::DISABLED_LOW, Color::Rgba32(0x7A7A7AFF));
env.set(chrome::BLACK_MEDIUM, Color::BLACK.with_alpha(0.8));
env.set(chrome::ALT_LOW, Color::BLACK.with_alpha(0.4));
env.set(chrome::BLACK_HIGH, Color::BLACK);
env.set(chrome::WHITE, Color::WHITE);
env.set(list::ACCENT_HIGH, Color::Rgba32(0x0078D4FF).with_alpha(0.2));
env.set(
list::ACCENT_MEDIUM,
Color::Rgba32(0x0078D4FF).with_alpha(0.4),
);
env.set(list::ACCENT_LOW, Color::Rgba32(0x0078D4FF).with_alpha(0.6));
env.set(list::LIST_LOW, Color::BLACK.with_alpha(0.1));
env.set(list::LIST_MEDIUM, Color::BLACK.with_alpha(0.2));
env.set(border::EDGE_HIGHTLIGHT, Color::WHITE.with_alpha(0.6));
env.set(border::TRANSIENT, Color::BLACK.with_alpha(0.14));
env.set(accent::ACCENT, Color::Rgba32(0x0078D4FF));
env.set(accent::ACCENT_1, Color::Rgba32(0x429CE3FF));
env.set(accent::ACCENT_DARK_1, Color::Rgba32(0x005A9EFF));
env.set(accent::ACCENT_LIGHT_1, Color::Rgba32(0xFF7233FF));
env.set(main::PRIMARY, Color::Rgba32(0xF74C00FF));
env.set(main::SECONDARY, Color::Rgba32(0xCC3F00FF));
env.set(main::TITLE_BAR, Color::Rgba32(0xFFFFFF00));
env.set(typography::FONT_COLOR, Color::Rgba32(0x201F1EFF));
env.set(
typography::SUBHEADER,
FontDescriptor::new(font.to_owned())
.with_size(34.)
.with_weight(FontWeight::EXTRA_LIGHT),
);
env.set(
typography::HEADER,
FontDescriptor::new(font.to_owned())
.with_size(46.)
.with_weight(FontWeight::EXTRA_LIGHT),
);
env.set(
typography::TITLE,
FontDescriptor::new(font.to_owned())
.with_size(24.)
.with_weight(FontWeight::EXTRA_LIGHT),
);
env.set(
typography::CAPTION,
FontDescriptor::new(font.to_owned())
.with_size(12.)
.with_weight(FontWeight::LIGHT),
);
env.set(
typography::CAPTION_ALT,
FontDescriptor::new(font.to_owned())
.with_size(13.)
.with_weight(FontWeight::LIGHT),
);
env.set(
typography::BODY,
FontDescriptor::new(font.to_owned())
.with_size(14.)
.with_weight(FontWeight::REGULAR),
);
env.set(
typography::SUBTITLE_ALT,
FontDescriptor::new(font.to_owned())
.with_size(18.)
.with_weight(FontWeight::REGULAR),
);
env.set(
typography::SUBTITLE,
FontDescriptor::new(font.to_owned())
.with_size(20.)
.with_weight(FontWeight::REGULAR),
);
env.set(
typography::BASE,
FontDescriptor::new(font.to_owned())
.with_size(14.)
.with_weight(FontWeight::REGULAR),
);
env.set(
typography::BASE_ALT,
FontDescriptor::new(font.to_owned())
.with_size(14.)
.with_weight(FontWeight::SEMI_BOLD),
);
env.set(
druid::theme::UI_FONT,
FontDescriptor::new(font.to_owned())
.with_size(15.)
.with_weight(FontWeight::REGULAR),
);
env.set(
druid::theme::UI_FONT_BOLD,
FontDescriptor::new(font.to_owned())
.with_size(15.)
.with_weight(FontWeight::BOLD),
);
env.set(
druid::theme::UI_FONT_ITALIC,
FontDescriptor::new(font)
.with_size(15.)
.with_style(FontStyle::Italic)
.with_weight(FontWeight::REGULAR),
);
env.set(
druid::theme::WINDOW_BACKGROUND_COLOR,
Color::Rgba32(0xF3F3F3FF),
);
}
fn set_dark_theme(env: &mut Env, _theme: Theme, font: FontFamily) {
env.set(base::LOW, Color::WHITE.with_alpha(0.2));
env.set(base::MEDIUM_LOW, Color::WHITE.with_alpha(0.4));
env.set(base::MEDIUM, Color::WHITE.with_alpha(0.6));
env.set(base::MEDIUM_HIGH, Color::WHITE.with_alpha(0.8));
env.set(base::HIGH, Color::WHITE);
env.set(alt::LOW, Color::BLACK.with_alpha(0.2));
env.set(alt::MEDIUM_LOW, Color::BLACK.with_alpha(0.4));
env.set(alt::MEDIUM, Color::BLACK.with_alpha(0.6));
env.set(alt::MEDIUM_HIGH, Color::BLACK.with_alpha(0.8));
env.set(alt::HIGH, Color::BLACK);
env.set(chrome::LOW, Color::Rgba32(0x171717FF));
env.set(chrome::MEDIUM_LOW, Color::Rgba32(0x2B2B2BFF));
env.set(chrome::MEDIUM, Color::Rgba32(0x1F1F1FFF));
env.set(chrome::HIGH, Color::Rgba32(0x767676FF));
env.set(chrome::ALT_LOW, Color::Rgba32(0xF2F2F2FF));
env.set(chrome::DISABLED_LOW, Color::Rgba32(0x858585FF));
env.set(chrome::DISABLED_HIGH, Color::Rgba32(0x333333FF));
env.set(chrome::BLACK_LOW, Color::BLACK.with_alpha(0.2));
env.set(chrome::WHITE_HIGH, Color::Rgba32(0xFFFFFFFF));
env.set(chrome::BLACK_MEDIUM_LOW, Color::BLACK.with_alpha(0.4));
env.set(chrome::BLACK_MEDIUM, Color::BLACK.with_alpha(0.8));
env.set(chrome::BLACK_HIGH, Color::BLACK);
env.set(chrome::WHITE, Color::WHITE);
env.set(list::ACCENT_HIGH, Color::Rgba32(0x0078D4FF).with_alpha(0.2));
env.set(
list::ACCENT_MEDIUM,
Color::Rgba32(0x0078D4FF).with_alpha(0.4),
);
env.set(list::ACCENT_LOW, Color::Rgba32(0x0078D4FF).with_alpha(0.6));
env.set(list::LIST_LOW, Color::BLACK.with_alpha(0.1));
env.set(list::LIST_MEDIUM, Color::BLACK.with_alpha(0.2));
env.set(border::EDGE_HIGHTLIGHT, Color::WHITE.with_alpha(0.6));
env.set(border::TRANSIENT, Color::BLACK.with_alpha(0.14));
env.set(accent::ACCENT, Color::Rgba32(0x0078D4FF));
env.set(accent::ACCENT_1, Color::Rgba32(0x429CE3FF));
env.set(accent::ACCENT_DARK_1, Color::Rgba32(0x005A9EFF));
env.set(accent::ACCENT_LIGHT_1, Color::Rgba32(0xFF7233FF));
env.set(main::PRIMARY, Color::Rgba32(0xF74C00FF));
env.set(main::SECONDARY, Color::Rgba32(0xCC3F00FF));
env.set(main::TITLE_BAR, Color::Rgba32(0x00000000));
env.set(typography::FONT_COLOR, Color::Rgba32(0xFFFFFFFF));
env.set(
typography::SUBHEADER,
FontDescriptor::new(font.to_owned())
.with_size(34.)
.with_weight(FontWeight::EXTRA_LIGHT),
);
env.set(
typography::HEADER,
FontDescriptor::new(font.to_owned())
.with_size(46.)
.with_weight(FontWeight::EXTRA_LIGHT),
);
env.set(
typography::TITLE,
FontDescriptor::new(font.to_owned())
.with_size(24.)
.with_weight(FontWeight::EXTRA_LIGHT),
);
env.set(
typography::CAPTION,
FontDescriptor::new(font.to_owned())
.with_size(12.)
.with_weight(FontWeight::LIGHT),
);
env.set(
typography::CAPTION_ALT,
FontDescriptor::new(font.to_owned())
.with_size(13.)
.with_weight(FontWeight::LIGHT),
);
env.set(
typography::BODY,
FontDescriptor::new(font.to_owned())
.with_size(14.)
.with_weight(FontWeight::REGULAR),
);
env.set(
typography::SUBTITLE_ALT,
FontDescriptor::new(font.to_owned())
.with_size(18.)
.with_weight(FontWeight::REGULAR),
);
env.set(
typography::SUBTITLE,
FontDescriptor::new(font.to_owned())
.with_size(20.)
.with_weight(FontWeight::REGULAR),
);
env.set(
typography::BASE,
FontDescriptor::new(font.to_owned())
.with_size(14.)
.with_weight(FontWeight::REGULAR),
);
env.set(
typography::BASE_ALT,
FontDescriptor::new(font.to_owned())
.with_size(14.)
.with_weight(FontWeight::SEMI_BOLD),
);
env.set(
druid::theme::UI_FONT,
FontDescriptor::new(font.to_owned())
.with_size(15.)
.with_weight(FontWeight::REGULAR),
);
env.set(
druid::theme::UI_FONT_BOLD,
FontDescriptor::new(font.to_owned())
.with_size(15.)
.with_weight(FontWeight::BOLD),
);
env.set(
druid::theme::UI_FONT_ITALIC,
FontDescriptor::new(font)
.with_size(15.)
.with_style(FontStyle::Italic)
.with_weight(FontWeight::REGULAR),
);
env.set(
druid::theme::WINDOW_BACKGROUND_COLOR,
Color::Rgba32(0x202020FF),
);
}
pub fn set_color_to_env(env: &mut Env, theme: Theme) {
let font = get_font();
env.set(main::IS_DARK, theme == Theme::Dark);
match theme {
Theme::Light => set_light_theme(env, theme, font),
Theme::Dark => set_dark_theme(env, theme, font),
}
}