GPU-accelerated UI toolkit (Vulkan)
git clone https://git.lucas.co/cce-ui.git
Fix hex color parsers to be quote-resilient
src/color.rs | 3 ++-
src/widget/container/parameters_bg.rs | 1 +
src/widget/input/color_selector.rs | 1 +
3 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/color.rs b/src/color.rs
index fc2243f..8efa6f1 100644
--- a/src/color.rs
+++ b/src/color.rs
@@ -109,7 +109,8 @@ fn parse_and_set_colors(content: &str) {
}
let parse_hex = |hex_str: &str| -> Option<[f32; 4]> {
- let hex = hex_str.trim().trim_start_matches('#');
+ let hex = hex_str.trim_matches(|c| c == '"' || c == '\'' || c == ' ');
+ let hex = hex.trim_start_matches('#');
if hex.len() >= 6 {
if let (Ok(r), Ok(g), Ok(b)) = (
u8::from_str_radix(&hex[0..2], 16),
diff --git a/src/widget/container/parameters_bg.rs b/src/widget/container/parameters_bg.rs
index d2ce2c3..b14e755 100644
--- a/src/widget/container/parameters_bg.rs
+++ b/src/widget/container/parameters_bg.rs
@@ -232,6 +232,7 @@ fn parse_slider_range(ptype: &str) -> (f32, f32) {
}
fn parse_hex_to_rgb(s: &str) -> Option<[u8; 3]> {
+ let s = s.trim_matches(|c| c == '"' || c == '\'' || c == ' ');
let s = s.trim_start_matches('#');
if s.len() == 6 || s.len() == 8 {
let r = u8::from_str_radix(&s[0..2], 16).ok()?;
diff --git a/src/widget/input/color_selector.rs b/src/widget/input/color_selector.rs
index 85e4c4c..cf8fd39 100644
--- a/src/widget/input/color_selector.rs
+++ b/src/widget/input/color_selector.rs
@@ -504,6 +504,7 @@ impl Drop for ColorSelector {
}
fn parse_hex(s: &str) -> Option<[u8; 4]> {
+ let s = s.trim_matches(|c| c == '"' || c == '\'' || c == ' ');
let s = s.trim_start_matches('#');
if s.len() == 6 {
let r = u8::from_str_radix(&s[0..2], 16).ok()?;