Crates.io | skribble_color |
lib.rs | skribble_color |
version | 0.0.0 |
source | src |
created_at | 2023-04-04 17:51:46.058045 |
updated_at | 2023-04-04 17:51:46.058045 |
description | convert between different supported css color formats using the palette crate |
homepage | https://github.com/ifiokjr/skribble |
repository | https://github.com/ifiokjr/skribble |
max_upload_size | |
id | 830362 |
size | 48,914 |
Parse supported css string into the supported color types.
Add the following to your Cargo.toml
:
[dependencies]
skribble_color = "0.0.0"
The following will convert a Color
type into another Color
type.
use skribble_color::Color;
let hex: Color = "#b1ffb0".parse().unwrap();
let rgb: Color = hex.into_rgb();
let hsl: Color = hex.into_hsl();
let hwb: Color = hex.into_hwb();
let lch: Color = hex.into_lch();
let lab: Color = hex.into_lab();
let oklch: Color = hex.into_oklch();
let oklab: Color = hex.into_oklab();
The following will parse a css string into a Color
type automatically detecting the type of color.
use skribble_color::Color;
use skribble_color::Rgba;
let hex: Color = "#b1ffb0".parse().unwrap();
assert_eq!(hex.to_string(), "#b1ffb0");
assert_eq!(hex, Color::Hex(Rgba::new(0.69411767, 1.0, 0.6901961, 1.0)));
use skribble_color::Color;
use skribble_color::Rgba;
let rgb: Color = "rgb(255, 0, 0)".parse().unwrap();
assert_eq!(rgb.to_string(), "rgb(255 0 0)");
assert_eq!(rgb, Color::Rgb(Rgba::new(1.0, 0.0, 0.0, 1.0)));
use skribble_color::Color;
use skribble_color::Hsla;
let hsl: Color = "hsl(120, 100%, 50%)".parse().unwrap();
assert_eq!(hsl.to_string(), "hsl(120 100% 50%)");
assert_eq!(hsl, Color::Hsl(Hsla::new(120.0, 1.0, 0.5, 1.0)));
use skribble_color::Color;
use skribble_color::Hwba;
let hwb: Color = "hwb(120 0% 0%)".parse().unwrap();
assert_eq!(hwb.to_string(), "hwb(120 0% 0%)");
assert_eq!(hwb, Color::Hwb(Hwba::new(120.0, 0.0, 0.0, 1.0)));