From 54b4abf5a92e8a76043439f22695c312a8b8bbaf Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Mon, 31 Jul 2023 00:47:59 -0400 Subject: [PATCH] Draft out skeleton for minimal custom themes. For now, custom themes will use constant structs like in Sniffnet's original code. Custom themes will be self contained instead of polluting the original code base. This should make it easier for contributors to modify or add any extra themes without having to change code in too many files. --- src/gui/styles/style_constants.rs | 3 ++ src/gui/styles/types/custom_palette.rs | 50 ++++++++++++++++++++++++++ src/gui/styles/types/mod.rs | 1 + src/gui/styles/types/palette.rs | 17 +-------- src/gui/styles/types/style_type.rs | 3 ++ 5 files changed, 58 insertions(+), 16 deletions(-) create mode 100644 src/gui/styles/types/custom_palette.rs diff --git a/src/gui/styles/style_constants.rs b/src/gui/styles/style_constants.rs index 1f1654a5..e2332c5e 100644 --- a/src/gui/styles/style_constants.rs +++ b/src/gui/styles/style_constants.rs @@ -180,6 +180,7 @@ pub fn get_color_mix_chart(style: StyleType) -> f64 { match style { StyleType::Night | StyleType::DeepSea => 0.3, StyleType::Day | StyleType::MonAmour => 0.8, + StyleType::Custom(style) => style.to_ext().color_mixing, } } @@ -216,6 +217,7 @@ pub fn get_starred_color(style: StyleType) -> Color { b: 39.0 / 255.0, a: 0.8, }, + StyleType::Custom(style) => style.to_ext().starred, } } @@ -224,5 +226,6 @@ pub fn get_color_mix_filter_badge(style: StyleType) -> f32 { StyleType::Night | StyleType::DeepSea => 0.2, StyleType::Day => 0.7, StyleType::MonAmour => 0.5, + StyleType::Custom(style) => style.to_ext().badge_alpha, } } diff --git a/src/gui/styles/types/custom_palette.rs b/src/gui/styles/types/custom_palette.rs new file mode 100644 index 00000000..2c108a79 --- /dev/null +++ b/src/gui/styles/types/custom_palette.rs @@ -0,0 +1,50 @@ +use std::fmt; + +use iced::Color; +use serde::{Deserialize, Serialize}; + +use super::palette::Palette; + +/// Extension color for themes. +pub struct PaletteExtension { + /// Color of favorites star + pub starred: Color, + /// Badge/logo alpha + pub badge_alpha: f32, + /// Traffic chart color mixing + pub color_mixing: f64, +} + +/// Custom style with any relevant metadata +// pub struct CustomPalette { +// name: &'static str, +// palette: Palette, +// extension: PaletteExtension, +//} + +#[derive(Clone, Copy, Serialize, Deserialize, Debug, Hash, PartialEq)] +pub enum ExtraStyles { + Dracula, +} + +impl ExtraStyles { + pub fn to_palette(self) -> Palette { + match self { + ExtraStyles::Dracula => unimplemented!(), + } + } + + pub fn to_ext(self) -> PaletteExtension { + match self { + ExtraStyles::Dracula => unimplemented!(), + } + } +} + +impl fmt::Display for ExtraStyles { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match *self { + ExtraStyles::Dracula => write!(f, "Dracula"), + } + } +} diff --git a/src/gui/styles/types/mod.rs b/src/gui/styles/types/mod.rs index 629f43df..9f59cb24 100644 --- a/src/gui/styles/types/mod.rs +++ b/src/gui/styles/types/mod.rs @@ -1,3 +1,4 @@ +pub mod custom_palette; pub mod element_type; pub mod palette; pub mod style_tuple; diff --git a/src/gui/styles/types/palette.rs b/src/gui/styles/types/palette.rs index 6b5af113..de5c8e4f 100644 --- a/src/gui/styles/types/palette.rs +++ b/src/gui/styles/types/palette.rs @@ -35,28 +35,13 @@ pub struct Palette { pub round_containers: Color, } -/// Extension color for themes. -pub struct PaletteExtension { - /// Color of favorites star - pub starred: Color, - /// Badge/logo alpha - pub badge_alpha: f32, - /// Traffic chart color mixing - pub color_mixing: f64 -} - -pub struct CustomPalette { - name: &'static str, - palette: Palette, - extension: PaletteExtension -} - pub fn get_colors(style: StyleType) -> Palette { match style { StyleType::Night => NIGHT_STYLE, StyleType::Day => DAY_STYLE, StyleType::DeepSea => DEEP_SEA_STYLE, StyleType::MonAmour => MON_AMOUR_STYLE, + StyleType::Custom(style) => style.to_palette() } } diff --git a/src/gui/styles/types/style_type.rs b/src/gui/styles/types/style_type.rs index 5d46a48b..2ea4322a 100644 --- a/src/gui/styles/types/style_type.rs +++ b/src/gui/styles/types/style_type.rs @@ -1,5 +1,7 @@ use serde::{Deserialize, Serialize}; +use super::custom_palette::ExtraStyles; + /// Used to specify the kind of style of the application #[derive(Clone, Copy, Serialize, Deserialize, Debug, Hash, PartialEq)] pub enum StyleType { @@ -7,6 +9,7 @@ pub enum StyleType { Day, DeepSea, MonAmour, + Custom(ExtraStyles) } impl Default for StyleType {