mirror of https://github.com/terhechte/postsack
Improved platform color handling
parent
97caf62240
commit
23afef2ea5
@ -1,27 +1,69 @@
|
||||
use eframe::egui::{self, Color32, Visuals};
|
||||
use once_cell::sync::OnceCell;
|
||||
|
||||
static INSTANCE: OnceCell<PlatformColors> = OnceCell::new();
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
mod windows;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
pub use windows::{initial_update, navigation_button, platform_colors, setup};
|
||||
pub use windows::{initial_update, navigation_button};
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
mod linux;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub use linux::{initial_update, navigation_button, platform_colors, setup};
|
||||
pub use linux::{initial_update, navigation_button};
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
mod macos;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub use macos::{initial_update, navigation_button, platform_colors, setup};
|
||||
pub use macos::{initial_update, navigation_button};
|
||||
|
||||
use eframe::egui::Color32;
|
||||
/// Platform-Native Colors
|
||||
#[derive(Debug)]
|
||||
pub struct PlatformColors {
|
||||
pub window_background_dark: Color32,
|
||||
pub window_background_light: Color32,
|
||||
pub content_background_dark: Color32,
|
||||
pub content_background_light: Color32,
|
||||
pub window_background: Color32,
|
||||
pub content_background: Color32,
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum Theme {
|
||||
Light,
|
||||
Dark,
|
||||
}
|
||||
|
||||
impl Theme {
|
||||
pub fn to_visuals(&self) -> Visuals {
|
||||
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);
|
||||
let mut visuals = theme.to_visuals();
|
||||
visuals.widgets.noninteractive.bg_fill = colors.window_background;
|
||||
ctx.set_visuals(visuals);
|
||||
module::setup(ctx)
|
||||
}
|
||||
|
||||
pub fn platform_colors() -> &'static PlatformColors {
|
||||
INSTANCE.get().unwrap()
|
||||
}
|
||||
|
Loading…
Reference in New Issue