Skip to content

Commit

Permalink
working different shades of colors
Browse files Browse the repository at this point in the history
  • Loading branch information
Redhawk18 committed Aug 10, 2023
1 parent f2c0e7c commit 39d5eda
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 35 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
iced = "0.10.0"
iced = { version = "0.10.0", features = ["palette"]}
iced_aw = { version = "0.6", default-features = false, features = ["menu", "tab_bar", "tabs"] }
log = "0.4.18"
palette = "*"
palette = "0.7.0"
pretty_env_logger = "0.5"
rfd = "0.11.4"
2 changes: 1 addition & 1 deletion src/gui/file_dialog.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::core;
use super::FileTab;
use crate::core;

use rfd::FileDialog;
use std::io::Result;
Expand Down
12 changes: 6 additions & 6 deletions src/gui/theme/colors.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::gui::theme::shade::Shade;
use crate::gui::theme::shades::Shades;

/// Holds infomation about the post-processed colors at the highest level
/// The result of Palette mixed with Shade
#[derive(Clone)]
pub struct Colors {
pub accent: Shade,
pub background: Shade,
pub primary: Shade,
pub secondary: Shade,
pub text: Shade,
pub accent: Shades,
pub background: Shades,
pub primary: Shades,
pub secondary: Shades,
pub text: Shades,
}
26 changes: 8 additions & 18 deletions src/gui/theme/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
mod colors;
mod pigment;
mod shade;
mod shades;
use colors::Colors;
use pigment::Pigment;
use shade::Shade;
use shades::Shades;

use iced::widget::{button, text, text_input};
use iced::{application, Background};
Expand All @@ -23,21 +23,11 @@ impl Default for Theme {

Theme {
colors: Colors {
accent: Shade {
default: pigment.accent,
},
background: Shade {
default: pigment.background,
},
primary: Shade {
default: pigment.primary,
},
secondary: Shade {
default: pigment.secondary,
},
text: Shade {
default: pigment.text,
},
accent: Shades::new(pigment.accent),
background: Shades::new(pigment.background),
primary: Shades::new(pigment.primary),
secondary: Shades::new(pigment.secondary),
text: Shades::new(pigment.text),
},
}
}
Expand Down Expand Up @@ -226,7 +216,7 @@ impl text_input::StyleSheet for Theme {

fn placeholder_color(&self, style: &Self::Style) -> iced::Color {
match style {
TextInput::Primary => self.colors.text.default, //TODO lightest
TextInput::Primary => self.colors.text.dark, //TODO lightest
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/gui/theme/pigment.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use iced::Color;


/// raw hex colors from the theme files
#[derive(Clone, Copy)]
pub struct Pigment {
Expand Down Expand Up @@ -42,3 +43,4 @@ fn hex_to_color(hex: &str) -> Option<Color> {

None
}

8 changes: 0 additions & 8 deletions src/gui/theme/shade.rs

This file was deleted.

55 changes: 55 additions & 0 deletions src/gui/theme/shades.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use iced::Color;
use palette::rgb::Rgb;
use palette::{DarkenAssign, FromColor, LightenAssign, Okhsl, Srgb};

/// provides post-processing to Pigment's raw colors
#[derive(Clone)]
pub struct Shades {
pub default: Color,
pub light: Color,
pub dark: Color,
}

impl Shades {
pub fn new(color: Color) -> Self{
Self {
default: color,
light: lighten(color, 0.5),
dark: darken(color, 0.5),
}
}
}

// special thanks to Halloy https://github.com/squidowl/halloy
fn to_hsl(color: Color) -> Okhsl {
let mut hsl = Okhsl::from_color(Rgb::from(color));
if hsl.saturation.is_nan() {
hsl.saturation = Okhsl::max_saturation();
}

hsl
}

fn from_hsl(hsl: Okhsl) -> Color {
Srgb::from_color(hsl).into()
}

// fn alpha(color: Color, alpha: f32) -> Color {
// Color { a: alpha, ..color }
// }

fn lighten(color: Color, amount: f32) -> Color {
let mut hsl = to_hsl(color);

hsl.lighten_fixed_assign(amount);

from_hsl(hsl)
}

fn darken(color: Color, amount: f32) -> Color {
let mut hsl = to_hsl(color);

hsl.darken_fixed_assign(amount);

from_hsl(hsl)
}

0 comments on commit 39d5eda

Please sign in to comment.