Skip to content

Commit

Permalink
Draft out skeleton for minimal custom themes.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
joshuamegnauth54 committed Jul 31, 2023
1 parent 2d00141 commit 54b4abf
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 16 deletions.
3 changes: 3 additions & 0 deletions src/gui/styles/style_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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,
}
}

Expand All @@ -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,
}
}
50 changes: 50 additions & 0 deletions src/gui/styles/types/custom_palette.rs
Original file line number Diff line number Diff line change
@@ -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"),
}
}
}
1 change: 1 addition & 0 deletions src/gui/styles/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod custom_palette;
pub mod element_type;
pub mod palette;
pub mod style_tuple;
Expand Down
17 changes: 1 addition & 16 deletions src/gui/styles/types/palette.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/gui/styles/types/style_type.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
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 {
Night,
Day,
DeepSea,
MonAmour,
Custom(ExtraStyles)
}

impl Default for StyleType {
Expand Down

0 comments on commit 54b4abf

Please sign in to comment.