mirror of https://github.com/terhechte/postsack
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
1.8 KiB
Rust
79 lines
1.8 KiB
Rust
3 years ago
|
use eframe::egui::{self, Color32, Visuals};
|
||
|
use once_cell::sync::OnceCell;
|
||
|
|
||
|
static INSTANCE: OnceCell<PlatformColors> = OnceCell::new();
|
||
|
|
||
3 years ago
|
#[cfg(target_os = "windows")]
|
||
|
mod windows;
|
||
|
|
||
|
#[cfg(target_os = "windows")]
|
||
3 years ago
|
pub use windows::{initial_update, navigation_button};
|
||
3 years ago
|
|
||
|
#[cfg(target_os = "linux")]
|
||
|
mod linux;
|
||
|
|
||
|
#[cfg(target_os = "linux")]
|
||
3 years ago
|
pub use linux::{initial_update, navigation_button};
|
||
3 years ago
|
|
||
|
#[cfg(target_os = "macos")]
|
||
|
mod macos;
|
||
|
|
||
|
#[cfg(target_os = "macos")]
|
||
3 years ago
|
pub use macos::{initial_update, navigation_button};
|
||
3 years ago
|
|
||
|
/// Platform-Native Colors
|
||
|
#[derive(Debug)]
|
||
|
pub struct PlatformColors {
|
||
3 years ago
|
pub is_light: bool,
|
||
|
pub animation_background: Color32,
|
||
3 years ago
|
pub window_background: Color32,
|
||
|
pub content_background: Color32,
|
||
3 years ago
|
pub text_primary: Color32,
|
||
|
pub text_secondary: Color32,
|
||
|
/// Brightest lines to darkest lines
|
||
|
pub line1: Color32,
|
||
|
pub line2: Color32,
|
||
|
pub line3: Color32,
|
||
|
pub line4: Color32,
|
||
3 years ago
|
}
|
||
|
|
||
|
#[allow(unused)]
|
||
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||
|
pub enum Theme {
|
||
|
Light,
|
||
|
Dark,
|
||
|
}
|
||
|
|
||
|
impl Theme {
|
||
3 years ago
|
pub fn visuals(&self) -> Visuals {
|
||
3 years ago
|
match self {
|
||
|
Theme::Light => egui::Visuals::light(),
|
||
|
Theme::Dark => egui::Visuals::dark(),
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn setup(ctx: &egui::CtxRef, theme: Theme) {
|
||
|
#[cfg(target_os = "windows")]
|
||
|
use windows as module;
|
||
|
|
||
|
#[cfg(target_os = "linux")]
|
||
|
use linux as module;
|
||
|
|
||
|
#[cfg(target_os = "macos")]
|
||
|
use macos as module;
|
||
|
|
||
|
INSTANCE
|
||
|
.set(module::platform_colors(theme))
|
||
|
.expect("Could not setup colors");
|
||
|
let colors = module::platform_colors(theme);
|
||
3 years ago
|
let mut visuals = theme.visuals();
|
||
3 years ago
|
visuals.widgets.noninteractive.bg_fill = colors.window_background;
|
||
|
ctx.set_visuals(visuals);
|
||
|
module::setup(ctx)
|
||
|
}
|
||
|
|
||
|
pub fn platform_colors() -> &'static PlatformColors {
|
||
|
INSTANCE.get().unwrap()
|
||
3 years ago
|
}
|