Skip to content

Commit

Permalink
Fix rgba color parsing (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
epsilon-phase authored Oct 1, 2024
1 parent 1aafda4 commit d1007bb
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion layout/src/core/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ impl Color {
if name.starts_with('#') {
let name = name.trim_start_matches('#');
if let Result::Ok(color) = u32::from_str_radix(name, 16) {
return Some(Color::new((color << 8) + 0xff));
if name.len() <= 7 {
return Some(Color::new((color << 8) + 0xff));
} else {
return Some(Color::new(color));
}
}
}
None
Expand All @@ -207,4 +211,6 @@ fn test_color() {

let color = Color::from_name("#112233");
assert_eq!(color.unwrap().to_web_color(), "#112233ff");
let color = Color::from_name("#112233FA");
assert_eq!(color.unwrap().to_web_color(), "#112233fa");
}

0 comments on commit d1007bb

Please sign in to comment.