Skip to content

Commit

Permalink
fix: wrong hsl color in generated file
Browse files Browse the repository at this point in the history
  • Loading branch information
InioX committed Dec 14, 2023
1 parent 2a706cf commit 54a6960
Showing 1 changed file with 11 additions and 33 deletions.
44 changes: 11 additions & 33 deletions src/util/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use color_eyre::Help;
use color_eyre::{eyre::Result, Report};
use color_eyre::SectionExt;

use colorsys::Hsl;
use colorsys::{Hsl,Rgb,ColorAlpha};
use serde::{Deserialize, Serialize};

use std::str;
Expand Down Expand Up @@ -374,6 +374,8 @@ fn generate_single_color(
}

fn generate_color_strings(color: Color) -> Colora {
let base_color = Rgb::from((color.red as f64, color.green as f64, color.blue as f64,color.alpha as f64));
let hsl_color = Hsl::from(&base_color);
Colora {
hex: format_argb_as_rgb([
color.alpha,
Expand All @@ -396,20 +398,11 @@ fn generate_color_strings(color: Color) -> Colora {
"rgba({:?}, {:?}, {:?}, {:?})",
color.red, color.green, color.blue, color.alpha
),
hsl: Hsl::new(
color.red as f64,
color.green as f64,
color.blue as f64,
Some(color.alpha as f64),
)
.to_css_string(),
hsla: Hsl::new(
color.red as f64,
color.green as f64,
color.blue as f64,
None,
)
.to_css_string(),
hsl: format!(
"hsl({:?}, {:?}, {:?})",
hsl_color.hue(), hsl_color.saturation(), hsl_color.lightness(),
),
hsla: hsl_color.to_css_string(),
red: format!(
"{:?}",
color.blue
Expand All @@ -428,30 +421,15 @@ fn generate_color_strings(color: Color) -> Colora {
),
hue: format!(
"{:?}",
Hsl::new(
color.red as f64,
color.green as f64,
color.blue as f64,
Some(color.alpha as f64),
).hue()
&hsl_color.hue()
),
lightness: format!(
"{:?}",
Hsl::new(
color.red as f64,
color.green as f64,
color.blue as f64,
Some(color.alpha as f64),
).lightness()
&hsl_color.lightness()
),
saturation: format!(
"{:?}",
Hsl::new(
color.red as f64,
color.green as f64,
color.blue as f64,
Some(color.alpha as f64),
).saturation()
&hsl_color.saturation()
),
}
}

0 comments on commit 54a6960

Please sign in to comment.