From c6eba704eca974a53542ec1782164a3e62a7d78b Mon Sep 17 00:00:00 2001 From: Mike Dilger Date: Sat, 2 Sep 2023 11:18:31 +1200 Subject: [PATCH] Theme color fixes, plus --- src/ui/feed/note/mod.rs | 2 +- src/ui/theme/classic.rs | 36 +++++++++++++++++++++++++++--------- src/ui/theme/default.rs | 33 ++++++++++++++++----------------- src/ui/theme/mod.rs | 15 ++++++++++----- src/ui/theme/roundy.rs | 27 ++++++++++++++++++++------- 5 files changed, 74 insertions(+), 39 deletions(-) diff --git a/src/ui/feed/note/mod.rs b/src/ui/feed/note/mod.rs index f6fb7acd..dda31ec6 100644 --- a/src/ui/feed/note/mod.rs +++ b/src/ui/feed/note/mod.rs @@ -589,7 +589,7 @@ fn render_note_inner( top: 8.0, }) .show(ui, |ui| { - let color = app.settings.theme.warning_marker_text_color(); + let color = app.settings.theme.accent_complementary_color(); ui.horizontal_wrapped(|ui| { ui.add(Label::new( RichText::new(format!("proxied from {}: ", proxy)).color(color), diff --git a/src/ui/theme/classic.rs b/src/ui/theme/classic.rs index 166feb9b..e1e4c1ee 100644 --- a/src/ui/theme/classic.rs +++ b/src/ui/theme/classic.rs @@ -2,7 +2,7 @@ use super::{FeedProperties, NoteRenderData, ThemeDef}; use crate::ui::HighlightType; use eframe::egui::style::{Selection, WidgetVisuals, Widgets}; use eframe::egui::{FontDefinitions, Margin, RichText, Style, TextFormat, TextStyle, Visuals}; -use eframe::epaint::{Color32, FontFamily, FontId, Rounding, Shadow, Stroke}; +use eframe::epaint::{ecolor, Color32, FontFamily, FontId, Rounding, Shadow, Stroke}; use std::collections::BTreeMap; #[derive(Default)] @@ -13,16 +13,29 @@ impl ThemeDef for ClassicTheme { "Classic" } - fn accent_color(_dark_mode: bool) -> Color32 { - Color32::from_rgb(0, 0, 0) // Not used + fn accent_color(dark_mode: bool) -> Color32 { + // not used within + if dark_mode { + Color32::from_rgb(116, 167, 204) + } else { + Color32::from_rgb(85, 122, 149) + } } - fn highlight_color(_dark_mode: bool) -> Color32 { - Color32::from_rgb(0, 0, 0) // Not used + fn accent_complementary_color(dark_mode: bool) -> Color32 { + // not used within + let mut hsva: ecolor::HsvaGamma = Self::accent_color(dark_mode).into(); + hsva.h = (hsva.h + 0.5) % 1.0; + hsva.into() } - fn accent_complementary_color(_dark_mode: bool) -> Color32 { - Color32::from_rgb(0, 0, 0) // Not used + fn highlighted_note_bgcolor(dark_mode: bool) -> Color32 { + // not used within + if dark_mode { + Color32::from_rgb(41, 34, 46) + } else { + Color32::from_rgb(255, 255, 237) + } } fn get_style(dark_mode: bool) -> Style { @@ -325,7 +338,7 @@ impl ThemeDef for ClassicTheme { Color32::BLACK }; let grey = if dark_mode { - Color32::DARK_GRAY + Color32::from_gray(36) } else { Color32::LIGHT_GRAY }; @@ -339,6 +352,11 @@ impl ThemeDef for ClassicTheme { } else { Color32::DARK_RED }; + let purple = if dark_mode { + Color32::from_rgb(0xA0, 0x40, 0xA0) + } else { + Color32::from_rgb(0x80, 0, 0x80) + }; match highlight_type { HighlightType::Nothing => TextFormat { @@ -361,7 +379,7 @@ impl ThemeDef for ClassicTheme { HighlightType::Relay => TextFormat { font_id: FontId::new(12.5, FontFamily::Monospace), background: grey, - color: red, + color: purple, ..Default::default() }, HighlightType::Hyperlink => TextFormat { diff --git a/src/ui/theme/default.rs b/src/ui/theme/default.rs index b626977d..f16ebee4 100644 --- a/src/ui/theme/default.rs +++ b/src/ui/theme/default.rs @@ -16,28 +16,27 @@ impl ThemeDef for DefaultTheme { } fn accent_color(dark_mode: bool) -> Color32 { - #[allow(clippy::if_same_then_else)] if dark_mode { - Color32::from_rgb(85, 122, 149) + Color32::from_rgb(116, 167, 204) } else { Color32::from_rgb(85, 122, 149) } } - fn highlight_color(dark_mode: bool) -> Color32 { - if dark_mode { - Color32::from_rgb(34, 28, 38) - } else { - Color32::from_rgb(255, 255, 237) - } - } - fn accent_complementary_color(dark_mode: bool) -> Color32 { let mut hsva: ecolor::HsvaGamma = Self::accent_color(dark_mode).into(); hsva.h = (hsva.h + 0.5) % 1.0; hsva.into() } + fn highlighted_note_bgcolor(dark_mode: bool) -> Color32 { + if dark_mode { + Color32::from_rgb(41, 34, 46) + } else { + Color32::from_rgb(255, 255, 237) + } + } + fn get_style(dark_mode: bool) -> Style { let mut style = Style::default(); @@ -339,7 +338,7 @@ impl ThemeDef for DefaultTheme { Color32::BLACK }; let grey = if dark_mode { - Color32::DARK_GRAY + Color32::from_gray(16) } else { Color32::LIGHT_GRAY }; @@ -541,20 +540,20 @@ impl ThemeDef for DefaultTheme { fn feed_frame_fill(dark_mode: bool, post: &NoteRenderData) -> Color32 { if post.is_main_event { if dark_mode { - let mut hsva: ecolor::HsvaGamma = Self::highlight_color(dark_mode).into(); + let mut hsva: ecolor::HsvaGamma = Self::highlighted_note_bgcolor(dark_mode).into(); hsva.h = (hsva.h - 0.07) % 1.0; hsva.v = (hsva.v + 0.1) % 1.0; hsva.into() } else { - let mut hsva: ecolor::HsvaGamma = Self::highlight_color(dark_mode).into(); + let mut hsva: ecolor::HsvaGamma = Self::highlighted_note_bgcolor(dark_mode).into(); hsva.h = (hsva.h + 0.07) % 1.0; hsva.into() } } else if post.is_new { if dark_mode { - Self::highlight_color(true) + Self::highlighted_note_bgcolor(true) } else { - Self::highlight_color(false) + Self::highlighted_note_bgcolor(false) } } else { if dark_mode { @@ -563,7 +562,7 @@ impl ThemeDef for DefaultTheme { hsva.v = 0.12; hsva.into() } else { - let mut hsva: ecolor::HsvaGamma = Self::highlight_color(dark_mode).into(); + let mut hsva: ecolor::HsvaGamma = Self::highlighted_note_bgcolor(dark_mode).into(); hsva.s = 0.0; hsva.v = 1.0; hsva.into() @@ -583,7 +582,7 @@ impl ThemeDef for DefaultTheme { let rgb: Color32 = hsva.into(); Stroke::new(1.0, rgb) } else { - let mut hsva: ecolor::HsvaGamma = Self::highlight_color(dark_mode).into(); + let mut hsva: ecolor::HsvaGamma = Self::highlighted_note_bgcolor(dark_mode).into(); hsva.s = 0.0; hsva.v = 0.90; let rgb: Color32 = hsva.into(); diff --git a/src/ui/theme/mod.rs b/src/ui/theme/mod.rs index 23deae10..dceb9368 100644 --- a/src/ui/theme/mod.rs +++ b/src/ui/theme/mod.rs @@ -74,16 +74,16 @@ macro_rules! theme_dispatch { } #[allow(dead_code)] - pub fn highlight_color(&self) -> Color32 { + pub fn accent_complementary_color(&self) -> Color32 { match self.variant { - $( $variant => $class::highlight_color(self.dark_mode), )+ + $( $variant => $class::accent_complementary_color(self.dark_mode), )+ } } #[allow(dead_code)] - pub fn accent_complementary_color(&self) -> Color32 { + pub fn highlighted_note_bgcolor(&self) -> Color32 { match self.variant { - $( $variant => $class::accent_complementary_color(self.dark_mode), )+ + $( $variant => $class::highlighted_note_bgcolor(self.dark_mode), )+ } } @@ -330,8 +330,13 @@ theme_dispatch!( pub trait ThemeDef: Send + Sync { // User facing name fn name() -> &'static str; + + // Used for strokes, lines, and text in various places fn accent_color(dark_mode: bool) -> Color32; - fn highlight_color(dark_mode: bool) -> Color32; + + // Used as background for highlighting unread events + fn highlighted_note_bgcolor(dark_mode: bool) -> Color32; + fn accent_complementary_color(dark_mode: bool) -> Color32; // These styles are used by egui by default for widgets if you don't override them diff --git a/src/ui/theme/roundy.rs b/src/ui/theme/roundy.rs index 464f9132..0630c372 100644 --- a/src/ui/theme/roundy.rs +++ b/src/ui/theme/roundy.rs @@ -13,16 +13,29 @@ impl ThemeDef for RoundyTheme { "Roundy" } - fn accent_color(_dark_mode: bool) -> Color32 { - Color32::from_rgb(0, 0, 0) // Not used + fn accent_color(dark_mode: bool) -> Color32 { + // not used within + if dark_mode { + Color32::from_rgb(116, 167, 204) + } else { + Color32::from_rgb(85, 122, 149) + } } - fn highlight_color(_dark_mode: bool) -> Color32 { - Color32::from_rgb(0, 0, 0) // Not used + fn accent_complementary_color(dark_mode: bool) -> Color32 { + // not used within + let mut hsva: ecolor::HsvaGamma = Self::accent_color(dark_mode).into(); + hsva.h = (hsva.h + 0.5) % 1.0; + hsva.into() } - fn accent_complementary_color(_dark_mode: bool) -> Color32 { - Color32::from_rgb(0, 0, 0) // Not used + fn highlighted_note_bgcolor(dark_mode: bool) -> Color32 { + // not used within + if dark_mode { + Color32::from_rgb(41, 34, 46) + } else { + Color32::from_rgb(255, 255, 237) + } } fn get_style(dark_mode: bool) -> Style { @@ -331,7 +344,7 @@ impl ThemeDef for RoundyTheme { Color32::BLACK }; let grey = if dark_mode { - Color32::DARK_GRAY + Color32::from_gray(36) } else { Color32::LIGHT_GRAY };