From 2d00141a672939e0b81450d1eebe4edb5f687bed Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Sun, 30 Jul 2023 23:01:06 -0400 Subject: [PATCH 01/21] Define palette extension structs. The new types are to avoid mangling the current style implementation too much. --- src/gui/styles/types/palette.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/gui/styles/types/palette.rs b/src/gui/styles/types/palette.rs index fd0026381..6b5af113c 100644 --- a/src/gui/styles/types/palette.rs +++ b/src/gui/styles/types/palette.rs @@ -35,6 +35,22 @@ 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, From 54b4abf5a92e8a76043439f22695c312a8b8bbaf Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Mon, 31 Jul 2023 00:47:59 -0400 Subject: [PATCH 02/21] 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 1f1654a54..e2332c5ea 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 000000000..2c108a791 --- /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 629f43df2..9f59cb24e 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 6b5af113c..de5c8e4f2 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 5d46a48b2..2ea4322a3 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 { From 3efdceb52702f7b345bc3889bb2c04bd9f7320c3 Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Tue, 1 Aug 2023 00:37:03 -0400 Subject: [PATCH 03/21] Add `Dracula` as an example theme to test. I implemented a theme to ensure there are no compiliation issues. Floating point math can't be called from a const context, so the themes are returned from a non-const function for now. `iced::color!` is used for ergonomics. --- .../{custom_palette.rs => custom_styles.rs} | 28 +++++++++++++------ src/gui/styles/types/custom_styles/dracula.rs | 26 +++++++++++++++++ src/gui/styles/types/mod.rs | 2 +- src/gui/styles/types/style_type.rs | 2 +- 4 files changed, 47 insertions(+), 11 deletions(-) rename src/gui/styles/types/{custom_palette.rs => custom_styles.rs} (60%) create mode 100644 src/gui/styles/types/custom_styles/dracula.rs diff --git a/src/gui/styles/types/custom_palette.rs b/src/gui/styles/types/custom_styles.rs similarity index 60% rename from src/gui/styles/types/custom_palette.rs rename to src/gui/styles/types/custom_styles.rs index 2c108a791..2ab9d4a88 100644 --- a/src/gui/styles/types/custom_palette.rs +++ b/src/gui/styles/types/custom_styles.rs @@ -1,3 +1,5 @@ +mod dracula; + use std::fmt; use iced::Color; @@ -5,6 +7,16 @@ use serde::{Deserialize, Serialize}; use super::palette::Palette; +/// Custom style with any relevant metadata +pub struct CustomPalette { + /// Displayable name of the style (i.e. "Catppuccin (Mocha)") + name: &'static str, + /// Color scheme's palette + palette: Palette, + /// Extra colors such as the favorites star + extension: PaletteExtension, +} + /// Extension color for themes. pub struct PaletteExtension { /// Color of favorites star @@ -15,28 +27,26 @@ pub struct PaletteExtension { pub color_mixing: f64, } -/// Custom style with any relevant metadata -// pub struct CustomPalette { -// name: &'static str, -// palette: Palette, -// extension: PaletteExtension, -//} - +/// Built in extra styles #[derive(Clone, Copy, Serialize, Deserialize, Debug, Hash, PartialEq)] pub enum ExtraStyles { Dracula, } impl ExtraStyles { + /// [Palette] of the [ExtraStyles] variant + #[inline] pub fn to_palette(self) -> Palette { match self { - ExtraStyles::Dracula => unimplemented!(), + ExtraStyles::Dracula => dracula::dracula().palette, } } + /// Extension colors for the current [ExtraStyles] variant + #[inline] pub fn to_ext(self) -> PaletteExtension { match self { - ExtraStyles::Dracula => unimplemented!(), + ExtraStyles::Dracula => dracula::dracula().extension, } } } diff --git a/src/gui/styles/types/custom_styles/dracula.rs b/src/gui/styles/types/custom_styles/dracula.rs new file mode 100644 index 000000000..c599fd81c --- /dev/null +++ b/src/gui/styles/types/custom_styles/dracula.rs @@ -0,0 +1,26 @@ +//! Dracula theme +//! https://draculatheme.com/ +use iced::color; + +use super::{CustomPalette, Palette, PaletteExtension}; + +pub(super) fn dracula() -> CustomPalette { + CustomPalette { + name: "Dracula", + palette: Palette { + primary: color!(0x44475a), // Current line + secondary: color!(0xff79c6), // Pink + outgoing: color!(0x8be9fd), // Cyan + buttons: color!(0x6272a4), // Comments + text_headers: color!(0x44475a), // Current line + text_body: color!(0xf8f8f2), // Foreground + round_borders: color!(0xbd93f9), // Purple + round_containers: color!(0x44475a), // Current line + }, + extension: PaletteExtension { + starred: color!(0xf1fa8c), + badge_alpha: 0.75, + color_mixing: 0.3, + }, + } +} diff --git a/src/gui/styles/types/mod.rs b/src/gui/styles/types/mod.rs index 9f59cb24e..10114ac43 100644 --- a/src/gui/styles/types/mod.rs +++ b/src/gui/styles/types/mod.rs @@ -1,4 +1,4 @@ -pub mod custom_palette; +pub mod custom_styles; pub mod element_type; pub mod palette; pub mod style_tuple; diff --git a/src/gui/styles/types/style_type.rs b/src/gui/styles/types/style_type.rs index 2ea4322a3..40040fe33 100644 --- a/src/gui/styles/types/style_type.rs +++ b/src/gui/styles/types/style_type.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use super::custom_palette::ExtraStyles; +use super::custom_styles::ExtraStyles; /// Used to specify the kind of style of the application #[derive(Clone, Copy, Serialize, Deserialize, Debug, Hash, PartialEq)] From 5e333e3790e7e5eb43d12e0efd59fa914c1bc279 Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Wed, 2 Aug 2023 00:50:16 -0400 Subject: [PATCH 04/21] Automatically append custom styles to settings. * Support appending extra styles to the settings page AFTER the built in styles. * Make the whole thing scrollable. --- src/gui/pages/settings_style_page.rs | 54 +++++++++++++++++++++++++-- src/gui/styles/types/custom_styles.rs | 5 +++ 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/gui/pages/settings_style_page.rs b/src/gui/pages/settings_style_page.rs index 347acbcd4..d8fbd1994 100644 --- a/src/gui/pages/settings_style_page.rs +++ b/src/gui/pages/settings_style_page.rs @@ -1,12 +1,13 @@ use iced::alignment::{Horizontal, Vertical}; -use iced::widget::{Button, Column, Container, Row, Text}; -use iced::{Alignment, Length}; -use iced_native::widget::{horizontal_space, vertical_space, Rule}; +use iced::widget::{Button, Column, Container, Row, Scrollable, Text}; +use iced::{Alignment, Element, Length}; +use iced_native::widget::{horizontal_space, vertical_space, Rule, Space}; use crate::gui::components::tab::get_settings_tabs; use crate::gui::pages::settings_notifications_page::settings_header; use crate::gui::pages::types::settings_page::SettingsPage; use crate::gui::styles::style_constants::{get_font, BORDER_WIDTH, FONT_SIZE_SUBTITLE}; +use crate::gui::styles::types::custom_styles::ExtraStyles; use crate::gui::styles::types::element_type::ElementType; use crate::gui::styles::types::style_tuple::StyleTuple; use crate::gui::types::message::Message; @@ -19,7 +20,7 @@ use crate::{Sniffer, StyleType}; pub fn settings_style_page(sniffer: &Sniffer) -> Container { let font = get_font(sniffer.style); - let content = Column::new() + let mut content = Column::new() .align_items(Alignment::Center) .width(Length::Fill) .push(settings_header(sniffer.style, sniffer.language)) @@ -81,6 +82,13 @@ pub fn settings_style_page(sniffer: &Sniffer) -> Container { )), ); + // Append custom styles to official styles. + content = content.push(vertical_space(Length::Fixed(10.0))); + for style in get_extra_styles(ExtraStyles::all_styles()) { + content = content.push(style); + } + let content = Scrollable::new(content); + Container::new(content) .height(Length::Fixed(400.0)) .width(Length::Fixed(800.0)) @@ -155,3 +163,41 @@ fn get_palette(style: StyleType) -> Container<'static, Message> { StyleTuple(style, ElementType::Palette), )) } + +// Buttons for each extra style arranged in rows of two +fn get_extra_styles(styles: &[ExtraStyles]) -> Vec> { + // Map each extra style into a palette container + let mut styles = styles.iter().map(|&style| { + let name = style.to_string(); + let description = "".to_owned(); + let style = StyleType::Custom(style); + get_palette_container(style, name, description, style) + }); + + // The best way to do this would be with itertools, but that would introduce another dependency. + let mut children = Vec::with_capacity(styles.len()); + + // This handles the case where there aren't an even number of styles. + // [Iterator::zip] drops remainders. Itertools' `zip_longest` and the unstable array chunks API + // are both better solutions. + while let (Some(first), second) = (styles.next(), styles.next()) { + // Add both styles and the vertical space if there are two styles. + if let Some(second) = second { + children.extend([ + Row::new() + .push(first) + .push(horizontal_space(Length::Fixed(15.0))) + .push(second) + .into(), + >>::into(vertical_space(Length::Fixed(10.0))), + ]); + } else { + children.extend([ + Row::new().push(first).into(), + >>::into(vertical_space(Length::Fixed(10.0))), + ]); + } + } + + children +} diff --git a/src/gui/styles/types/custom_styles.rs b/src/gui/styles/types/custom_styles.rs index 2ab9d4a88..883a68693 100644 --- a/src/gui/styles/types/custom_styles.rs +++ b/src/gui/styles/types/custom_styles.rs @@ -49,6 +49,11 @@ impl ExtraStyles { ExtraStyles::Dracula => dracula::dracula().extension, } } + + #[inline] + pub const fn all_styles() -> &'static [Self] { + &[ExtraStyles::Dracula] + } } impl fmt::Display for ExtraStyles { From 20446025f7cd0f9eda72ae8af1db4bfca870098a Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Wed, 2 Aug 2023 21:38:50 -0400 Subject: [PATCH 05/21] Add gruvbox. --- src/gui/styles/types/custom_styles.rs | 7 ++++- src/gui/styles/types/custom_styles/gruvbox.rs | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/gui/styles/types/custom_styles/gruvbox.rs diff --git a/src/gui/styles/types/custom_styles.rs b/src/gui/styles/types/custom_styles.rs index 883a68693..0511e8569 100644 --- a/src/gui/styles/types/custom_styles.rs +++ b/src/gui/styles/types/custom_styles.rs @@ -1,4 +1,5 @@ mod dracula; +mod gruvbox; use std::fmt; @@ -31,6 +32,7 @@ pub struct PaletteExtension { #[derive(Clone, Copy, Serialize, Deserialize, Debug, Hash, PartialEq)] pub enum ExtraStyles { Dracula, + Gruvbox, } impl ExtraStyles { @@ -39,6 +41,7 @@ impl ExtraStyles { pub fn to_palette(self) -> Palette { match self { ExtraStyles::Dracula => dracula::dracula().palette, + ExtraStyles::Gruvbox => gruvbox::gruvbox_dark().palette, } } @@ -47,12 +50,13 @@ impl ExtraStyles { pub fn to_ext(self) -> PaletteExtension { match self { ExtraStyles::Dracula => dracula::dracula().extension, + ExtraStyles::Gruvbox => gruvbox::gruvbox_dark().extension, } } #[inline] pub const fn all_styles() -> &'static [Self] { - &[ExtraStyles::Dracula] + &[ExtraStyles::Dracula, ExtraStyles::Gruvbox] } } @@ -60,6 +64,7 @@ impl fmt::Display for ExtraStyles { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { ExtraStyles::Dracula => write!(f, "Dracula"), + ExtraStyles::Gruvbox => write!(f, "Gruvbox (Dark)"), } } } diff --git a/src/gui/styles/types/custom_styles/gruvbox.rs b/src/gui/styles/types/custom_styles/gruvbox.rs new file mode 100644 index 000000000..9c9ed7719 --- /dev/null +++ b/src/gui/styles/types/custom_styles/gruvbox.rs @@ -0,0 +1,27 @@ +//! Gruvbox +//! https://github.com/morhetz/gruvbox + +use iced::color; + +use super::{CustomPalette, Palette, PaletteExtension}; + +pub(super) fn gruvbox_dark() -> CustomPalette { + CustomPalette { + name: "Gruvbox (Dark)", + palette: Palette { + primary: color!(0x282828), // bg + secondary: color!(0xfe8019), // orange + outgoing: color!(0x8ec07c), // aqua + buttons: color!(0x928374), // gray + text_headers: color!(0x1d2021), // bg0_h + text_body: color!(0xebdbb2), // fg + round_borders: color!(0x98971a), // green + round_containers: color!(0x504945), // bg2 + }, + extension: PaletteExtension { + starred: color!(0xd79921), + badge_alpha: 0.75, + color_mixing: 0.3, + }, + } +} From 5722964a287f208312799ab7f43e584cad4f8ff6 Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Wed, 2 Aug 2023 23:12:23 -0400 Subject: [PATCH 06/21] Fix deserializing `StyleType::Custom`. `StyleType::Custom` should be serialized to and deserialized from a TOML table. The `toml` crate doesn't seem to figure this out which causes saving and loading the settings to fail. I fixed this by hinting that the type should be a table using serde's attributes. --- src/configs/types/config_settings.rs | 3 ++- src/gui/styles/types/custom_styles.rs | 1 + src/gui/styles/types/style_type.rs | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/configs/types/config_settings.rs b/src/configs/types/config_settings.rs index 0f5533397..ebad75303 100644 --- a/src/configs/types/config_settings.rs +++ b/src/configs/types/config_settings.rs @@ -8,7 +8,8 @@ use crate::{Language, StyleType}; #[derive(Serialize, Deserialize, Default)] pub struct ConfigSettings { - pub style: StyleType, pub language: Language, pub notifications: Notifications, + // StyleType should be last in order to deserialize as a table properly + pub style: StyleType, } diff --git a/src/gui/styles/types/custom_styles.rs b/src/gui/styles/types/custom_styles.rs index 0511e8569..8ee60848d 100644 --- a/src/gui/styles/types/custom_styles.rs +++ b/src/gui/styles/types/custom_styles.rs @@ -30,6 +30,7 @@ pub struct PaletteExtension { /// Built in extra styles #[derive(Clone, Copy, Serialize, Deserialize, Debug, Hash, PartialEq)] +#[serde(tag = "custom")] pub enum ExtraStyles { Dracula, Gruvbox, diff --git a/src/gui/styles/types/style_type.rs b/src/gui/styles/types/style_type.rs index 40040fe33..acaf62b09 100644 --- a/src/gui/styles/types/style_type.rs +++ b/src/gui/styles/types/style_type.rs @@ -4,12 +4,13 @@ use super::custom_styles::ExtraStyles; /// Used to specify the kind of style of the application #[derive(Clone, Copy, Serialize, Deserialize, Debug, Hash, PartialEq)] +#[serde(tag = "style", content = "name")] pub enum StyleType { Night, Day, DeepSea, MonAmour, - Custom(ExtraStyles) + Custom(ExtraStyles), } impl Default for StyleType { From e1a1c7fead005837589c0a7e5195e61e8d656390 Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Fri, 4 Aug 2023 01:11:33 -0400 Subject: [PATCH 07/21] Add style Solarized light. --- src/gui/styles/types/custom_styles.rs | 12 ++++++++- .../styles/types/custom_styles/solarized.rs | 26 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/gui/styles/types/custom_styles/solarized.rs diff --git a/src/gui/styles/types/custom_styles.rs b/src/gui/styles/types/custom_styles.rs index 1904ac801..cfce72b7e 100644 --- a/src/gui/styles/types/custom_styles.rs +++ b/src/gui/styles/types/custom_styles.rs @@ -1,5 +1,6 @@ mod dracula; mod gruvbox; +mod solarized; use std::fmt; @@ -34,6 +35,7 @@ pub struct PaletteExtension { pub enum ExtraStyles { Dracula, Gruvbox, + SolarizedLight, } impl ExtraStyles { @@ -43,6 +45,7 @@ impl ExtraStyles { match self { ExtraStyles::Dracula => dracula::dracula().palette, ExtraStyles::Gruvbox => gruvbox::gruvbox_dark().palette, + ExtraStyles::SolarizedLight => solarized::solarized_light().palette, } } @@ -52,6 +55,7 @@ impl ExtraStyles { match self { ExtraStyles::Dracula => dracula::dracula().extension, ExtraStyles::Gruvbox => gruvbox::gruvbox_dark().extension, + ExtraStyles::SolarizedLight => solarized::solarized_light().extension, } } @@ -61,13 +65,18 @@ impl ExtraStyles { match self { ExtraStyles::Dracula => true, ExtraStyles::Gruvbox => true, + ExtraStyles::SolarizedLight => false, } } /// Slice of all implemented custom styles #[inline] pub const fn all_styles() -> &'static [Self] { - &[ExtraStyles::Dracula, ExtraStyles::Gruvbox] + &[ + ExtraStyles::Dracula, + ExtraStyles::Gruvbox, + ExtraStyles::SolarizedLight, + ] } } @@ -76,6 +85,7 @@ impl fmt::Display for ExtraStyles { match *self { ExtraStyles::Dracula => write!(f, "Dracula"), ExtraStyles::Gruvbox => write!(f, "Gruvbox (Dark)"), + ExtraStyles::SolarizedLight => write!(f, "Solarized (Light)"), } } } diff --git a/src/gui/styles/types/custom_styles/solarized.rs b/src/gui/styles/types/custom_styles/solarized.rs new file mode 100644 index 000000000..a65037876 --- /dev/null +++ b/src/gui/styles/types/custom_styles/solarized.rs @@ -0,0 +1,26 @@ +//! Solarized +//! https://ethanschoonover.com/solarized/ +use iced::color; + +use super::{CustomPalette, Palette, PaletteExtension}; + +pub(super) fn solarized_light() -> CustomPalette { + CustomPalette { + name: "Solarized light", + palette: Palette { + primary: color!(0xfdf6e3), // base3 + secondary: color!(0x859900), // green + outgoing: color!(0x268bd2), // blue + buttons: color!(0xeee8d5), // base2 + text_headers: color!(0xfdf6e3), // base3 + text_body: color!(0x93a1a1), // base1 + round_borders: color!(0xcb4b16), // orange + round_containers: color!(0xeee8d5), // base2 + }, + extension: PaletteExtension { + starred: color!(0xb58900), + badge_alpha: 0.75, + color_mixing: 0.3, + }, + } +} From 5386d87a62ca03f562db3376f4770b0898f12436 Mon Sep 17 00:00:00 2001 From: Giuliano Bellini s294739 Date: Fri, 4 Aug 2023 10:29:22 +0200 Subject: [PATCH 08/21] improvements to style settings page layout --- src/gui/pages/settings_style_page.rs | 63 ++++++++++++++++++---------- src/gui/styles/rule.rs | 5 ++- 2 files changed, 46 insertions(+), 22 deletions(-) diff --git a/src/gui/pages/settings_style_page.rs b/src/gui/pages/settings_style_page.rs index 7a2beb414..b558f0434 100644 --- a/src/gui/pages/settings_style_page.rs +++ b/src/gui/pages/settings_style_page.rs @@ -3,6 +3,7 @@ use iced::widget::{button, horizontal_space, vertical_space, Rule}; use iced::widget::{Button, Column, Container, Row, Scrollable, Space, Text}; use iced::Length::Fixed; use iced::{Alignment, Element, Length}; +use iced::widget::scrollable::Direction; use crate::gui::components::tab::get_settings_tabs; use crate::gui::pages::settings_notifications_page::settings_header; @@ -22,6 +23,7 @@ use crate::translations::translations::{ use crate::translations::translations_2::color_gradients_translation; use crate::StyleType::{Day, DeepSea, MonAmour, Night}; use crate::{Language, Sniffer, StyleType}; +use crate::gui::styles::scrollbar::{ScrollbarStyleTuple, ScrollbarType}; pub fn settings_style_page(sniffer: &Sniffer) -> Container { let font = get_font(sniffer.style); @@ -56,13 +58,17 @@ pub fn settings_style_page(sniffer: &Sniffer) -> Container { .font(font) .size(FONT_SIZE_SUBTITLE), ) - .push(vertical_space(Length::Fixed(10.0))) + .push(vertical_space(Length::Fixed(15.0))) .push(gradients_row( sniffer.style, sniffer.color_gradient, sniffer.language, )) - .push(vertical_space(Length::Fixed(10.0))) + .push(vertical_space(Length::Fixed(15.0))); + + let mut styles_col = Column::new() + .align_items(Alignment::Center) + .width(Length::Fill) .push( Row::new() .push(get_palette_container( @@ -95,14 +101,18 @@ pub fn settings_style_page(sniffer: &Sniffer) -> Container { mon_amour_translation(sniffer.language).to_string(), MonAmour, )), - ); - - // Append custom styles to official styles. - content = content.push(vertical_space(Length::Fixed(10.0))); - for style in get_extra_styles(ExtraStyles::all_styles()) { - content = content.push(style); + ) + .push(vertical_space(Length::Fixed(10.0))); + for style in get_extra_styles(ExtraStyles::all_styles(), sniffer.style) { + styles_col = styles_col.push(style); } - let content = Scrollable::new(content); + + let styles_scroll = Scrollable::new( +styles_col + ).direction(Direction::Vertical(ScrollbarType::properties())) + .style(ScrollbarStyleTuple(sniffer.style, ScrollbarType::Standard)); + + content = content.push(styles_scroll); Container::new(content) .height(Length::Fixed(400.0)) @@ -185,16 +195,25 @@ fn get_palette_container( on_press: StyleType, ) -> Button<'static, Message> { let font = get_font(style); - let content = Column::new() + + let is_custom = match on_press { + StyleType::Custom(_) => true, + _ => false + }; + + let mut content = Column::new() .width(Length::Fill) .align_items(Alignment::Center) .spacing(5) .push(Text::new(name).font(font)) - .push(get_palette(on_press)) - .push(Text::new(description).font(font)); + .push(get_palette(on_press, is_custom)); + + if !is_custom { + content=content.push(Text::new(description).font(font)) + } Button::new(content) - .height(Length::Fixed(110.0)) + .height(Length::Fixed(if is_custom {75.0} else { 110.0})) .width(Length::Fixed(380.0)) .padding(5) .style( @@ -211,27 +230,29 @@ fn get_palette_container( .on_press(Message::Style(on_press)) } -fn get_palette(style: StyleType) -> Container<'static, Message> { +fn get_palette(style: StyleType, is_custom: bool) -> Container<'static, Message> { + let height = if is_custom {25.0} else { 40.0 }; + Container::new( Row::new() .padding(0) .push(Row::new().padding(0).width(Length::Fixed(120.0)).push( - Rule::horizontal(40).style(>::into( + Rule::horizontal(height).style(>::into( RuleStyleTuple(style, RuleType::PalettePrimary), )), )) .push(Row::new().padding(0).width(Length::Fixed(80.0)).push( - Rule::horizontal(40).style(>::into( + Rule::horizontal(height).style(>::into( RuleStyleTuple(style, RuleType::PaletteSecondary), )), )) .push(Row::new().padding(0).width(Length::Fixed(60.0)).push( - Rule::horizontal(40).style(>::into( + Rule::horizontal(height).style(>::into( RuleStyleTuple(style, RuleType::PaletteOutgoing), )), )) .push(Row::new().padding(0).width(Length::Fixed(40.0)).push( - Rule::horizontal(40).style(>::into( + Rule::horizontal(height).style(>::into( RuleStyleTuple(style, RuleType::PaletteButtons), )), )), @@ -239,20 +260,20 @@ fn get_palette(style: StyleType) -> Container<'static, Message> { .align_x(Horizontal::Center) .align_y(Vertical::Center) .width(300.0 + 2.0 * BORDER_WIDTH) - .height(40.0 + 1.7 * BORDER_WIDTH) + .height(height + 1.7 * BORDER_WIDTH) .style(>::into( ContainerStyleTuple(style, ContainerType::Palette), )) } // Buttons for each extra style arranged in rows of two -fn get_extra_styles(styles: &[ExtraStyles]) -> Vec> { +fn get_extra_styles(styles: &[ExtraStyles], current_style: StyleType) -> Vec> { // Map each extra style into a palette container let mut styles = styles.iter().map(|&style| { let name = style.to_string(); let description = "".to_owned(); let style = StyleType::Custom(style); - get_palette_container(style, name, description, style) + get_palette_container(current_style, name, description, style) }); // The best way to do this would be with itertools, but that would introduce another dependency. diff --git a/src/gui/styles/rule.rs b/src/gui/styles/rule.rs index 78adb6774..8afe3bd28 100644 --- a/src/gui/styles/rule.rs +++ b/src/gui/styles/rule.rs @@ -43,7 +43,10 @@ impl rule::StyleSheet for RuleStyleTuple { RuleType::PalettePrimary | RuleType::PaletteSecondary | RuleType::PaletteOutgoing - | RuleType::PaletteButtons => 40, + | RuleType::PaletteButtons => match self.0 { + StyleType::Custom(_) => 25, + _ => 40 + }, RuleType::Standard => 3, }, radius: 0.0.into(), From dd3f5acec405d706adf967a40f31a3547c9d19a0 Mon Sep 17 00:00:00 2001 From: Giuliano Bellini s294739 Date: Fri, 4 Aug 2023 10:49:48 +0200 Subject: [PATCH 09/21] format files and fix lints --- src/gui/pages/settings_style_page.rs | 29 +++++++++---------- src/gui/styles/rule.rs | 2 +- src/gui/styles/types/custom_styles.rs | 7 ++--- src/gui/styles/types/custom_styles/dracula.rs | 4 ++- src/gui/styles/types/custom_styles/gruvbox.rs | 4 ++- .../styles/types/custom_styles/solarized.rs | 4 ++- src/gui/styles/types/palette.rs | 2 +- src/gui/styles/types/style_type.rs | 2 +- 8 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/gui/pages/settings_style_page.rs b/src/gui/pages/settings_style_page.rs index b558f0434..d310847d7 100644 --- a/src/gui/pages/settings_style_page.rs +++ b/src/gui/pages/settings_style_page.rs @@ -1,9 +1,9 @@ use iced::alignment::{Horizontal, Vertical}; +use iced::widget::scrollable::Direction; use iced::widget::{button, horizontal_space, vertical_space, Rule}; use iced::widget::{Button, Column, Container, Row, Scrollable, Space, Text}; use iced::Length::Fixed; use iced::{Alignment, Element, Length}; -use iced::widget::scrollable::Direction; use crate::gui::components::tab::get_settings_tabs; use crate::gui::pages::settings_notifications_page::settings_header; @@ -11,6 +11,7 @@ use crate::gui::pages::types::settings_page::SettingsPage; use crate::gui::styles::button::{ButtonStyleTuple, ButtonType}; use crate::gui::styles::container::{ContainerStyleTuple, ContainerType}; use crate::gui::styles::rule::{RuleStyleTuple, RuleType}; +use crate::gui::styles::scrollbar::{ScrollbarStyleTuple, ScrollbarType}; use crate::gui::styles::style_constants::{get_font, BORDER_WIDTH, FONT_SIZE_SUBTITLE, ICONS}; use crate::gui::styles::text::{TextStyleTuple, TextType}; use crate::gui::styles::types::custom_styles::ExtraStyles; @@ -23,7 +24,6 @@ use crate::translations::translations::{ use crate::translations::translations_2::color_gradients_translation; use crate::StyleType::{Day, DeepSea, MonAmour, Night}; use crate::{Language, Sniffer, StyleType}; -use crate::gui::styles::scrollbar::{ScrollbarStyleTuple, ScrollbarType}; pub fn settings_style_page(sniffer: &Sniffer) -> Container { let font = get_font(sniffer.style); @@ -66,7 +66,7 @@ pub fn settings_style_page(sniffer: &Sniffer) -> Container { )) .push(vertical_space(Length::Fixed(15.0))); - let mut styles_col = Column::new() + let mut styles_col = Column::new() .align_items(Alignment::Center) .width(Length::Fill) .push( @@ -107,9 +107,8 @@ pub fn settings_style_page(sniffer: &Sniffer) -> Container { styles_col = styles_col.push(style); } - let styles_scroll = Scrollable::new( -styles_col - ).direction(Direction::Vertical(ScrollbarType::properties())) + let styles_scroll = Scrollable::new(styles_col) + .direction(Direction::Vertical(ScrollbarType::properties())) .style(ScrollbarStyleTuple(sniffer.style, ScrollbarType::Standard)); content = content.push(styles_scroll); @@ -196,10 +195,7 @@ fn get_palette_container( ) -> Button<'static, Message> { let font = get_font(style); - let is_custom = match on_press { - StyleType::Custom(_) => true, - _ => false - }; + let is_custom = matches!(on_press, StyleType::Custom(_)); let mut content = Column::new() .width(Length::Fill) @@ -209,11 +205,11 @@ fn get_palette_container( .push(get_palette(on_press, is_custom)); if !is_custom { - content=content.push(Text::new(description).font(font)) + content = content.push(Text::new(description).font(font)); } Button::new(content) - .height(Length::Fixed(if is_custom {75.0} else { 110.0})) + .height(Length::Fixed(if is_custom { 75.0 } else { 110.0 })) .width(Length::Fixed(380.0)) .padding(5) .style( @@ -231,7 +227,7 @@ fn get_palette_container( } fn get_palette(style: StyleType, is_custom: bool) -> Container<'static, Message> { - let height = if is_custom {25.0} else { 40.0 }; + let height = if is_custom { 25.0 } else { 40.0 }; Container::new( Row::new() @@ -267,11 +263,14 @@ fn get_palette(style: StyleType, is_custom: bool) -> Container<'static, Message> } // Buttons for each extra style arranged in rows of two -fn get_extra_styles(styles: &[ExtraStyles], current_style: StyleType) -> Vec> { +fn get_extra_styles( + styles: &[ExtraStyles], + current_style: StyleType, +) -> Vec> { // Map each extra style into a palette container let mut styles = styles.iter().map(|&style| { let name = style.to_string(); - let description = "".to_owned(); + let description = String::new(); let style = StyleType::Custom(style); get_palette_container(current_style, name, description, style) }); diff --git a/src/gui/styles/rule.rs b/src/gui/styles/rule.rs index 8afe3bd28..aa5410cd6 100644 --- a/src/gui/styles/rule.rs +++ b/src/gui/styles/rule.rs @@ -45,7 +45,7 @@ impl rule::StyleSheet for RuleStyleTuple { | RuleType::PaletteOutgoing | RuleType::PaletteButtons => match self.0 { StyleType::Custom(_) => 25, - _ => 40 + _ => 40, }, RuleType::Standard => 3, }, diff --git a/src/gui/styles/types/custom_styles.rs b/src/gui/styles/types/custom_styles.rs index cfce72b7e..fa921951b 100644 --- a/src/gui/styles/types/custom_styles.rs +++ b/src/gui/styles/types/custom_styles.rs @@ -39,7 +39,7 @@ pub enum ExtraStyles { } impl ExtraStyles { - /// [Palette] of the [ExtraStyles] variant + /// [`Palette`] of the [`ExtraStyles`] variant #[inline] pub fn to_palette(self) -> Palette { match self { @@ -49,7 +49,7 @@ impl ExtraStyles { } } - /// Extension colors for the current [ExtraStyles] variant + /// Extension colors for the current [`ExtraStyles`] variant #[inline] pub fn to_ext(self) -> PaletteExtension { match self { @@ -63,8 +63,7 @@ impl ExtraStyles { #[inline] pub const fn is_nightly(self) -> bool { match self { - ExtraStyles::Dracula => true, - ExtraStyles::Gruvbox => true, + ExtraStyles::Dracula | ExtraStyles::Gruvbox => true, ExtraStyles::SolarizedLight => false, } } diff --git a/src/gui/styles/types/custom_styles/dracula.rs b/src/gui/styles/types/custom_styles/dracula.rs index c599fd81c..92720eb4c 100644 --- a/src/gui/styles/types/custom_styles/dracula.rs +++ b/src/gui/styles/types/custom_styles/dracula.rs @@ -1,5 +1,7 @@ +#![allow(clippy::unreadable_literal)] + //! Dracula theme -//! https://draculatheme.com/ +//! use iced::color; use super::{CustomPalette, Palette, PaletteExtension}; diff --git a/src/gui/styles/types/custom_styles/gruvbox.rs b/src/gui/styles/types/custom_styles/gruvbox.rs index 9c9ed7719..3931544e4 100644 --- a/src/gui/styles/types/custom_styles/gruvbox.rs +++ b/src/gui/styles/types/custom_styles/gruvbox.rs @@ -1,5 +1,7 @@ +#![allow(clippy::unreadable_literal)] + //! Gruvbox -//! https://github.com/morhetz/gruvbox +//! use iced::color; diff --git a/src/gui/styles/types/custom_styles/solarized.rs b/src/gui/styles/types/custom_styles/solarized.rs index a65037876..e004f3289 100644 --- a/src/gui/styles/types/custom_styles/solarized.rs +++ b/src/gui/styles/types/custom_styles/solarized.rs @@ -1,5 +1,7 @@ +#![allow(clippy::unreadable_literal)] + //! Solarized -//! https://ethanschoonover.com/solarized/ +//! use iced::color; use super::{CustomPalette, Palette, PaletteExtension}; diff --git a/src/gui/styles/types/palette.rs b/src/gui/styles/types/palette.rs index de5c8e4f2..dff3a48e2 100644 --- a/src/gui/styles/types/palette.rs +++ b/src/gui/styles/types/palette.rs @@ -41,7 +41,7 @@ pub fn get_colors(style: StyleType) -> Palette { StyleType::Day => DAY_STYLE, StyleType::DeepSea => DEEP_SEA_STYLE, StyleType::MonAmour => MON_AMOUR_STYLE, - StyleType::Custom(style) => style.to_palette() + 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 4a4ef06de..fe659c180 100644 --- a/src/gui/styles/types/style_type.rs +++ b/src/gui/styles/types/style_type.rs @@ -24,7 +24,7 @@ impl StyleType { match self { StyleType::Night | StyleType::DeepSea => true, StyleType::Day | StyleType::MonAmour => false, - StyleType::Custom(style) => style.is_nightly() + StyleType::Custom(style) => style.is_nightly(), } } } From 85a65966aab34813600667e264a8f028d81ac032 Mon Sep 17 00:00:00 2001 From: Giuliano Bellini s294739 Date: Fri, 4 Aug 2023 11:35:01 +0200 Subject: [PATCH 10/21] use StyleType::is_nightly to determine font weights --- src/chart/types/traffic_chart.rs | 55 +++++++++++++++---------------- src/gui/styles/style_constants.rs | 19 ++++++----- src/gui/types/sniffer.rs | 2 +- 3 files changed, 37 insertions(+), 39 deletions(-) diff --git a/src/chart/types/traffic_chart.rs b/src/chart/types/traffic_chart.rs index d4b46d73a..6cc246805 100644 --- a/src/chart/types/traffic_chart.rs +++ b/src/chart/types/traffic_chart.rs @@ -5,7 +5,6 @@ use std::collections::VecDeque; use iced::alignment::{Horizontal, Vertical}; use iced::widget::{Column, Container}; use iced::Element; -use plotters::style::RGBColor; use plotters_iced::{Chart, ChartBuilder, ChartWidget, DrawingBackend}; use crate::gui::styles::style_constants::{get_color_mix_chart, CHARTS_LINE_BORDER}; @@ -35,12 +34,12 @@ pub struct TrafficChart { pub min_sent_packets: i64, /// Minimum number of received packets per time interval (computed on last 30 intervals) pub max_received_packets: i64, - pub color_mix: f64, - pub color_incoming: RGBColor, - pub color_outgoing: RGBColor, - pub color_font: RGBColor, - pub chart_type: ChartType, + /// Language used for the chart legend pub language: Language, + /// Packets or bytes + pub chart_type: ChartType, + /// Style of the chart + pub style: StyleType, } impl TrafficChart { @@ -55,12 +54,9 @@ impl TrafficChart { max_received_bytes: 0, min_sent_packets: 0, max_received_packets: 0, - color_mix: get_color_mix_chart(style), - color_incoming: to_rgb_color(get_colors(style).secondary), - color_outgoing: to_rgb_color(get_colors(style).outgoing), - color_font: to_rgb_color(get_colors(style).text_body), - chart_type: ChartType::Bytes, language, + chart_type: ChartType::Bytes, + style, } } @@ -79,11 +75,8 @@ impl TrafficChart { self.language = language; } - pub fn change_colors(&mut self, style: StyleType) { - self.color_font = to_rgb_color(get_colors(style).text_body); - self.color_incoming = to_rgb_color(get_colors(style).secondary); - self.color_outgoing = to_rgb_color(get_colors(style).outgoing); - self.color_mix = get_color_mix_chart(style); + pub fn change_style(&mut self, style: StyleType) { + self.style = style; } } @@ -97,9 +90,10 @@ impl Chart for TrafficChart { ) { use plotters::prelude::*; - let font_weight = match self.color_font { - RGBColor(255, 255, 255) => FontStyle::Normal, // if white non-bold - _ => FontStyle::Bold, + let font_weight = if self.style.is_nightly() { + FontStyle::Normal + } else { + FontStyle::Bold }; if self.ticks == 0 { @@ -108,8 +102,11 @@ impl Chart for TrafficChart { let tot_seconds = self.ticks - 1; let first_time_displayed = if self.ticks > 30 { self.ticks - 30 } else { 0 }; - let color_incoming = self.color_incoming; - let color_outgoing = self.color_outgoing; + let colors = get_colors(self.style); + let color_incoming = to_rgb_color(colors.secondary); + let color_outgoing = to_rgb_color(colors.outgoing); + let color_font = to_rgb_color(colors.text_body); + let color_mix = get_color_mix_chart(self.style); chart_builder .margin_right(30) @@ -133,7 +130,7 @@ impl Chart for TrafficChart { ("Sarasa Mono SC", 12) .into_font() .style(font_weight) - .color(&self.color_font), + .color(&color_font), ) .y_labels(7) .y_label_formatter(&|bytes| { @@ -146,7 +143,7 @@ impl Chart for TrafficChart { AreaSeries::new( self.received_bytes.iter().copied(), 0, - color_incoming.mix(self.color_mix), + color_incoming.mix(color_mix), ) .border_style( ShapeStyle::from(&color_incoming).stroke_width(CHARTS_LINE_BORDER), @@ -162,7 +159,7 @@ impl Chart for TrafficChart { AreaSeries::new( self.sent_bytes.iter().copied(), 0, - color_outgoing.mix(self.color_mix), + color_outgoing.mix(color_mix), ) .border_style( ShapeStyle::from(&color_outgoing).stroke_width(CHARTS_LINE_BORDER), @@ -182,7 +179,7 @@ impl Chart for TrafficChart { ("Sarasa Mono SC", 13.5) .into_font() .style(font_weight) - .color(&self.color_font), + .color(&color_font), ) .draw() .expect("Error drawing graph"); @@ -203,7 +200,7 @@ impl Chart for TrafficChart { ("Sarasa Mono SC", 12) .into_font() .style(font_weight) - .color(&self.color_font), + .color(&color_font), ) .y_labels(7) .y_label_formatter(&|packets| packets.abs().to_string()) @@ -214,7 +211,7 @@ impl Chart for TrafficChart { AreaSeries::new( self.received_packets.iter().copied(), 0, - color_incoming.mix(self.color_mix), + color_incoming.mix(color_mix), ) .border_style( ShapeStyle::from(&color_incoming).stroke_width(CHARTS_LINE_BORDER), @@ -230,7 +227,7 @@ impl Chart for TrafficChart { AreaSeries::new( self.sent_packets.iter().copied(), 0, - color_outgoing.mix(self.color_mix), + color_outgoing.mix(color_mix), ) .border_style( ShapeStyle::from(&color_outgoing).stroke_width(CHARTS_LINE_BORDER), @@ -250,7 +247,7 @@ impl Chart for TrafficChart { ("Sarasa Mono SC", 13.5) .into_font() .style(font_weight) - .color(&self.color_font), + .color(&color_font), ) .draw() .expect("Error drawing graph"); diff --git a/src/gui/styles/style_constants.rs b/src/gui/styles/style_constants.rs index c6f6954be..08c9646cb 100644 --- a/src/gui/styles/style_constants.rs +++ b/src/gui/styles/style_constants.rs @@ -2,10 +2,9 @@ use iced::font::{Family, Stretch, Weight}; use iced::{Color, Font}; -use plotters::style::RGBColor; -use crate::gui::styles::types::palette::{to_rgb_color, Palette}; -use crate::{get_colors, StyleType}; +use crate::gui::styles::types::palette::Palette; +use crate::StyleType; // night theme const PRIMARY_NIGHT: Color = Color { @@ -177,16 +176,18 @@ pub const SARASA_MONO: Font = Font { }; pub fn get_font(style: StyleType) -> Font { - match to_rgb_color(get_colors(style).text_body) { - RGBColor(255, 255, 255) => SARASA_MONO, - _ => SARASA_MONO_BOLD, + if style.is_nightly() { + SARASA_MONO + } else { + SARASA_MONO_BOLD } } pub fn get_font_headers(style: StyleType) -> Font { - match to_rgb_color(get_colors(style).text_headers) { - RGBColor(255, 255, 255) => SARASA_MONO, - _ => SARASA_MONO_BOLD, + if style.is_nightly() { + SARASA_MONO_BOLD + } else { + SARASA_MONO } } diff --git a/src/gui/types/sniffer.rs b/src/gui/types/sniffer.rs index 3b33e7d8f..cd310a116 100644 --- a/src/gui/types/sniffer.rs +++ b/src/gui/types/sniffer.rs @@ -141,7 +141,7 @@ impl Sniffer { Message::Reset => return self.reset(), Message::Style(style) => { self.style = style; - self.traffic_chart.change_colors(self.style); + self.traffic_chart.change_style(self.style); } Message::Waiting => self.update_waiting_dots(), Message::AddOrRemoveFavorite(host, add) => self.add_or_remove_favorite(&host, add), From b165fcd97cc5a6ea1aed4e0ac6b3bcb23913edd6 Mon Sep 17 00:00:00 2001 From: Giuliano Bellini s294739 Date: Fri, 4 Aug 2023 11:41:17 +0200 Subject: [PATCH 11/21] fix tests --- src/chart/manage_chart_data.rs | 9 ++-- src/gui/types/sniffer.rs | 86 +--------------------------------- 2 files changed, 5 insertions(+), 90 deletions(-) diff --git a/src/chart/manage_chart_data.rs b/src/chart/manage_chart_data.rs index e8daf53a8..ccab59607 100644 --- a/src/chart/manage_chart_data.rs +++ b/src/chart/manage_chart_data.rs @@ -84,7 +84,7 @@ mod tests { use std::collections::VecDeque; use crate::chart::manage_chart_data::{get_max, get_min, update_charts_data}; - use crate::{ChartType, RunTimeData, TrafficChart}; + use crate::{ChartType, Language, RunTimeData, StyleType, TrafficChart}; #[test] fn test_chart_data_updates() { @@ -162,12 +162,9 @@ mod tests { max_received_bytes: 21000, min_sent_packets: -1000, max_received_packets: 21000, - color_mix: 0.0, - color_incoming: Default::default(), - color_outgoing: Default::default(), - color_font: Default::default(), + language: Language::default(), chart_type: ChartType::Packets, - language: Default::default(), + style: StyleType::default(), }; let mut runtime_data = RunTimeData { all_bytes: 0, diff --git a/src/gui/types/sniffer.rs b/src/gui/types/sniffer.rs index cd310a116..8a84c8c6e 100644 --- a/src/gui/types/sniffer.rs +++ b/src/gui/types/sniffer.rs @@ -522,8 +522,6 @@ mod tests { use crate::countries::types::country::Country; use crate::gui::components::types::my_modal::MyModal; use crate::gui::pages::types::settings_page::SettingsPage; - use crate::gui::styles::style_constants::get_color_mix_chart; - use crate::gui::styles::types::palette::to_rgb_color; use crate::gui::types::message::Message; use crate::networking::types::host::Host; use crate::notifications::types::logged_notification::{ @@ -534,8 +532,8 @@ mod tests { }; use crate::notifications::types::sound::Sound; use crate::{ - get_colors, AppProtocol, ByteMultiple, ChartType, InfoTraffic, IpVersion, Language, - ReportSortType, RunningPage, Sniffer, Status, StyleType, TransProtocol, + AppProtocol, ByteMultiple, ChartType, InfoTraffic, IpVersion, Language, ReportSortType, + RunningPage, Sniffer, Status, StyleType, TransProtocol, }; #[test] @@ -659,94 +657,14 @@ mod tests { sniffer.update(Message::Style(StyleType::MonAmour)); assert_eq!(sniffer.style, StyleType::MonAmour); - assert_eq!( - sniffer.traffic_chart.color_font, - to_rgb_color(get_colors(StyleType::MonAmour).text_body) - ); - assert_eq!( - sniffer.traffic_chart.color_outgoing, - to_rgb_color(get_colors(StyleType::MonAmour).outgoing) - ); - assert_eq!( - sniffer.traffic_chart.color_incoming, - to_rgb_color(get_colors(StyleType::MonAmour).secondary) - ); - assert_eq!( - sniffer.traffic_chart.color_mix, - get_color_mix_chart(StyleType::MonAmour) - ); sniffer.update(Message::Style(StyleType::Day)); assert_eq!(sniffer.style, StyleType::Day); - assert_eq!( - sniffer.traffic_chart.color_font, - to_rgb_color(get_colors(StyleType::Day).text_body) - ); - assert_eq!( - sniffer.traffic_chart.color_outgoing, - to_rgb_color(get_colors(StyleType::Day).outgoing) - ); - assert_eq!( - sniffer.traffic_chart.color_incoming, - to_rgb_color(get_colors(StyleType::Day).secondary) - ); - assert_eq!( - sniffer.traffic_chart.color_mix, - get_color_mix_chart(StyleType::Day) - ); sniffer.update(Message::Style(StyleType::Night)); assert_eq!(sniffer.style, StyleType::Night); - assert_eq!( - sniffer.traffic_chart.color_font, - to_rgb_color(get_colors(StyleType::Night).text_body) - ); - assert_eq!( - sniffer.traffic_chart.color_outgoing, - to_rgb_color(get_colors(StyleType::Night).outgoing) - ); - assert_eq!( - sniffer.traffic_chart.color_incoming, - to_rgb_color(get_colors(StyleType::Night).secondary) - ); - assert_eq!( - sniffer.traffic_chart.color_mix, - get_color_mix_chart(StyleType::Night) - ); sniffer.update(Message::Style(StyleType::DeepSea)); assert_eq!(sniffer.style, StyleType::DeepSea); - assert_eq!( - sniffer.traffic_chart.color_font, - to_rgb_color(get_colors(StyleType::DeepSea).text_body) - ); - assert_eq!( - sniffer.traffic_chart.color_outgoing, - to_rgb_color(get_colors(StyleType::DeepSea).outgoing) - ); - assert_eq!( - sniffer.traffic_chart.color_incoming, - to_rgb_color(get_colors(StyleType::DeepSea).secondary) - ); - assert_eq!( - sniffer.traffic_chart.color_mix, - get_color_mix_chart(StyleType::DeepSea) - ); sniffer.update(Message::Style(StyleType::DeepSea)); assert_eq!(sniffer.style, StyleType::DeepSea); - assert_eq!( - sniffer.traffic_chart.color_font, - to_rgb_color(get_colors(StyleType::DeepSea).text_body) - ); - assert_eq!( - sniffer.traffic_chart.color_outgoing, - to_rgb_color(get_colors(StyleType::DeepSea).outgoing) - ); - assert_eq!( - sniffer.traffic_chart.color_incoming, - to_rgb_color(get_colors(StyleType::DeepSea).secondary) - ); - assert_eq!( - sniffer.traffic_chart.color_mix, - get_color_mix_chart(StyleType::DeepSea) - ); } #[test] From 306c46d38138e41a288f334412bf32f3afbe4f18 Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Fri, 4 Aug 2023 22:53:14 -0400 Subject: [PATCH 12/21] Add style Solarized dark. --- src/gui/styles/types/custom_styles.rs | 13 ++++++---- src/gui/styles/types/custom_styles/dracula.rs | 1 - src/gui/styles/types/custom_styles/gruvbox.rs | 2 +- .../styles/types/custom_styles/solarized.rs | 25 +++++++++++++++++-- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/gui/styles/types/custom_styles.rs b/src/gui/styles/types/custom_styles.rs index fa921951b..c6af72ee2 100644 --- a/src/gui/styles/types/custom_styles.rs +++ b/src/gui/styles/types/custom_styles.rs @@ -11,8 +11,6 @@ use super::palette::Palette; /// Custom style with any relevant metadata pub struct CustomPalette { - /// Displayable name of the style (i.e. "Catppuccin (Mocha)") - name: &'static str, /// Color scheme's palette palette: Palette, /// Extra colors such as the favorites star @@ -35,6 +33,7 @@ pub struct PaletteExtension { pub enum ExtraStyles { Dracula, Gruvbox, + SolarizedDark, SolarizedLight, } @@ -45,6 +44,7 @@ impl ExtraStyles { match self { ExtraStyles::Dracula => dracula::dracula().palette, ExtraStyles::Gruvbox => gruvbox::gruvbox_dark().palette, + ExtraStyles::SolarizedDark => solarized::solarized_dark().palette, ExtraStyles::SolarizedLight => solarized::solarized_light().palette, } } @@ -55,6 +55,7 @@ impl ExtraStyles { match self { ExtraStyles::Dracula => dracula::dracula().extension, ExtraStyles::Gruvbox => gruvbox::gruvbox_dark().extension, + ExtraStyles::SolarizedDark => solarized::solarized_dark().extension, ExtraStyles::SolarizedLight => solarized::solarized_light().extension, } } @@ -63,7 +64,7 @@ impl ExtraStyles { #[inline] pub const fn is_nightly(self) -> bool { match self { - ExtraStyles::Dracula | ExtraStyles::Gruvbox => true, + ExtraStyles::Dracula | ExtraStyles::Gruvbox | ExtraStyles::SolarizedDark => true, ExtraStyles::SolarizedLight => false, } } @@ -74,6 +75,7 @@ impl ExtraStyles { &[ ExtraStyles::Dracula, ExtraStyles::Gruvbox, + ExtraStyles::SolarizedDark, ExtraStyles::SolarizedLight, ] } @@ -83,8 +85,9 @@ impl fmt::Display for ExtraStyles { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { ExtraStyles::Dracula => write!(f, "Dracula"), - ExtraStyles::Gruvbox => write!(f, "Gruvbox (Dark)"), - ExtraStyles::SolarizedLight => write!(f, "Solarized (Light)"), + ExtraStyles::Gruvbox => write!(f, "Gruvbox (Night)"), + ExtraStyles::SolarizedLight => write!(f, "Solarized (Day)"), + ExtraStyles::SolarizedDark => write!(f, "Solarized (Night)"), } } } diff --git a/src/gui/styles/types/custom_styles/dracula.rs b/src/gui/styles/types/custom_styles/dracula.rs index 92720eb4c..00996d6b8 100644 --- a/src/gui/styles/types/custom_styles/dracula.rs +++ b/src/gui/styles/types/custom_styles/dracula.rs @@ -8,7 +8,6 @@ use super::{CustomPalette, Palette, PaletteExtension}; pub(super) fn dracula() -> CustomPalette { CustomPalette { - name: "Dracula", palette: Palette { primary: color!(0x44475a), // Current line secondary: color!(0xff79c6), // Pink diff --git a/src/gui/styles/types/custom_styles/gruvbox.rs b/src/gui/styles/types/custom_styles/gruvbox.rs index 3931544e4..f362257d8 100644 --- a/src/gui/styles/types/custom_styles/gruvbox.rs +++ b/src/gui/styles/types/custom_styles/gruvbox.rs @@ -7,9 +7,9 @@ use iced::color; use super::{CustomPalette, Palette, PaletteExtension}; +/// Gruvbox (night style) pub(super) fn gruvbox_dark() -> CustomPalette { CustomPalette { - name: "Gruvbox (Dark)", palette: Palette { primary: color!(0x282828), // bg secondary: color!(0xfe8019), // orange diff --git a/src/gui/styles/types/custom_styles/solarized.rs b/src/gui/styles/types/custom_styles/solarized.rs index e004f3289..2f3e33488 100644 --- a/src/gui/styles/types/custom_styles/solarized.rs +++ b/src/gui/styles/types/custom_styles/solarized.rs @@ -6,9 +6,9 @@ use iced::color; use super::{CustomPalette, Palette, PaletteExtension}; +/// Solarized light (Day style) pub(super) fn solarized_light() -> CustomPalette { CustomPalette { - name: "Solarized light", palette: Palette { primary: color!(0xfdf6e3), // base3 secondary: color!(0x859900), // green @@ -20,7 +20,28 @@ pub(super) fn solarized_light() -> CustomPalette { round_containers: color!(0xeee8d5), // base2 }, extension: PaletteExtension { - starred: color!(0xb58900), + starred: color!(0xb58900), // yellow + badge_alpha: 0.75, + color_mixing: 0.8, + }, + } +} + +/// Solarized dark (Night style) +pub(super) fn solarized_dark() -> CustomPalette { + CustomPalette { + palette: Palette { + primary: color!(0x002b36), // base03 + secondary: color!(0x859900), // green + outgoing: color!(0x268bd2), // blue + buttons: color!(0x586e75), // base02 + text_headers: color!(0x002b36), // base03 + text_body: color!(0x839496), // base0 + round_borders: color!(0xcb4b16), // orange + round_containers: color!(0x586e75), // base2 + }, + extension: PaletteExtension { + starred: color!(0xb58900), // yellow badge_alpha: 0.75, color_mixing: 0.3, }, From d67717107ef9d2e766294cbc83fe841814ab195b Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Sat, 5 Aug 2023 01:26:40 -0400 Subject: [PATCH 13/21] Add Nord and update solarized. --- src/gui/styles/types/custom_styles.rs | 11 +++++++- src/gui/styles/types/custom_styles/nord.rs | 27 +++++++++++++++++++ .../styles/types/custom_styles/solarized.rs | 4 +-- 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 src/gui/styles/types/custom_styles/nord.rs diff --git a/src/gui/styles/types/custom_styles.rs b/src/gui/styles/types/custom_styles.rs index c6af72ee2..c6c249b79 100644 --- a/src/gui/styles/types/custom_styles.rs +++ b/src/gui/styles/types/custom_styles.rs @@ -1,5 +1,6 @@ mod dracula; mod gruvbox; +mod nord; mod solarized; use std::fmt; @@ -33,6 +34,7 @@ pub struct PaletteExtension { pub enum ExtraStyles { Dracula, Gruvbox, + Nord, SolarizedDark, SolarizedLight, } @@ -44,6 +46,7 @@ impl ExtraStyles { match self { ExtraStyles::Dracula => dracula::dracula().palette, ExtraStyles::Gruvbox => gruvbox::gruvbox_dark().palette, + ExtraStyles::Nord => nord::nord().palette, ExtraStyles::SolarizedDark => solarized::solarized_dark().palette, ExtraStyles::SolarizedLight => solarized::solarized_light().palette, } @@ -55,6 +58,7 @@ impl ExtraStyles { match self { ExtraStyles::Dracula => dracula::dracula().extension, ExtraStyles::Gruvbox => gruvbox::gruvbox_dark().extension, + ExtraStyles::Nord => nord::nord().extension, ExtraStyles::SolarizedDark => solarized::solarized_dark().extension, ExtraStyles::SolarizedLight => solarized::solarized_light().extension, } @@ -64,7 +68,10 @@ impl ExtraStyles { #[inline] pub const fn is_nightly(self) -> bool { match self { - ExtraStyles::Dracula | ExtraStyles::Gruvbox | ExtraStyles::SolarizedDark => true, + ExtraStyles::Dracula + | ExtraStyles::Gruvbox + | ExtraStyles::Nord + | ExtraStyles::SolarizedDark => true, ExtraStyles::SolarizedLight => false, } } @@ -75,6 +82,7 @@ impl ExtraStyles { &[ ExtraStyles::Dracula, ExtraStyles::Gruvbox, + ExtraStyles::Nord, ExtraStyles::SolarizedDark, ExtraStyles::SolarizedLight, ] @@ -86,6 +94,7 @@ impl fmt::Display for ExtraStyles { match *self { ExtraStyles::Dracula => write!(f, "Dracula"), ExtraStyles::Gruvbox => write!(f, "Gruvbox (Night)"), + ExtraStyles::Nord => write!(f, "Nord"), ExtraStyles::SolarizedLight => write!(f, "Solarized (Day)"), ExtraStyles::SolarizedDark => write!(f, "Solarized (Night)"), } diff --git a/src/gui/styles/types/custom_styles/nord.rs b/src/gui/styles/types/custom_styles/nord.rs new file mode 100644 index 000000000..074c8948a --- /dev/null +++ b/src/gui/styles/types/custom_styles/nord.rs @@ -0,0 +1,27 @@ +#![allow(clippy::unreadable_literal)] + +//! Nord theme +//! https://www.nordtheme.com/docs/colors-and-palettes +use iced::color; + +use super::{CustomPalette, Palette, PaletteExtension}; + +pub(super) fn nord() -> CustomPalette { + CustomPalette { + palette: Palette { + primary: color!(0x2e3440), // nord0 + secondary: color!(0x88c0d0), // nord8 + outgoing: color!(0x81a1c1), // nord9 + buttons: color!(0x3b4252), // nord1 + text_headers: color!(0x4c566a), // nord3 + text_body: color!(0xd8dee9), // nord4 + round_borders: color!(0xe5e9f0), // nord5 + round_containers: color!(0x434c5e), // nord2 + }, + extension: PaletteExtension { + starred: color!(0xebcb8b), // nord13 + badge_alpha: 0.75, + color_mixing: 0.3, + }, + } +} diff --git a/src/gui/styles/types/custom_styles/solarized.rs b/src/gui/styles/types/custom_styles/solarized.rs index 2f3e33488..eebc5f4a8 100644 --- a/src/gui/styles/types/custom_styles/solarized.rs +++ b/src/gui/styles/types/custom_styles/solarized.rs @@ -34,11 +34,11 @@ pub(super) fn solarized_dark() -> CustomPalette { primary: color!(0x002b36), // base03 secondary: color!(0x859900), // green outgoing: color!(0x268bd2), // blue - buttons: color!(0x586e75), // base02 + buttons: color!(0x073642), // base02 text_headers: color!(0x002b36), // base03 text_body: color!(0x839496), // base0 round_borders: color!(0xcb4b16), // orange - round_containers: color!(0x586e75), // base2 + round_containers: color!(0x073642), // base2 }, extension: PaletteExtension { starred: color!(0xb58900), // yellow From 2a4ca7f86983b3215222dd5262dbd12392cbca6a Mon Sep 17 00:00:00 2001 From: Giuliano Bellini s294739 Date: Sat, 5 Aug 2023 13:57:45 +0200 Subject: [PATCH 14/21] improvements to overall palettes structure and colors --- src/chart/types/traffic_chart.rs | 12 ++-- src/gui/styles/button.rs | 27 +++++--- src/gui/styles/container.rs | 17 +++-- src/gui/styles/picklist.rs | 8 ++- src/gui/styles/rule.rs | 7 ++- src/gui/styles/scrollbar.rs | 22 +++++-- src/gui/styles/style_constants.rs | 63 ++++++------------- src/gui/styles/text_input.rs | 6 +- src/gui/styles/types/custom_styles.rs | 8 ++- src/gui/styles/types/custom_styles/dracula.rs | 21 +++---- src/gui/styles/types/custom_styles/gruvbox.rs | 21 +++---- src/gui/styles/types/custom_styles/nord.rs | 21 +++---- .../styles/types/custom_styles/solarized.rs | 40 ++++++------ src/gui/styles/types/palette.rs | 4 -- 14 files changed, 144 insertions(+), 133 deletions(-) diff --git a/src/chart/types/traffic_chart.rs b/src/chart/types/traffic_chart.rs index 6cc246805..d7d17c1ee 100644 --- a/src/chart/types/traffic_chart.rs +++ b/src/chart/types/traffic_chart.rs @@ -7,7 +7,7 @@ use iced::widget::{Column, Container}; use iced::Element; use plotters_iced::{Chart, ChartBuilder, ChartWidget, DrawingBackend}; -use crate::gui::styles::style_constants::{get_color_mix_chart, CHARTS_LINE_BORDER}; +use crate::gui::styles::style_constants::{get_alpha_chart_badge, CHARTS_LINE_BORDER}; use crate::gui::styles::types::palette::to_rgb_color; use crate::gui::types::message::Message; use crate::translations::translations::{incoming_translation, outgoing_translation}; @@ -106,7 +106,7 @@ impl Chart for TrafficChart { let color_incoming = to_rgb_color(colors.secondary); let color_outgoing = to_rgb_color(colors.outgoing); let color_font = to_rgb_color(colors.text_body); - let color_mix = get_color_mix_chart(self.style); + let color_mix = get_alpha_chart_badge(self.style); chart_builder .margin_right(30) @@ -143,7 +143,7 @@ impl Chart for TrafficChart { AreaSeries::new( self.received_bytes.iter().copied(), 0, - color_incoming.mix(color_mix), + color_incoming.mix(color_mix.into()), ) .border_style( ShapeStyle::from(&color_incoming).stroke_width(CHARTS_LINE_BORDER), @@ -159,7 +159,7 @@ impl Chart for TrafficChart { AreaSeries::new( self.sent_bytes.iter().copied(), 0, - color_outgoing.mix(color_mix), + color_outgoing.mix(color_mix.into()), ) .border_style( ShapeStyle::from(&color_outgoing).stroke_width(CHARTS_LINE_BORDER), @@ -211,7 +211,7 @@ impl Chart for TrafficChart { AreaSeries::new( self.received_packets.iter().copied(), 0, - color_incoming.mix(color_mix), + color_incoming.mix(color_mix.into()), ) .border_style( ShapeStyle::from(&color_incoming).stroke_width(CHARTS_LINE_BORDER), @@ -227,7 +227,7 @@ impl Chart for TrafficChart { AreaSeries::new( self.sent_packets.iter().copied(), 0, - color_outgoing.mix(color_mix), + color_outgoing.mix(color_mix.into()), ) .border_style( ShapeStyle::from(&color_outgoing).stroke_width(CHARTS_LINE_BORDER), diff --git a/src/gui/styles/button.rs b/src/gui/styles/button.rs index f694efaf2..e274fecc2 100644 --- a/src/gui/styles/button.rs +++ b/src/gui/styles/button.rs @@ -4,7 +4,10 @@ use iced::widget::button; use iced::widget::button::Appearance; use iced::{Background, Color, Vector}; -use crate::gui::styles::style_constants::{get_starred_color, BORDER_BUTTON_RADIUS, BORDER_WIDTH}; +use crate::gui::styles::style_constants::{ + get_alpha_round_borders, get_alpha_round_containers, get_starred_color, BORDER_BUTTON_RADIUS, + BORDER_WIDTH, +}; use crate::gui::styles::types::gradient_type::{ get_gradient_buttons, get_gradient_hovered_buttons, GradientType, }; @@ -42,14 +45,17 @@ impl button::StyleSheet for ButtonStyleTuple { let colors = get_colors(self.0); button::Appearance { background: Some(match self { - ButtonStyleTuple(_, ButtonType::TabActive) => Background::Color(colors.primary), + ButtonStyleTuple(_, ButtonType::TabActive) => { + Background::Color(mix_colors(colors.primary, colors.buttons)) + } ButtonStyleTuple(_, ButtonType::Starred) => { Background::Color(get_starred_color(self.0)) } ButtonStyleTuple(_, ButtonType::Badge) => Background::Color(colors.secondary), - ButtonStyleTuple(_, ButtonType::BorderedRound) => { - Background::Color(colors.round_containers) - } + ButtonStyleTuple(_, ButtonType::BorderedRound) => Background::Color(Color { + a: get_alpha_round_containers(self.0), + ..colors.buttons + }), ButtonStyleTuple(_, ButtonType::Neutral | ButtonType::NotStarred) => { Background::Color(Color::TRANSPARENT) } @@ -102,7 +108,10 @@ impl button::StyleSheet for ButtonStyleTuple { }, border_color: match self { ButtonStyleTuple(_, ButtonType::Alert) => Color::new(0.8, 0.15, 0.15, 1.0), - ButtonStyleTuple(_, ButtonType::BorderedRound) => colors.round_borders, + ButtonStyleTuple(_, ButtonType::BorderedRound) => Color { + a: get_alpha_round_borders(self.0), + ..colors.buttons + }, _ => colors.secondary, }, } @@ -120,7 +129,6 @@ impl button::StyleSheet for ButtonStyleTuple { ButtonStyleTuple(_, ButtonType::Starred) => { Background::Color(get_starred_color(self.0)) } - ButtonStyleTuple(_, ButtonType::TabActive) => Background::Color(colors.primary), ButtonStyleTuple(_, ButtonType::Gradient(GradientType::None)) => { Background::Color(mix_colors(colors.primary, colors.secondary)) } @@ -156,7 +164,10 @@ impl button::StyleSheet for ButtonStyleTuple { ButtonStyleTuple( _, ButtonType::BorderedRound | ButtonType::Neutral | ButtonType::NotStarred, - ) => colors.round_borders, + ) => Color { + a: get_alpha_round_borders(self.0), + ..colors.buttons + }, _ => colors.secondary, }, text_color: match self { diff --git a/src/gui/styles/container.rs b/src/gui/styles/container.rs index 9a29203df..e3233cd50 100644 --- a/src/gui/styles/container.rs +++ b/src/gui/styles/container.rs @@ -5,7 +5,8 @@ use iced::Theme; use iced::{Background, Color}; use crate::gui::styles::style_constants::{ - get_color_mix_filter_badge, BORDER_ROUNDED_RADIUS, BORDER_WIDTH, + get_alpha_chart_badge, get_alpha_round_borders, get_alpha_round_containers, + BORDER_ROUNDED_RADIUS, BORDER_WIDTH, }; use crate::gui::styles::types::gradient_type::{get_gradient_headers, GradientType}; use crate::{get_colors, StyleType}; @@ -49,14 +50,15 @@ impl iced::widget::container::StyleSheet for ContainerStyleTuple { Background::Color(colors.secondary) } ContainerStyleTuple(_, ContainerType::Tooltip) => Background::Color(colors.buttons), - ContainerStyleTuple(_, ContainerType::BorderedRound) => { - Background::Color(colors.round_containers) - } + ContainerStyleTuple(_, ContainerType::BorderedRound) => Background::Color(Color { + a: get_alpha_round_containers(self.0), + ..colors.buttons + }), ContainerStyleTuple(_, ContainerType::Neutral | ContainerType::Palette) => { Background::Color(Color::TRANSPARENT) } ContainerStyleTuple(_, ContainerType::Badge) => Background::Color(Color { - a: get_color_mix_filter_badge(self.0), + a: get_alpha_chart_badge(self.0), ..colors.secondary }), ContainerStyleTuple(_, ContainerType::Gradient(gradient_type)) => { @@ -94,7 +96,10 @@ impl iced::widget::container::StyleSheet for ContainerStyleTuple { border_color: match self { ContainerStyleTuple(_, ContainerType::Alert) => Color::new(1.0, 0.0, 0.0, 1.0), ContainerStyleTuple(_, ContainerType::Palette) => Color::BLACK, - _ => colors.round_borders, + _ => Color { + a: get_alpha_round_borders(self.0), + ..colors.buttons + }, }, } } diff --git a/src/gui/styles/picklist.rs b/src/gui/styles/picklist.rs index 646b289e3..956181de5 100644 --- a/src/gui/styles/picklist.rs +++ b/src/gui/styles/picklist.rs @@ -3,8 +3,9 @@ use std::rc::Rc; use iced::widget::pick_list; -use iced::Background; +use iced::{Background, Color}; +use crate::gui::styles::style_constants::get_alpha_round_borders; use crate::gui::styles::types::palette::mix_colors; use crate::{get_colors, StyleType}; @@ -51,7 +52,10 @@ impl pick_list::StyleSheet for PicklistStyleTuple { background: Background::Color(colors.buttons), border_radius: 0.0.into(), border_width: 1.0, - border_color: colors.round_borders, + border_color: Color { + a: get_alpha_round_borders(self.0), + ..colors.buttons + }, } } diff --git a/src/gui/styles/rule.rs b/src/gui/styles/rule.rs index aa5410cd6..963b7f117 100644 --- a/src/gui/styles/rule.rs +++ b/src/gui/styles/rule.rs @@ -2,7 +2,9 @@ use iced::widget::rule; use iced::widget::rule::FillMode; +use iced::Color; +use crate::gui::styles::style_constants::get_alpha_round_borders; use crate::{get_colors, StyleType}; #[derive(Clone, Copy)] @@ -36,7 +38,10 @@ impl rule::StyleSheet for RuleStyleTuple { RuleType::Outgoing | RuleType::PaletteOutgoing => colors.outgoing, RuleType::PalettePrimary => colors.primary, RuleType::PaletteButtons => colors.buttons, - RuleType::Standard => colors.round_borders, + RuleType::Standard => Color { + a: get_alpha_round_borders(self.0), + ..colors.buttons + }, }, width: match self.1 { RuleType::Incoming | RuleType::Outgoing => 5, diff --git a/src/gui/styles/scrollbar.rs b/src/gui/styles/scrollbar.rs index bcfdf84f1..19dc64aff 100644 --- a/src/gui/styles/scrollbar.rs +++ b/src/gui/styles/scrollbar.rs @@ -5,7 +5,7 @@ use iced::widget::scrollable::{Scrollbar, Scroller}; use iced::Theme; use iced::{Background, Color}; -use crate::gui::styles::style_constants::BORDER_ROUNDED_RADIUS; +use crate::gui::styles::style_constants::{get_alpha_round_borders, BORDER_ROUNDED_RADIUS}; use crate::gui::styles::types::palette::mix_colors; use crate::{get_colors, StyleType}; @@ -38,9 +38,15 @@ impl iced::widget::scrollable::StyleSheet for ScrollbarStyleTuple { background: Some(Background::Color(Color::TRANSPARENT)), border_radius: BORDER_ROUNDED_RADIUS.into(), border_width: 0.0, - border_color: colors.round_borders, + border_color: Color { + a: get_alpha_round_borders(self.0), + ..colors.buttons + }, scroller: Scroller { - color: colors.round_borders, + color: Color { + a: get_alpha_round_borders(self.0), + ..colors.buttons + }, border_radius: BORDER_ROUNDED_RADIUS.into(), border_width: 0.0, border_color: Color::TRANSPARENT, @@ -51,10 +57,16 @@ impl iced::widget::scrollable::StyleSheet for ScrollbarStyleTuple { fn hovered(&self, _: &Self::Style, is_mouse_over_scrollbar: bool) -> Scrollbar { let colors = get_colors(self.0); Scrollbar { - background: Some(Background::Color(colors.round_borders)), + background: Some(Background::Color(Color { + a: get_alpha_round_borders(self.0), + ..colors.buttons + })), border_radius: BORDER_ROUNDED_RADIUS.into(), border_width: 0.0, - border_color: colors.round_borders, + border_color: Color { + a: get_alpha_round_borders(self.0), + ..colors.buttons + }, scroller: Scroller { color: if is_mouse_over_scrollbar { colors.secondary diff --git a/src/gui/styles/style_constants.rs b/src/gui/styles/style_constants.rs index 08c9646cb..70d5e0ad9 100644 --- a/src/gui/styles/style_constants.rs +++ b/src/gui/styles/style_constants.rs @@ -32,14 +32,6 @@ pub const NIGHT_STYLE: Palette = Palette { outgoing: SECONDARY_DAY, text_headers: Color::BLACK, text_body: Color::WHITE, - round_borders: Color { - a: 0.3, - ..Color::BLACK - }, - round_containers: Color { - a: 0.2, - ..Color::BLACK - }, }; // day theme @@ -63,14 +55,6 @@ pub const DAY_STYLE: Palette = Palette { outgoing: SECONDARY_NIGHT, text_headers: Color::WHITE, text_body: Color::BLACK, - round_borders: Color { - a: 0.25, - ..Color::BLACK - }, - round_containers: Color { - a: 0.1, - ..Color::BLACK - }, }; // deep sea theme @@ -105,14 +89,6 @@ pub const DEEP_SEA_STYLE: Palette = Palette { outgoing: OUTGOING_DEEP_SEA, text_headers: Color::BLACK, text_body: Color::WHITE, - round_borders: Color { - a: 0.1, - ..SECONDARY_DEEP_SEA - }, - round_containers: Color { - a: 0.03, - ..SECONDARY_DEEP_SEA - }, }; // mon amour theme @@ -147,14 +123,6 @@ pub const MON_AMOUR_STYLE: Palette = Palette { outgoing: OUTGOING_MON_AMOUR, text_headers: Color::WHITE, text_body: Color::BLACK, - round_borders: Color { - a: 0.6, - ..BUTTONS_MON_AMOUR - }, - round_containers: Color { - a: 0.3, - ..BUTTONS_MON_AMOUR - }, }; pub const SARASA_MONO_BOLD_BYTES: &[u8] = @@ -191,14 +159,6 @@ pub fn get_font_headers(style: StyleType) -> Font { } } -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, - } -} - //font to display icons pub const ICONS_BYTES: &[u8] = include_bytes!("../../../resources/fonts/subset/icons.ttf"); pub const ICONS: Font = Font::with_name("Glyphter"); @@ -234,11 +194,28 @@ pub fn get_starred_color(style: StyleType) -> Color { } } -pub fn get_color_mix_filter_badge(style: StyleType) -> f32 { +pub fn get_alpha_chart_badge(style: StyleType) -> f32 { match style { StyleType::Night | StyleType::DeepSea => 0.2, - StyleType::Day => 0.7, + StyleType::Day | StyleType::MonAmour => 0.8, + StyleType::Custom(style) => style.to_ext().chart_badge_alpha, + } +} + +pub fn get_alpha_round_borders(style: StyleType) -> f32 { + match style { + StyleType::Night | StyleType::DeepSea => 0.35, + StyleType::Day => 0.45, StyleType::MonAmour => 0.5, - StyleType::Custom(style) => style.to_ext().badge_alpha, + StyleType::Custom(style) => style.to_ext().round_borders_alpha, + } +} + +pub fn get_alpha_round_containers(style: StyleType) -> f32 { + match style { + StyleType::Night | StyleType::MonAmour => 0.25, + StyleType::Day => 0.2, + StyleType::DeepSea => 0.15, + StyleType::Custom(style) => style.to_ext().round_containers_alpha, } } diff --git a/src/gui/styles/text_input.rs b/src/gui/styles/text_input.rs index 4b87c72fb..aa15a8f7e 100644 --- a/src/gui/styles/text_input.rs +++ b/src/gui/styles/text_input.rs @@ -4,6 +4,7 @@ use iced::widget::text_input; use iced::widget::text_input::Appearance; use iced::{Background, Color}; +use crate::gui::styles::style_constants::get_alpha_round_borders; use crate::{get_colors, StyleType}; #[derive(Clone, Copy)] @@ -35,7 +36,10 @@ impl iced::widget::text_input::StyleSheet for TextInputStyleTuple { border_width: 1.0, border_color: match self.1 { TextInputType::Badge => Color::TRANSPARENT, - TextInputType::Standard => colors.round_borders, + TextInputType::Standard => Color { + a: get_alpha_round_borders(self.0), + ..colors.buttons + }, }, icon_color: colors.text_body, } diff --git a/src/gui/styles/types/custom_styles.rs b/src/gui/styles/types/custom_styles.rs index c6c249b79..96d0e0699 100644 --- a/src/gui/styles/types/custom_styles.rs +++ b/src/gui/styles/types/custom_styles.rs @@ -23,9 +23,11 @@ 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 chart_badge_alpha: f32, + /// Round borders alpha + pub round_borders_alpha: f32, + /// Round containers alpha + pub round_containers_alpha: f32, } /// Built in extra styles diff --git a/src/gui/styles/types/custom_styles/dracula.rs b/src/gui/styles/types/custom_styles/dracula.rs index 00996d6b8..d1f7a504e 100644 --- a/src/gui/styles/types/custom_styles/dracula.rs +++ b/src/gui/styles/types/custom_styles/dracula.rs @@ -9,19 +9,18 @@ use super::{CustomPalette, Palette, PaletteExtension}; pub(super) fn dracula() -> CustomPalette { CustomPalette { palette: Palette { - primary: color!(0x44475a), // Current line - secondary: color!(0xff79c6), // Pink - outgoing: color!(0x8be9fd), // Cyan - buttons: color!(0x6272a4), // Comments - text_headers: color!(0x44475a), // Current line - text_body: color!(0xf8f8f2), // Foreground - round_borders: color!(0xbd93f9), // Purple - round_containers: color!(0x44475a), // Current line + primary: color!(0x282a36), // Backgorund + secondary: color!(0xff79c6), // Pink + outgoing: color!(0x8be9fd), // Cyan + buttons: color!(0x6272a4), // Comments + text_headers: color!(0x282a36), // Background + text_body: color!(0xf8f8f2), // Foreground }, extension: PaletteExtension { - starred: color!(0xf1fa8c), - badge_alpha: 0.75, - color_mixing: 0.3, + starred: color!(0xf1fa8c, 0.7), + round_borders_alpha: 0.1, + round_containers_alpha: 0.04, + chart_badge_alpha: 0.15, }, } } diff --git a/src/gui/styles/types/custom_styles/gruvbox.rs b/src/gui/styles/types/custom_styles/gruvbox.rs index f362257d8..f111248cf 100644 --- a/src/gui/styles/types/custom_styles/gruvbox.rs +++ b/src/gui/styles/types/custom_styles/gruvbox.rs @@ -11,19 +11,18 @@ use super::{CustomPalette, Palette, PaletteExtension}; pub(super) fn gruvbox_dark() -> CustomPalette { CustomPalette { palette: Palette { - primary: color!(0x282828), // bg - secondary: color!(0xfe8019), // orange - outgoing: color!(0x8ec07c), // aqua - buttons: color!(0x928374), // gray - text_headers: color!(0x1d2021), // bg0_h - text_body: color!(0xebdbb2), // fg - round_borders: color!(0x98971a), // green - round_containers: color!(0x504945), // bg2 + primary: color!(0x282828), // bg + secondary: color!(0xfe8019), // orange + outgoing: color!(0x8ec07c), // aqua + buttons: color!(0x7c6f64), // bg4 + text_headers: color!(0x1d2021), // bg0_h + text_body: color!(0xebdbb2), // fg }, extension: PaletteExtension { - starred: color!(0xd79921), - badge_alpha: 0.75, - color_mixing: 0.3, + starred: color!(0xd79921, 0.8), + chart_badge_alpha: 0.15, + round_borders_alpha: 0.12, + round_containers_alpha: 0.05, }, } } diff --git a/src/gui/styles/types/custom_styles/nord.rs b/src/gui/styles/types/custom_styles/nord.rs index 074c8948a..739bb16b0 100644 --- a/src/gui/styles/types/custom_styles/nord.rs +++ b/src/gui/styles/types/custom_styles/nord.rs @@ -1,7 +1,7 @@ #![allow(clippy::unreadable_literal)] //! Nord theme -//! https://www.nordtheme.com/docs/colors-and-palettes +//! use iced::color; use super::{CustomPalette, Palette, PaletteExtension}; @@ -9,19 +9,18 @@ use super::{CustomPalette, Palette, PaletteExtension}; pub(super) fn nord() -> CustomPalette { CustomPalette { palette: Palette { - primary: color!(0x2e3440), // nord0 - secondary: color!(0x88c0d0), // nord8 - outgoing: color!(0x81a1c1), // nord9 - buttons: color!(0x3b4252), // nord1 - text_headers: color!(0x4c566a), // nord3 - text_body: color!(0xd8dee9), // nord4 - round_borders: color!(0xe5e9f0), // nord5 - round_containers: color!(0x434c5e), // nord2 + primary: color!(0x2e3440), // nord0 + secondary: color!(0x88c0d0), // nord8 + outgoing: color!(0xB48EAD), // nord15 + buttons: color!(0x4C566A), // nord3 + text_headers: color!(0x2e3440), // nord0 + text_body: color!(0xd8dee9), // nord4 }, extension: PaletteExtension { starred: color!(0xebcb8b), // nord13 - badge_alpha: 0.75, - color_mixing: 0.3, + chart_badge_alpha: 0.2, + round_borders_alpha: 0.35, + round_containers_alpha: 0.15, }, } } diff --git a/src/gui/styles/types/custom_styles/solarized.rs b/src/gui/styles/types/custom_styles/solarized.rs index eebc5f4a8..9df94f5c7 100644 --- a/src/gui/styles/types/custom_styles/solarized.rs +++ b/src/gui/styles/types/custom_styles/solarized.rs @@ -10,19 +10,18 @@ use super::{CustomPalette, Palette, PaletteExtension}; pub(super) fn solarized_light() -> CustomPalette { CustomPalette { palette: Palette { - primary: color!(0xfdf6e3), // base3 - secondary: color!(0x859900), // green - outgoing: color!(0x268bd2), // blue - buttons: color!(0xeee8d5), // base2 - text_headers: color!(0xfdf6e3), // base3 - text_body: color!(0x93a1a1), // base1 - round_borders: color!(0xcb4b16), // orange - round_containers: color!(0xeee8d5), // base2 + primary: color!(0xfdf6e3), // base3 + secondary: color!(0xdc322f), // red + outgoing: color!(0x859900), // green + buttons: color!(0x93a1a1), // base1 + text_headers: color!(0xfdf6e3), // base3 + text_body: color!(0x002b36), // base03 }, extension: PaletteExtension { - starred: color!(0xb58900), // yellow - badge_alpha: 0.75, - color_mixing: 0.8, + starred: color!(0xb58900, 0.9), // yellow + chart_badge_alpha: 0.75, + round_borders_alpha: 0.35, + round_containers_alpha: 0.15, }, } } @@ -31,19 +30,18 @@ pub(super) fn solarized_light() -> CustomPalette { pub(super) fn solarized_dark() -> CustomPalette { CustomPalette { palette: Palette { - primary: color!(0x002b36), // base03 - secondary: color!(0x859900), // green - outgoing: color!(0x268bd2), // blue - buttons: color!(0x073642), // base02 - text_headers: color!(0x002b36), // base03 - text_body: color!(0x839496), // base0 - round_borders: color!(0xcb4b16), // orange - round_containers: color!(0x073642), // base2 + primary: color!(0x002b36), // base03 + secondary: color!(0x859900), // green + outgoing: color!(0x268bd2), // blue + buttons: color!(0x586e75), // base01 + text_headers: color!(0x002b36), // base03 + text_body: color!(0xeee8d5), // base2 }, extension: PaletteExtension { starred: color!(0xb58900), // yellow - badge_alpha: 0.75, - color_mixing: 0.3, + chart_badge_alpha: 0.25, + round_borders_alpha: 0.15, + round_containers_alpha: 0.08, }, } } diff --git a/src/gui/styles/types/palette.rs b/src/gui/styles/types/palette.rs index dff3a48e2..1c27f514e 100644 --- a/src/gui/styles/types/palette.rs +++ b/src/gui/styles/types/palette.rs @@ -29,10 +29,6 @@ pub struct Palette { pub text_headers: Color, /// Color of body and buttons text pub text_body: Color, - /// Color of round container borders and scrollbar borders - pub round_borders: Color, - /// Color of round containers - pub round_containers: Color, } pub fn get_colors(style: StyleType) -> Palette { From 09deb577273de78104738f42300f878f6a0859b2 Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Sat, 5 Aug 2023 22:55:20 -0400 Subject: [PATCH 15/21] Add Nord (Day) as a light theme. --- src/gui/styles/types/custom_styles.rs | 19 ++++++++++++------- src/gui/styles/types/custom_styles/nord.rs | 21 ++++++++++++++++++++- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/gui/styles/types/custom_styles.rs b/src/gui/styles/types/custom_styles.rs index 96d0e0699..19a0b0cbf 100644 --- a/src/gui/styles/types/custom_styles.rs +++ b/src/gui/styles/types/custom_styles.rs @@ -36,7 +36,8 @@ pub struct PaletteExtension { pub enum ExtraStyles { Dracula, Gruvbox, - Nord, + NordLight, + NordDark, SolarizedDark, SolarizedLight, } @@ -48,7 +49,8 @@ impl ExtraStyles { match self { ExtraStyles::Dracula => dracula::dracula().palette, ExtraStyles::Gruvbox => gruvbox::gruvbox_dark().palette, - ExtraStyles::Nord => nord::nord().palette, + ExtraStyles::NordLight => nord::nord_day().palette, + ExtraStyles::NordDark => nord::nord_night().palette, ExtraStyles::SolarizedDark => solarized::solarized_dark().palette, ExtraStyles::SolarizedLight => solarized::solarized_light().palette, } @@ -60,7 +62,8 @@ impl ExtraStyles { match self { ExtraStyles::Dracula => dracula::dracula().extension, ExtraStyles::Gruvbox => gruvbox::gruvbox_dark().extension, - ExtraStyles::Nord => nord::nord().extension, + ExtraStyles::NordLight => nord::nord_day().extension, + ExtraStyles::NordDark => nord::nord_night().extension, ExtraStyles::SolarizedDark => solarized::solarized_dark().extension, ExtraStyles::SolarizedLight => solarized::solarized_light().extension, } @@ -72,9 +75,9 @@ impl ExtraStyles { match self { ExtraStyles::Dracula | ExtraStyles::Gruvbox - | ExtraStyles::Nord + | ExtraStyles::NordDark | ExtraStyles::SolarizedDark => true, - ExtraStyles::SolarizedLight => false, + ExtraStyles::NordLight | ExtraStyles::SolarizedLight => false, } } @@ -84,7 +87,8 @@ impl ExtraStyles { &[ ExtraStyles::Dracula, ExtraStyles::Gruvbox, - ExtraStyles::Nord, + ExtraStyles::NordLight, + ExtraStyles::NordDark, ExtraStyles::SolarizedDark, ExtraStyles::SolarizedLight, ] @@ -96,7 +100,8 @@ impl fmt::Display for ExtraStyles { match *self { ExtraStyles::Dracula => write!(f, "Dracula"), ExtraStyles::Gruvbox => write!(f, "Gruvbox (Night)"), - ExtraStyles::Nord => write!(f, "Nord"), + ExtraStyles::NordLight => write!(f, "Nord (Day)"), + ExtraStyles::NordDark => write!(f, "Nord (Night)"), ExtraStyles::SolarizedLight => write!(f, "Solarized (Day)"), ExtraStyles::SolarizedDark => write!(f, "Solarized (Night)"), } diff --git a/src/gui/styles/types/custom_styles/nord.rs b/src/gui/styles/types/custom_styles/nord.rs index 739bb16b0..3c7a2715c 100644 --- a/src/gui/styles/types/custom_styles/nord.rs +++ b/src/gui/styles/types/custom_styles/nord.rs @@ -6,7 +6,7 @@ use iced::color; use super::{CustomPalette, Palette, PaletteExtension}; -pub(super) fn nord() -> CustomPalette { +pub(super) fn nord_night() -> CustomPalette { CustomPalette { palette: Palette { primary: color!(0x2e3440), // nord0 @@ -24,3 +24,22 @@ pub(super) fn nord() -> CustomPalette { }, } } + +pub(super) fn nord_day() -> CustomPalette { + CustomPalette { + palette: Palette { + primary: color!(0xeceff4), // nord6 + secondary: color!(0x05e81ac), // nord10 + outgoing: color!(0xb48ead), // nord15 + buttons: color!(0xd8dee9), // nord4 + text_headers: color!(0xeceff4), // nord6 + text_body: color!(0x2e3440), // nord0 + }, + extension: PaletteExtension { + starred: color!(0xebcb8b), // nord13 + chart_badge_alpha: 0.6, + round_borders_alpha: 0.35, + round_containers_alpha: 0.15, + }, + } +} From 50044079bceb5340c1e35910d8e172cd1e10f242 Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Sun, 6 Aug 2023 01:23:23 -0400 Subject: [PATCH 16/21] Add Gruvbox light. --- src/gui/styles/types/custom_styles.rs | 21 ++++++++++++------- src/gui/styles/types/custom_styles/gruvbox.rs | 20 ++++++++++++++++++ 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/gui/styles/types/custom_styles.rs b/src/gui/styles/types/custom_styles.rs index 19a0b0cbf..6c8f8a5f9 100644 --- a/src/gui/styles/types/custom_styles.rs +++ b/src/gui/styles/types/custom_styles.rs @@ -35,7 +35,8 @@ pub struct PaletteExtension { #[serde(tag = "custom")] pub enum ExtraStyles { Dracula, - Gruvbox, + GruvboxDark, + GruvboxLight, NordLight, NordDark, SolarizedDark, @@ -48,7 +49,8 @@ impl ExtraStyles { pub fn to_palette(self) -> Palette { match self { ExtraStyles::Dracula => dracula::dracula().palette, - ExtraStyles::Gruvbox => gruvbox::gruvbox_dark().palette, + ExtraStyles::GruvboxDark => gruvbox::gruvbox_dark().palette, + ExtraStyles::GruvboxLight => gruvbox::gruvbox_light().palette, ExtraStyles::NordLight => nord::nord_day().palette, ExtraStyles::NordDark => nord::nord_night().palette, ExtraStyles::SolarizedDark => solarized::solarized_dark().palette, @@ -61,7 +63,8 @@ impl ExtraStyles { pub fn to_ext(self) -> PaletteExtension { match self { ExtraStyles::Dracula => dracula::dracula().extension, - ExtraStyles::Gruvbox => gruvbox::gruvbox_dark().extension, + ExtraStyles::GruvboxDark => gruvbox::gruvbox_dark().extension, + ExtraStyles::GruvboxLight => gruvbox::gruvbox_light().extension, ExtraStyles::NordLight => nord::nord_day().extension, ExtraStyles::NordDark => nord::nord_night().extension, ExtraStyles::SolarizedDark => solarized::solarized_dark().extension, @@ -74,10 +77,12 @@ impl ExtraStyles { pub const fn is_nightly(self) -> bool { match self { ExtraStyles::Dracula - | ExtraStyles::Gruvbox + | ExtraStyles::GruvboxDark | ExtraStyles::NordDark | ExtraStyles::SolarizedDark => true, - ExtraStyles::NordLight | ExtraStyles::SolarizedLight => false, + ExtraStyles::GruvboxLight | ExtraStyles::NordLight | ExtraStyles::SolarizedLight => { + false + } } } @@ -86,7 +91,8 @@ impl ExtraStyles { pub const fn all_styles() -> &'static [Self] { &[ ExtraStyles::Dracula, - ExtraStyles::Gruvbox, + ExtraStyles::GruvboxDark, + ExtraStyles::GruvboxLight, ExtraStyles::NordLight, ExtraStyles::NordDark, ExtraStyles::SolarizedDark, @@ -99,7 +105,8 @@ impl fmt::Display for ExtraStyles { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { ExtraStyles::Dracula => write!(f, "Dracula"), - ExtraStyles::Gruvbox => write!(f, "Gruvbox (Night)"), + ExtraStyles::GruvboxDark => write!(f, "Gruvbox (Night)"), + ExtraStyles::GruvboxLight => write!(f, "Gruvbox (Day)"), ExtraStyles::NordLight => write!(f, "Nord (Day)"), ExtraStyles::NordDark => write!(f, "Nord (Night)"), ExtraStyles::SolarizedLight => write!(f, "Solarized (Day)"), diff --git a/src/gui/styles/types/custom_styles/gruvbox.rs b/src/gui/styles/types/custom_styles/gruvbox.rs index f111248cf..70976a446 100644 --- a/src/gui/styles/types/custom_styles/gruvbox.rs +++ b/src/gui/styles/types/custom_styles/gruvbox.rs @@ -26,3 +26,23 @@ pub(super) fn gruvbox_dark() -> CustomPalette { }, } } + +/// Gruvbox (day style) +pub(super) fn gruvbox_light() -> CustomPalette { + CustomPalette { + palette: Palette { + primary: color!(0xfbf1c7), // bg + secondary: color!(0xd65d0e), // orange + outgoing: color!(0x689d6a), // aqua + buttons: color!(0xd5c4a1), // bg2 + text_headers: color!(0xf9f5d7), // bg0_h + text_body: color!(0x282828), // fg + }, + extension: PaletteExtension { + starred: color!(0xd79921), // yellow + chart_badge_alpha: 0.75, + round_borders_alpha: 0.4, + round_containers_alpha: 0.15, + }, + } +} From a3443760a32dd6e35b9c3722b786e61b73da53bb Mon Sep 17 00:00:00 2001 From: Giuliano Bellini s294739 Date: Sun, 6 Aug 2023 11:32:01 +0200 Subject: [PATCH 17/21] fixed highlighted text and minor palettes improvements --- src/gui/styles/button.rs | 5 +---- src/gui/styles/text.rs | 21 +++++++------------ src/gui/styles/types/custom_styles/gruvbox.rs | 6 +++--- src/gui/styles/types/custom_styles/nord.rs | 2 +- .../styles/types/custom_styles/solarized.rs | 4 ++-- 5 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/gui/styles/button.rs b/src/gui/styles/button.rs index e274fecc2..3fd5554d2 100644 --- a/src/gui/styles/button.rs +++ b/src/gui/styles/button.rs @@ -45,7 +45,7 @@ impl button::StyleSheet for ButtonStyleTuple { let colors = get_colors(self.0); button::Appearance { background: Some(match self { - ButtonStyleTuple(_, ButtonType::TabActive) => { + ButtonStyleTuple(_, ButtonType::TabActive | ButtonType::BorderedRoundSelected) => { Background::Color(mix_colors(colors.primary, colors.buttons)) } ButtonStyleTuple(_, ButtonType::Starred) => { @@ -59,9 +59,6 @@ impl button::StyleSheet for ButtonStyleTuple { ButtonStyleTuple(_, ButtonType::Neutral | ButtonType::NotStarred) => { Background::Color(Color::TRANSPARENT) } - ButtonStyleTuple(_, ButtonType::BorderedRoundSelected) => { - Background::Color(mix_colors(colors.primary, colors.buttons)) - } ButtonStyleTuple(_, ButtonType::Gradient(GradientType::None)) => { Background::Color(colors.secondary) } diff --git a/src/gui/styles/text.rs b/src/gui/styles/text.rs index 7ce47ab33..a10fb2468 100644 --- a/src/gui/styles/text.rs +++ b/src/gui/styles/text.rs @@ -4,7 +4,6 @@ use iced::widget::{Column, Text}; use iced::Color; use crate::gui::styles::style_constants::get_font; -use crate::gui::styles::types::palette::Palette; use crate::gui::types::message::Message; use crate::{get_colors, StyleType}; @@ -38,21 +37,19 @@ pub struct TextStyleTuple(pub StyleType, pub TextType); impl From for iced::theme::Text { fn from(tuple: TextStyleTuple) -> Self { - let colors = get_colors(tuple.0); - iced::theme::Text::Color(highlight(tuple.1, &colors)) + //let colors = get_colors(tuple.0); + iced::theme::Text::Color(highlight(tuple.0, tuple.1)) } } /// Returns the weighted average of two colors; color intensity is fixed to 100% -pub fn highlight(element: TextType, colors: &Palette) -> Color { +pub fn highlight(style: StyleType, element: TextType) -> Color { + let colors = get_colors(style); let color = colors.secondary; + let is_nightly = style.is_nightly(); match element { TextType::Title => { - let (p1, c) = if colors.text_body.eq(&Color::BLACK) { - (0.9, 0.7) - } else { - (0.6, 1.0) - }; + let (p1, c) = if is_nightly { (0.6, 1.0) } else { (0.9, 0.7) }; Color { r: c * (1.0 - p1) + color.r * p1, g: c * (1.0 - p1) + color.g * p1, @@ -61,11 +58,7 @@ pub fn highlight(element: TextType, colors: &Palette) -> Color { } } TextType::Subtitle => { - let (p1, c) = if colors.text_body.eq(&Color::BLACK) { - (0.6, 0.7) - } else { - (0.4, 1.0) - }; + let (p1, c) = if is_nightly { (0.4, 1.0) } else { (0.6, 0.7) }; Color { r: c * (1.0 - p1) + color.r * p1, g: c * (1.0 - p1) + color.g * p1, diff --git a/src/gui/styles/types/custom_styles/gruvbox.rs b/src/gui/styles/types/custom_styles/gruvbox.rs index 70976a446..631a1ae8c 100644 --- a/src/gui/styles/types/custom_styles/gruvbox.rs +++ b/src/gui/styles/types/custom_styles/gruvbox.rs @@ -39,10 +39,10 @@ pub(super) fn gruvbox_light() -> CustomPalette { text_body: color!(0x282828), // fg }, extension: PaletteExtension { - starred: color!(0xd79921), // yellow + starred: color!(0xd79921, 0.8), // yellow chart_badge_alpha: 0.75, - round_borders_alpha: 0.4, - round_containers_alpha: 0.15, + round_borders_alpha: 0.45, + round_containers_alpha: 0.2, }, } } diff --git a/src/gui/styles/types/custom_styles/nord.rs b/src/gui/styles/types/custom_styles/nord.rs index 3c7a2715c..3d4a0748c 100644 --- a/src/gui/styles/types/custom_styles/nord.rs +++ b/src/gui/styles/types/custom_styles/nord.rs @@ -31,7 +31,7 @@ pub(super) fn nord_day() -> CustomPalette { primary: color!(0xeceff4), // nord6 secondary: color!(0x05e81ac), // nord10 outgoing: color!(0xb48ead), // nord15 - buttons: color!(0xd8dee9), // nord4 + buttons: color!(0x8FBCBB), // nord7 text_headers: color!(0xeceff4), // nord6 text_body: color!(0x2e3440), // nord0 }, diff --git a/src/gui/styles/types/custom_styles/solarized.rs b/src/gui/styles/types/custom_styles/solarized.rs index 9df94f5c7..242c8dd2d 100644 --- a/src/gui/styles/types/custom_styles/solarized.rs +++ b/src/gui/styles/types/custom_styles/solarized.rs @@ -11,8 +11,8 @@ pub(super) fn solarized_light() -> CustomPalette { CustomPalette { palette: Palette { primary: color!(0xfdf6e3), // base3 - secondary: color!(0xdc322f), // red - outgoing: color!(0x859900), // green + secondary: color!(0x859900), // green + outgoing: color!(0x268bd2), // blue buttons: color!(0x93a1a1), // base1 text_headers: color!(0xfdf6e3), // base3 text_body: color!(0x002b36), // base03 From ff0c70205287a18123e2cad401fce2720ab72742 Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Sun, 6 Aug 2023 23:20:59 -0400 Subject: [PATCH 18/21] Add a light variation of Dracula. I used colors from: https://github.com/AshGrowem/Dracula.min/blob/master/colors-used-table.md --- src/gui/styles/types/custom_styles.rs | 24 ++++++++++++------- src/gui/styles/types/custom_styles/dracula.rs | 24 +++++++++++++++++-- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/gui/styles/types/custom_styles.rs b/src/gui/styles/types/custom_styles.rs index 6c8f8a5f9..a76d1b684 100644 --- a/src/gui/styles/types/custom_styles.rs +++ b/src/gui/styles/types/custom_styles.rs @@ -34,7 +34,8 @@ pub struct PaletteExtension { #[derive(Clone, Copy, Serialize, Deserialize, Debug, Hash, PartialEq)] #[serde(tag = "custom")] pub enum ExtraStyles { - Dracula, + DraculaDay, + DraculaNight, GruvboxDark, GruvboxLight, NordLight, @@ -48,7 +49,8 @@ impl ExtraStyles { #[inline] pub fn to_palette(self) -> Palette { match self { - ExtraStyles::Dracula => dracula::dracula().palette, + ExtraStyles::DraculaDay => dracula::dracula_light().palette, + ExtraStyles::DraculaNight => dracula::dracula_dark().palette, ExtraStyles::GruvboxDark => gruvbox::gruvbox_dark().palette, ExtraStyles::GruvboxLight => gruvbox::gruvbox_light().palette, ExtraStyles::NordLight => nord::nord_day().palette, @@ -62,7 +64,8 @@ impl ExtraStyles { #[inline] pub fn to_ext(self) -> PaletteExtension { match self { - ExtraStyles::Dracula => dracula::dracula().extension, + ExtraStyles::DraculaDay => dracula::dracula_light().extension, + ExtraStyles::DraculaNight => dracula::dracula_dark().extension, ExtraStyles::GruvboxDark => gruvbox::gruvbox_dark().extension, ExtraStyles::GruvboxLight => gruvbox::gruvbox_light().extension, ExtraStyles::NordLight => nord::nord_day().extension, @@ -76,13 +79,14 @@ impl ExtraStyles { #[inline] pub const fn is_nightly(self) -> bool { match self { - ExtraStyles::Dracula + ExtraStyles::DraculaNight | ExtraStyles::GruvboxDark | ExtraStyles::NordDark | ExtraStyles::SolarizedDark => true, - ExtraStyles::GruvboxLight | ExtraStyles::NordLight | ExtraStyles::SolarizedLight => { - false - } + ExtraStyles::DraculaDay + | ExtraStyles::GruvboxLight + | ExtraStyles::NordLight + | ExtraStyles::SolarizedLight => false, } } @@ -90,7 +94,8 @@ impl ExtraStyles { #[inline] pub const fn all_styles() -> &'static [Self] { &[ - ExtraStyles::Dracula, + ExtraStyles::DraculaDay, + ExtraStyles::DraculaNight, ExtraStyles::GruvboxDark, ExtraStyles::GruvboxLight, ExtraStyles::NordLight, @@ -104,7 +109,8 @@ impl ExtraStyles { impl fmt::Display for ExtraStyles { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { - ExtraStyles::Dracula => write!(f, "Dracula"), + ExtraStyles::DraculaDay => write!(f, "Dracula (Day)"), + ExtraStyles::DraculaNight => write!(f, "Dracula (Night)"), ExtraStyles::GruvboxDark => write!(f, "Gruvbox (Night)"), ExtraStyles::GruvboxLight => write!(f, "Gruvbox (Day)"), ExtraStyles::NordLight => write!(f, "Nord (Day)"), diff --git a/src/gui/styles/types/custom_styles/dracula.rs b/src/gui/styles/types/custom_styles/dracula.rs index d1f7a504e..9288c64b9 100644 --- a/src/gui/styles/types/custom_styles/dracula.rs +++ b/src/gui/styles/types/custom_styles/dracula.rs @@ -2,14 +2,15 @@ //! Dracula theme //! +//! Light style from: https://github.com/AshGrowem/Dracula.min/ use iced::color; use super::{CustomPalette, Palette, PaletteExtension}; -pub(super) fn dracula() -> CustomPalette { +pub(super) fn dracula_dark() -> CustomPalette { CustomPalette { palette: Palette { - primary: color!(0x282a36), // Backgorund + primary: color!(0x282a36), // Background secondary: color!(0xff79c6), // Pink outgoing: color!(0x8be9fd), // Cyan buttons: color!(0x6272a4), // Comments @@ -24,3 +25,22 @@ pub(super) fn dracula() -> CustomPalette { }, } } + +pub(super) fn dracula_light() -> CustomPalette { + CustomPalette { + palette: Palette { + primary: color!(0xf1f2ff), + secondary: color!(0xff79c6), + outgoing: color!(0x8be9fd), + buttons: color!(0xcbcee5), + text_headers: color!(0xf1f2ff), + text_body: color!(0x282a36), + }, + extension: PaletteExtension { + starred: color!(0xf1fa8c, 0.7), + chart_badge_alpha: 0.25, + round_borders_alpha: 0.15, + round_containers_alpha: 0.05, + }, + } +} From 32ec19f32325d6acf06e9e7b5c15567e8eae5266 Mon Sep 17 00:00:00 2001 From: Giuliano Bellini s294739 Date: Mon, 7 Aug 2023 15:04:33 +0200 Subject: [PATCH 19/21] fix Dracula Light palette --- src/gui/styles/types/custom_styles/dracula.rs | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/gui/styles/types/custom_styles/dracula.rs b/src/gui/styles/types/custom_styles/dracula.rs index 9288c64b9..32989eb54 100644 --- a/src/gui/styles/types/custom_styles/dracula.rs +++ b/src/gui/styles/types/custom_styles/dracula.rs @@ -2,7 +2,7 @@ //! Dracula theme //! -//! Light style from: https://github.com/AshGrowem/Dracula.min/ +//! Light style from: use iced::color; use super::{CustomPalette, Palette, PaletteExtension}; @@ -26,21 +26,22 @@ pub(super) fn dracula_dark() -> CustomPalette { } } +// Light Darker variant pub(super) fn dracula_light() -> CustomPalette { CustomPalette { palette: Palette { - primary: color!(0xf1f2ff), - secondary: color!(0xff79c6), - outgoing: color!(0x8be9fd), - buttons: color!(0xcbcee5), - text_headers: color!(0xf1f2ff), + primary: color!(0xf8f8f2), + secondary: color!(0x9f1670), + outgoing: color!(0x005d6f), + buttons: color!(0xc5c8de), + text_headers: color!(0xf8f8f2), text_body: color!(0x282a36), }, extension: PaletteExtension { - starred: color!(0xf1fa8c, 0.7), - chart_badge_alpha: 0.25, - round_borders_alpha: 0.15, - round_containers_alpha: 0.05, + starred: color!(0xffb86c, 0.8), + chart_badge_alpha: 0.75, + round_borders_alpha: 0.45, + round_containers_alpha: 0.25, }, } } From 66f1b8d480e41631bf8392ed66bfb7b5bc5f6b79 Mon Sep 17 00:00:00 2001 From: Giuliano Bellini s294739 Date: Mon, 7 Aug 2023 15:35:36 +0200 Subject: [PATCH 20/21] refactoring --- src/gui/pages/settings_style_page.rs | 2 +- .../dracula.rs | 7 +-- .../gruvbox.rs | 7 +-- src/gui/styles/custom_themes/mod.rs | 4 ++ .../custom_styles => custom_themes}/nord.rs | 7 +-- .../solarized.rs | 7 +-- src/gui/styles/mod.rs | 1 + .../{custom_styles.rs => custom_palette.rs} | 48 +++++++++---------- src/gui/styles/types/mod.rs | 2 +- src/gui/styles/types/style_type.rs | 2 +- 10 files changed, 46 insertions(+), 41 deletions(-) rename src/gui/styles/{types/custom_styles => custom_themes}/dracula.rs (83%) rename src/gui/styles/{types/custom_styles => custom_themes}/gruvbox.rs (83%) create mode 100644 src/gui/styles/custom_themes/mod.rs rename src/gui/styles/{types/custom_styles => custom_themes}/nord.rs (83%) rename src/gui/styles/{types/custom_styles => custom_themes}/solarized.rs (84%) rename src/gui/styles/types/{custom_styles.rs => custom_palette.rs} (74%) diff --git a/src/gui/pages/settings_style_page.rs b/src/gui/pages/settings_style_page.rs index d310847d7..84addceae 100644 --- a/src/gui/pages/settings_style_page.rs +++ b/src/gui/pages/settings_style_page.rs @@ -14,7 +14,7 @@ use crate::gui::styles::rule::{RuleStyleTuple, RuleType}; use crate::gui::styles::scrollbar::{ScrollbarStyleTuple, ScrollbarType}; use crate::gui::styles::style_constants::{get_font, BORDER_WIDTH, FONT_SIZE_SUBTITLE, ICONS}; use crate::gui::styles::text::{TextStyleTuple, TextType}; -use crate::gui::styles::types::custom_styles::ExtraStyles; +use crate::gui::styles::types::custom_palette::ExtraStyles; use crate::gui::styles::types::gradient_type::GradientType; use crate::gui::types::message::Message; use crate::translations::translations::{ diff --git a/src/gui/styles/types/custom_styles/dracula.rs b/src/gui/styles/custom_themes/dracula.rs similarity index 83% rename from src/gui/styles/types/custom_styles/dracula.rs rename to src/gui/styles/custom_themes/dracula.rs index 32989eb54..58fcdf4b8 100644 --- a/src/gui/styles/types/custom_styles/dracula.rs +++ b/src/gui/styles/custom_themes/dracula.rs @@ -5,9 +5,10 @@ //! Light style from: use iced::color; -use super::{CustomPalette, Palette, PaletteExtension}; +use crate::gui::styles::types::custom_palette::{CustomPalette, PaletteExtension}; +use crate::gui::styles::types::palette::Palette; -pub(super) fn dracula_dark() -> CustomPalette { +pub(in crate::gui::styles) fn dracula_dark() -> CustomPalette { CustomPalette { palette: Palette { primary: color!(0x282a36), // Background @@ -27,7 +28,7 @@ pub(super) fn dracula_dark() -> CustomPalette { } // Light Darker variant -pub(super) fn dracula_light() -> CustomPalette { +pub(in crate::gui::styles) fn dracula_light() -> CustomPalette { CustomPalette { palette: Palette { primary: color!(0xf8f8f2), diff --git a/src/gui/styles/types/custom_styles/gruvbox.rs b/src/gui/styles/custom_themes/gruvbox.rs similarity index 83% rename from src/gui/styles/types/custom_styles/gruvbox.rs rename to src/gui/styles/custom_themes/gruvbox.rs index 631a1ae8c..2cd7b9fc6 100644 --- a/src/gui/styles/types/custom_styles/gruvbox.rs +++ b/src/gui/styles/custom_themes/gruvbox.rs @@ -5,10 +5,11 @@ use iced::color; -use super::{CustomPalette, Palette, PaletteExtension}; +use crate::gui::styles::types::custom_palette::{CustomPalette, PaletteExtension}; +use crate::gui::styles::types::palette::Palette; /// Gruvbox (night style) -pub(super) fn gruvbox_dark() -> CustomPalette { +pub(in crate::gui::styles) fn gruvbox_dark() -> CustomPalette { CustomPalette { palette: Palette { primary: color!(0x282828), // bg @@ -28,7 +29,7 @@ pub(super) fn gruvbox_dark() -> CustomPalette { } /// Gruvbox (day style) -pub(super) fn gruvbox_light() -> CustomPalette { +pub(in crate::gui::styles) fn gruvbox_light() -> CustomPalette { CustomPalette { palette: Palette { primary: color!(0xfbf1c7), // bg diff --git a/src/gui/styles/custom_themes/mod.rs b/src/gui/styles/custom_themes/mod.rs new file mode 100644 index 000000000..1ccee9527 --- /dev/null +++ b/src/gui/styles/custom_themes/mod.rs @@ -0,0 +1,4 @@ +pub mod dracula; +pub mod gruvbox; +pub mod nord; +pub mod solarized; diff --git a/src/gui/styles/types/custom_styles/nord.rs b/src/gui/styles/custom_themes/nord.rs similarity index 83% rename from src/gui/styles/types/custom_styles/nord.rs rename to src/gui/styles/custom_themes/nord.rs index 3d4a0748c..e6016595e 100644 --- a/src/gui/styles/types/custom_styles/nord.rs +++ b/src/gui/styles/custom_themes/nord.rs @@ -4,9 +4,10 @@ //! use iced::color; -use super::{CustomPalette, Palette, PaletteExtension}; +use crate::gui::styles::types::custom_palette::{CustomPalette, PaletteExtension}; +use crate::gui::styles::types::palette::Palette; -pub(super) fn nord_night() -> CustomPalette { +pub(in crate::gui::styles) fn nord_dark() -> CustomPalette { CustomPalette { palette: Palette { primary: color!(0x2e3440), // nord0 @@ -25,7 +26,7 @@ pub(super) fn nord_night() -> CustomPalette { } } -pub(super) fn nord_day() -> CustomPalette { +pub(in crate::gui::styles) fn nord_light() -> CustomPalette { CustomPalette { palette: Palette { primary: color!(0xeceff4), // nord6 diff --git a/src/gui/styles/types/custom_styles/solarized.rs b/src/gui/styles/custom_themes/solarized.rs similarity index 84% rename from src/gui/styles/types/custom_styles/solarized.rs rename to src/gui/styles/custom_themes/solarized.rs index 242c8dd2d..8d09fa7fb 100644 --- a/src/gui/styles/types/custom_styles/solarized.rs +++ b/src/gui/styles/custom_themes/solarized.rs @@ -4,10 +4,11 @@ //! use iced::color; -use super::{CustomPalette, Palette, PaletteExtension}; +use crate::gui::styles::types::custom_palette::{CustomPalette, PaletteExtension}; +use crate::gui::styles::types::palette::Palette; /// Solarized light (Day style) -pub(super) fn solarized_light() -> CustomPalette { +pub(in crate::gui::styles) fn solarized_light() -> CustomPalette { CustomPalette { palette: Palette { primary: color!(0xfdf6e3), // base3 @@ -27,7 +28,7 @@ pub(super) fn solarized_light() -> CustomPalette { } /// Solarized dark (Night style) -pub(super) fn solarized_dark() -> CustomPalette { +pub(in crate::gui::styles) fn solarized_dark() -> CustomPalette { CustomPalette { palette: Palette { primary: color!(0x002b36), // base03 diff --git a/src/gui/styles/mod.rs b/src/gui/styles/mod.rs index a927f707e..841c5eaad 100644 --- a/src/gui/styles/mod.rs +++ b/src/gui/styles/mod.rs @@ -1,6 +1,7 @@ pub mod button; pub mod checkbox; pub mod container; +pub mod custom_themes; pub mod picklist; pub mod radio; pub mod rule; diff --git a/src/gui/styles/types/custom_styles.rs b/src/gui/styles/types/custom_palette.rs similarity index 74% rename from src/gui/styles/types/custom_styles.rs rename to src/gui/styles/types/custom_palette.rs index a76d1b684..9df38fac7 100644 --- a/src/gui/styles/types/custom_styles.rs +++ b/src/gui/styles/types/custom_palette.rs @@ -1,21 +1,17 @@ -mod dracula; -mod gruvbox; -mod nord; -mod solarized; - use std::fmt; use iced::Color; use serde::{Deserialize, Serialize}; -use super::palette::Palette; +use crate::gui::styles::custom_themes::{dracula, gruvbox, nord, solarized}; +use crate::gui::styles::types::palette::Palette; /// Custom style with any relevant metadata pub struct CustomPalette { /// Color scheme's palette - palette: Palette, + pub(crate) palette: Palette, /// Extra colors such as the favorites star - extension: PaletteExtension, + pub(crate) extension: PaletteExtension, } /// Extension color for themes. @@ -34,12 +30,12 @@ pub struct PaletteExtension { #[derive(Clone, Copy, Serialize, Deserialize, Debug, Hash, PartialEq)] #[serde(tag = "custom")] pub enum ExtraStyles { - DraculaDay, - DraculaNight, + DraculaDark, + DraculaLight, GruvboxDark, GruvboxLight, - NordLight, NordDark, + NordLight, SolarizedDark, SolarizedLight, } @@ -49,12 +45,12 @@ impl ExtraStyles { #[inline] pub fn to_palette(self) -> Palette { match self { - ExtraStyles::DraculaDay => dracula::dracula_light().palette, - ExtraStyles::DraculaNight => dracula::dracula_dark().palette, + ExtraStyles::DraculaLight => dracula::dracula_light().palette, + ExtraStyles::DraculaDark => dracula::dracula_dark().palette, ExtraStyles::GruvboxDark => gruvbox::gruvbox_dark().palette, ExtraStyles::GruvboxLight => gruvbox::gruvbox_light().palette, - ExtraStyles::NordLight => nord::nord_day().palette, - ExtraStyles::NordDark => nord::nord_night().palette, + ExtraStyles::NordLight => nord::nord_light().palette, + ExtraStyles::NordDark => nord::nord_dark().palette, ExtraStyles::SolarizedDark => solarized::solarized_dark().palette, ExtraStyles::SolarizedLight => solarized::solarized_light().palette, } @@ -64,12 +60,12 @@ impl ExtraStyles { #[inline] pub fn to_ext(self) -> PaletteExtension { match self { - ExtraStyles::DraculaDay => dracula::dracula_light().extension, - ExtraStyles::DraculaNight => dracula::dracula_dark().extension, + ExtraStyles::DraculaLight => dracula::dracula_light().extension, + ExtraStyles::DraculaDark => dracula::dracula_dark().extension, ExtraStyles::GruvboxDark => gruvbox::gruvbox_dark().extension, ExtraStyles::GruvboxLight => gruvbox::gruvbox_light().extension, - ExtraStyles::NordLight => nord::nord_day().extension, - ExtraStyles::NordDark => nord::nord_night().extension, + ExtraStyles::NordLight => nord::nord_light().extension, + ExtraStyles::NordDark => nord::nord_dark().extension, ExtraStyles::SolarizedDark => solarized::solarized_dark().extension, ExtraStyles::SolarizedLight => solarized::solarized_light().extension, } @@ -79,11 +75,11 @@ impl ExtraStyles { #[inline] pub const fn is_nightly(self) -> bool { match self { - ExtraStyles::DraculaNight + ExtraStyles::DraculaDark | ExtraStyles::GruvboxDark | ExtraStyles::NordDark | ExtraStyles::SolarizedDark => true, - ExtraStyles::DraculaDay + ExtraStyles::DraculaLight | ExtraStyles::GruvboxLight | ExtraStyles::NordLight | ExtraStyles::SolarizedLight => false, @@ -94,12 +90,12 @@ impl ExtraStyles { #[inline] pub const fn all_styles() -> &'static [Self] { &[ - ExtraStyles::DraculaDay, - ExtraStyles::DraculaNight, + ExtraStyles::DraculaDark, + ExtraStyles::DraculaLight, ExtraStyles::GruvboxDark, ExtraStyles::GruvboxLight, - ExtraStyles::NordLight, ExtraStyles::NordDark, + ExtraStyles::NordLight, ExtraStyles::SolarizedDark, ExtraStyles::SolarizedLight, ] @@ -109,8 +105,8 @@ impl ExtraStyles { impl fmt::Display for ExtraStyles { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { - ExtraStyles::DraculaDay => write!(f, "Dracula (Day)"), - ExtraStyles::DraculaNight => write!(f, "Dracula (Night)"), + ExtraStyles::DraculaLight => write!(f, "Dracula (Day)"), + ExtraStyles::DraculaDark => write!(f, "Dracula (Night)"), ExtraStyles::GruvboxDark => write!(f, "Gruvbox (Night)"), ExtraStyles::GruvboxLight => write!(f, "Gruvbox (Day)"), ExtraStyles::NordLight => write!(f, "Nord (Day)"), diff --git a/src/gui/styles/types/mod.rs b/src/gui/styles/types/mod.rs index 7a8e2ce8a..4613b2da9 100644 --- a/src/gui/styles/types/mod.rs +++ b/src/gui/styles/types/mod.rs @@ -1,4 +1,4 @@ -pub mod custom_styles; +pub mod custom_palette; pub mod gradient_type; pub mod palette; pub mod style_type; diff --git a/src/gui/styles/types/style_type.rs b/src/gui/styles/types/style_type.rs index fe659c180..a097e1273 100644 --- a/src/gui/styles/types/style_type.rs +++ b/src/gui/styles/types/style_type.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use super::custom_styles::ExtraStyles; +use crate::gui::styles::types::custom_palette::ExtraStyles; /// Used to specify the kind of style of the application #[derive(Clone, Copy, Serialize, Deserialize, Debug, Hash, PartialEq)] From 0b56a2ac5ffb2d5d3a8395b0006fc4a87b923604 Mon Sep 17 00:00:00 2001 From: Giuliano Bellini s294739 Date: Mon, 7 Aug 2023 17:04:28 +0200 Subject: [PATCH 21/21] some more refactoring --- src/gui/pages/settings_style_page.rs | 6 +++--- src/gui/styles/text.rs | 1 - src/gui/styles/types/custom_palette.rs | 4 ---- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/gui/pages/settings_style_page.rs b/src/gui/pages/settings_style_page.rs index 84addceae..450a7ceb0 100644 --- a/src/gui/pages/settings_style_page.rs +++ b/src/gui/pages/settings_style_page.rs @@ -103,8 +103,8 @@ pub fn settings_style_page(sniffer: &Sniffer) -> Container { )), ) .push(vertical_space(Length::Fixed(10.0))); - for style in get_extra_styles(ExtraStyles::all_styles(), sniffer.style) { - styles_col = styles_col.push(style); + for children in get_extra_palettes(ExtraStyles::all_styles(), sniffer.style) { + styles_col = styles_col.push(children); } let styles_scroll = Scrollable::new(styles_col) @@ -263,7 +263,7 @@ fn get_palette(style: StyleType, is_custom: bool) -> Container<'static, Message> } // Buttons for each extra style arranged in rows of two -fn get_extra_styles( +fn get_extra_palettes( styles: &[ExtraStyles], current_style: StyleType, ) -> Vec> { diff --git a/src/gui/styles/text.rs b/src/gui/styles/text.rs index a10fb2468..a21b34a0e 100644 --- a/src/gui/styles/text.rs +++ b/src/gui/styles/text.rs @@ -37,7 +37,6 @@ pub struct TextStyleTuple(pub StyleType, pub TextType); impl From for iced::theme::Text { fn from(tuple: TextStyleTuple) -> Self { - //let colors = get_colors(tuple.0); iced::theme::Text::Color(highlight(tuple.0, tuple.1)) } } diff --git a/src/gui/styles/types/custom_palette.rs b/src/gui/styles/types/custom_palette.rs index 9df38fac7..6a2d7f0af 100644 --- a/src/gui/styles/types/custom_palette.rs +++ b/src/gui/styles/types/custom_palette.rs @@ -42,7 +42,6 @@ pub enum ExtraStyles { impl ExtraStyles { /// [`Palette`] of the [`ExtraStyles`] variant - #[inline] pub fn to_palette(self) -> Palette { match self { ExtraStyles::DraculaLight => dracula::dracula_light().palette, @@ -57,7 +56,6 @@ impl ExtraStyles { } /// Extension colors for the current [`ExtraStyles`] variant - #[inline] pub fn to_ext(self) -> PaletteExtension { match self { ExtraStyles::DraculaLight => dracula::dracula_light().extension, @@ -72,7 +70,6 @@ impl ExtraStyles { } /// Theme is a night/dark style - #[inline] pub const fn is_nightly(self) -> bool { match self { ExtraStyles::DraculaDark @@ -87,7 +84,6 @@ impl ExtraStyles { } /// Slice of all implemented custom styles - #[inline] pub const fn all_styles() -> &'static [Self] { &[ ExtraStyles::DraculaDark,