From b1f0d4c187461e9eace1276e5923c88069c32cec Mon Sep 17 00:00:00 2001 From: Benedikt Terhechte Date: Sun, 14 Nov 2021 19:49:23 -0500 Subject: [PATCH] Added more colors to platform, improve on linux --- src/gui/app_state/startup.rs | 3 ++- src/gui/platform/linux.rs | 16 ++++++++++++++++ src/gui/platform/macos.rs | 16 ++++++++++++++++ src/gui/platform/mod.rs | 9 +++++++++ src/gui/platform/windows.rs | 16 ++++++++++++++++ src/gui/widgets/background.rs | 28 ++++++++++++++++++++++------ 6 files changed, 81 insertions(+), 7 deletions(-) diff --git a/src/gui/app_state/startup.rs b/src/gui/app_state/startup.rs index 6bfb656..8d32607 100644 --- a/src/gui/app_state/startup.rs +++ b/src/gui/app_state/startup.rs @@ -145,7 +145,7 @@ impl StartupUI { ui.add( egui::widgets::Label::new("Email Folder:") - .text_color(Color32::WHITE) + .text_color(platform_colors().text_primary) .text_style(TextStyle::Body), ); ui.end_row(); @@ -185,6 +185,7 @@ impl StartupUI { ui.add( egui::widgets::Label::new("Used to filter send mails") + .text_color(platform_colors().text_secondary) .text_style(TextStyle::Small), ); ui.end_row(); diff --git a/src/gui/platform/linux.rs b/src/gui/platform/linux.rs index f8bfc03..b689de5 100644 --- a/src/gui/platform/linux.rs +++ b/src/gui/platform/linux.rs @@ -9,12 +9,28 @@ pub fn platform_colors(theme: Theme) -> PlatformColors { // From Google images, Gtk match theme { Theme::Light => PlatformColors { + is_light: true, + animation_background: Color32::from_rgb(248, 246, 249), window_background: Color32::from_rgb(246, 245, 244), content_background: Color32::from_rgb(254, 254, 254), + text_primary: Color32::from_gray(0), + text_secondary: Color32::from_gray(30), + line1: Color32::from_gray(0), + line2: Color32::from_gray(30), + line3: Color32::from_gray(60), + line4: Color32::from_gray(90), }, Theme::Dark => PlatformColors { + is_light: false, + animation_background: Color32::from_gray(60), window_background: Color32::from_rgb(73, 73, 73), content_background: Color32::from_rgb(34, 32, 40), + text_primary: Color32::from_gray(255), + text_secondary: Color32::from_gray(200), + line1: Color32::from_gray(255), + line2: Color32::from_gray(210), + line3: Color32::from_gray(190), + line4: Color32::from_gray(120), }, } } diff --git a/src/gui/platform/macos.rs b/src/gui/platform/macos.rs index ee2fc9b..400d89a 100644 --- a/src/gui/platform/macos.rs +++ b/src/gui/platform/macos.rs @@ -16,12 +16,28 @@ use super::{PlatformColors, Theme}; pub fn platform_colors(theme: THeme) -> PlatformColors { match theme { Theme::Light => PlatformColors { + is_light: true, + animation_background: Color32::from_rgb(248, 246, 249), window_background: Color32::from_rgb(238, 236, 242), content_background: Color32::from_rgb(236, 234, 238), + text_primary: Color32::from_gray(0), + text_secondary: Color32::from_gray(30), + line1: Color32::from_gray(0), + line2: Color32::from_gray(30), + line3: Color32::from_gray(60), + line4: Color32::from_gray(90), }, Theme::Dark => PlatformColors { + is_light: false, + animation_background: Color32::from_rgb(0, 0, 0), window_background: Color32::from_rgb(36, 30, 42), content_background: Color32::from_rgb(20, 14, 26), + text_primary: Color32::from_gray(255), + text_secondary: Color32::from_gray(200), + line1: Color32::from_gray(255), + line2: Color32::from_gray(190), + line3: Color32::from_gray(150), + line4: Color32::from_gray(70), }, } } diff --git a/src/gui/platform/mod.rs b/src/gui/platform/mod.rs index 86a7f58..25e48c0 100644 --- a/src/gui/platform/mod.rs +++ b/src/gui/platform/mod.rs @@ -24,8 +24,17 @@ pub use macos::{initial_update, navigation_button}; /// Platform-Native Colors #[derive(Debug)] pub struct PlatformColors { + pub is_light: bool, + pub animation_background: Color32, pub window_background: Color32, pub content_background: Color32, + 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, } #[allow(unused)] diff --git a/src/gui/platform/windows.rs b/src/gui/platform/windows.rs index 4528cd4..4017454 100644 --- a/src/gui/platform/windows.rs +++ b/src/gui/platform/windows.rs @@ -8,12 +8,28 @@ pub fn platform_colors() -> PlatformColors { // From Google images, Windows 11 match theme { Theme::Light => PlatformColors { + is_light: true, + animation_background: Color32::from_rgb(248, 246, 249), window_background: Color32::from_rgb(241, 243, 246), content_background: Color32::from_rgb(251, 251, 253), + text_primary: Color32::from_gray(0), + text_secondary: Color32::from_gray(30), + line1: Color32::from_gray(0), + line2: Color32::from_gray(30), + line3: Color32::from_gray(60), + line4: Color32::from_gray(90), }, Theme::Dark => PlatformColors { + is_light: false, + animation_background: Color32::from_gray(60), window_background: Color32::from_rgb(32, 32, 32), content_background: Color32::from_rgb(34, 32, 40), + text_primary: Color32::from_gray(255), + text_secondary: Color32::from_gray(200), + line1: Color32::from_gray(255), + line2: Color32::from_gray(210), + line3: Color32::from_gray(190), + line4: Color32::from_gray(120), }, } } diff --git a/src/gui/widgets/background.rs b/src/gui/widgets/background.rs index 0f8d15d..c4e06dc 100644 --- a/src/gui/widgets/background.rs +++ b/src/gui/widgets/background.rs @@ -5,6 +5,8 @@ use eframe::egui::{ use std::ops::Rem; +use crate::gui::platform::{platform_colors, PlatformColors}; + /// This will draw Ui with a background color and margins. /// This can be used for calls that don't provide a `Frame`, /// such as `horizontal` or `vertical` @@ -81,6 +83,8 @@ impl<'a> AnimatedBackground<'a> { // paint stuff let rect_size = vec2(size.x / divisions, size.y / divisions); + let colors = platform_colors(); + // we only animate if there's no progress let (offset, add) = if self.animate_progress.is_none() { // Define the animation speed @@ -142,9 +146,19 @@ impl<'a> AnimatedBackground<'a> { let rect = Rect::from_min_size(pos, size); // the fill color is based on the added block count color_adder += *n; - let color = (color_adder % 50) as u8; - painter.rect_filled(rect, 0.0, Color32::from_gray(color)); - painter.rect_stroke(rect, 0.0, Stroke::new(1.0, Color32::from_gray(110))); + let color_addition = if colors.is_light { + -1 * (color_adder % 50) as i8 + } else { + (color_adder % 50) as i8 + }; + let color = Color32::from_rgb( + (colors.animation_background.r() as i8 + color_addition) as u8, + (colors.animation_background.g() as i8 + color_addition) as u8, + (colors.animation_background.b() as i8 + color_addition) as u8, + ); + + painter.rect_filled(rect, 0.0, color); + painter.rect_stroke(rect, 0.0, Stroke::new(1.0, colors.line3)); } } @@ -162,6 +176,8 @@ impl<'a> AnimatedBackground<'a> { recurse: &[(i8, i8, i8)], total: usize, ) { + let colors = platform_colors(); + for y in 0..=(division + 2.0) as i8 { for x in 0..=(division + 2.0) as i8 { let fx = ((x - 1) as f32 * size.x) + (offset as f32); @@ -173,14 +189,14 @@ impl<'a> AnimatedBackground<'a> { // on the x axis take the offset into account let rx = (*rx).rem((total as i8) + 1); if rx == x && ry == &y { - Self::draw_segmentation(painter, rect, *rd); + Self::draw_segmentation(painter, rect, *rd, colors); } } } } } - fn draw_segmentation(painter: &Painter, into: Rect, divisions: i8) { + fn draw_segmentation(painter: &Painter, into: Rect, divisions: i8, colors: &PlatformColors) { let mut rect = into; for d in 0..=divisions { // division back and forth in direction @@ -207,7 +223,7 @@ impl<'a> AnimatedBackground<'a> { }, ) }; - painter.rect_stroke(next, 0.0, Stroke::new(1.0, Color32::from_gray(70))); + painter.rect_stroke(next, 0.0, Stroke::new(1.0, colors.line4)); rect = next; } }