From 7a50cc33835430e24b69cf534af37a8eb8615d2d Mon Sep 17 00:00:00 2001
From: Robbert van der Helm <mail@robbertvanderhelm.nl>
Date: Wed, 9 Feb 2022 11:31:59 +0100
Subject: [PATCH] Add HSV scaling utilities

---
 nih_plug_egui/src/widgets.rs      |  1 +
 nih_plug_egui/src/widgets/util.rs | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)
 create mode 100644 nih_plug_egui/src/widgets/util.rs

diff --git a/nih_plug_egui/src/widgets.rs b/nih_plug_egui/src/widgets.rs
index fcb3b751..de1a222c 100644
--- a/nih_plug_egui/src/widgets.rs
+++ b/nih_plug_egui/src/widgets.rs
@@ -6,6 +6,7 @@
 //! to copy the widgets and modify them to your personal taste.
 
 mod param_slider;
+pub mod util;
 
 pub use param_slider::ParamSlider;
 
diff --git a/nih_plug_egui/src/widgets/util.rs b/nih_plug_egui/src/widgets/util.rs
new file mode 100644
index 00000000..eed19ce1
--- /dev/null
+++ b/nih_plug_egui/src/widgets/util.rs
@@ -0,0 +1,21 @@
+//! Utilities for creating these widgets
+
+use egui::Color32;
+
+/// Additively modify the hue, saturation, and lightness [0, 1] values of a color.
+pub fn add_hsv(color: Color32, h: f32, s: f32, v: f32) -> Color32 {
+    let mut hsv = egui::color::Hsva::from(color);
+    hsv.h += h;
+    hsv.s += s;
+    hsv.v += v;
+    hsv.into()
+}
+
+/// Multiplicatively modify the hue, saturation, and lightness [0, 1] values of a color.
+pub fn scale_hsv(color: Color32, h: f32, s: f32, v: f32) -> Color32 {
+    let mut hsv = egui::color::Hsva::from(color);
+    hsv.h *= h;
+    hsv.s *= s;
+    hsv.v *= v;
+    hsv.into()
+}