Improved platform color handling

pull/2/head
Benedikt Terhechte 3 years ago
parent 97caf62240
commit 23afef2ea5

2
Cargo.lock generated

@ -1645,11 +1645,11 @@ dependencies = [
"eyre",
"flate2",
"image",
"lazy_static",
"lru",
"mbox-reader",
"num-format",
"objc",
"once_cell",
"rand",
"rayon",
"regex",

@ -28,10 +28,10 @@ tracing-subscriber = "0.3.0"
rusqlite = {version = "0.25.3", features = ["chrono", "trace", "serde_json"]}
regex = "1.5.3"
flate2 = "1.0.22"
once_cell = "1.8.0"
email-parser = { git = "https://github.com/terhechte/email-parser", features = ["sender", "to", "in-reply-to", "date", "subject", "mime", "allow-duplicate-headers", "compatibility-fixes"]}
rayon = "1.5.1"
chrono = "0.4.19"
lazy_static = "*"
serde_json = "*"
serde = { version = "*", features = ["derive"]}
crossbeam-channel = "0.5.1"

@ -4,6 +4,7 @@ use eframe::{
};
use super::app_state::StateUI;
use super::platform::Theme;
use super::textures::Textures;
pub struct PostsackApp {
@ -30,13 +31,7 @@ impl App for PostsackApp {
}
fn setup(&mut self, ctx: &egui::CtxRef, frame: &mut Frame<'_>, _storage: Option<&dyn Storage>) {
super::platform::setup(ctx);
// Adapt to the platform colors
let platform_colors = super::platform::platform_colors();
let mut visuals = egui::Visuals::dark();
visuals.widgets.noninteractive.bg_fill = platform_colors.window_background_dark;
ctx.set_visuals(visuals);
super::platform::setup(ctx, Theme::Dark);
// Load textures
self.textures = Some(Textures::populated(frame));

@ -202,7 +202,7 @@ impl ImporterUI {
shadow_background(
ui.painter(),
paint_rect,
colors.window_background_dark,
colors.window_background,
Stroke::new(1.0, Color32::from_gray(90)),
12.0,
Shadow::big_dark(),
@ -271,7 +271,7 @@ impl ImporterUI {
}
#[cfg(not(target_os = "macos"))]
fn permission_ui(&mut self, ui: &mut egui::Ui, textures: &Option<Textures>) -> Response {
fn permission_ui(&mut self, ui: &mut egui::Ui, _textures: &Option<Textures>) -> Response {
ui.label("")
}
}

@ -52,7 +52,7 @@ impl StateUIVariant for MainUI {
let platform_colors = super::super::platform::platform_colors();
let frame = egui::containers::Frame::none()
.fill(platform_colors.window_background_dark)
.fill(platform_colors.window_background)
.stroke(Stroke::none());
egui::TopBottomPanel::top("my_panel")
@ -86,7 +86,7 @@ impl StateUIVariant for MainUI {
});
} else {
let stroke = Stroke::none();
let fill = platform_colors.content_background_dark;
let fill = platform_colors.content_background;
super::super::widgets::background::color_background(
ui,
15.0,

@ -113,7 +113,7 @@ impl StartupUI {
shadow_background(
ui.painter(),
paint_rect,
colors.window_background_dark,
colors.window_background,
Stroke::new(1.0, Color32::from_gray(90)),
12.0,
Shadow::big_dark(),

@ -1,25 +1,29 @@
#![cfg(target_os = "linux")]
use eyre::Result;
use eframe::egui::{self, Color32};
use eyre::Result;
use super::PlatformColors;
use super::{PlatformColors, Theme};
pub fn platform_colors() -> PlatformColors {
pub fn platform_colors(theme: Theme) -> PlatformColors {
// From Google images, Gtk
PlatformColors {
window_background_dark: Color32::from_rgb(53, 53, 53),
window_background_light: Color32::from_rgb(246, 245, 244),
content_background_dark: Color32::from_rgb(34, 32, 40),
content_background_light: Color32::from_rgb(254, 254, 254),
match theme {
Theme::Light => PlatformColors {
window_background: Color32::from_rgb(246, 245, 244),
content_background: Color32::from_rgb(254, 254, 254),
},
Theme::Dark => PlatformColors {
window_background: Color32::from_rgb(73, 73, 73),
content_background: Color32::from_rgb(34, 32, 40),
},
}
}
/// This is called from `App::setup`
pub fn setup(ctx: &egui::CtxRef) {}
pub fn setup(_ctx: &egui::CtxRef) {}
/// This is called once from `App::update` on the first run.
pub fn initial_update(ctx: &egui::CtxRef) -> Result<()> {
pub fn initial_update(_ctx: &egui::CtxRef) -> Result<()> {
Ok(())
}

@ -11,14 +11,18 @@ use eframe::egui::{self, Color32, FontDefinitions, FontFamily, Stroke};
use eyre::{bail, Result};
use objc::runtime::{Object, YES};
use super::PlatformColors;
use super::{PlatformColors, Theme};
pub fn platform_colors() -> PlatformColors {
PlatformColors {
window_background_dark: Color32::from_rgb(36, 30, 42),
window_background_light: Color32::from_rgb(238, 236, 242),
content_background_dark: Color32::from_rgb(20, 14, 26),
content_background_light: Color32::from_rgb(236, 234, 238),
pub fn platform_colors(theme: THeme) -> PlatformColors {
match theme {
Theme::Light => PlatformColors {
window_background: Color32::from_rgb(238, 236, 242),
content_background: Color32::from_rgb(236, 234, 238),
},
Theme::Dark => PlatformColors {
window_background: Color32::from_rgb(36, 30, 42),
content_background: Color32::from_rgb(20, 14, 26),
},
}
}

@ -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()
}

@ -1,16 +1,20 @@
#![cfg(target_os = "windows")]
use eframe::egui;
use eframe::egui::{self, Color32};
use super::PlatformColors;
use super::{PlatformColors, Theme};
pub fn platform_colors() -> PlatformColors {
// From Google images, Windows 11
PlatformColors {
window_background_dark: Color32::from_rgb(32, 32, 32),
window_background_light: Color32::from_rgb(241, 243, 246),
content_background_dark: Color32::from_rgb(34, 32, 40),
content_background_light: Color32::from_rgb(251, 251, 253),
match theme {
Theme::Light => PlatformColors {
window_background: Color32::from_rgb(241, 243, 246),
content_background: Color32::from_rgb(251, 251, 253),
},
Theme::Dark => PlatformColors {
window_background: Color32::from_rgb(32, 32, 32),
content_background: Color32::from_rgb(34, 32, 40),
},
}
}

@ -16,7 +16,7 @@ pub struct Textures {
}
impl Textures {
pub fn populated(frame: &mut epi::Frame<'_>) -> Textures {
pub fn populated(_frame: &mut epi::Frame<'_>) -> Textures {
#[cfg(target_os = "macos")]
{
let missing_permissions_image = install_missing_permission_image(
@ -35,6 +35,7 @@ impl Textures {
/// Load the permission image
// via: https://github.com/emilk/egui/blob/master/eframe/examples/image.rs
#[allow(unused)]
fn install_missing_permission_image(
image_data: &[u8],
frame: &mut epi::Frame<'_>,

@ -46,7 +46,7 @@ impl<'a> Widget for Rectangles<'a> {
for (index, item) in items.iter().enumerate() {
let item_response = ui.put(
item.layout_rect(),
rectangle(&item, active, colors.content_background_dark, index, total),
rectangle(&item, active, colors.content_background, index, total),
);
if item_response.clicked() && active {
*self.error = self.engine.push(item.clone()).err();

Loading…
Cancel
Save