skribble_color

Crates.ioskribble_color
lib.rsskribble_color
version0.0.0
sourcesrc
created_at2023-04-04 17:51:46.058045
updated_at2023-04-04 17:51:46.058045
descriptionconvert between different supported css color formats using the palette crate
homepagehttps://github.com/ifiokjr/skribble
repositoryhttps://github.com/ifiokjr/skribble
max_upload_size
id830362
size48,914
Ifiok Jr. (ifiokjr)

documentation

https://docs.rs/skribble_color

README

skribble_color

Parse supported css string into the supported color types.

Usage

Add the following to your Cargo.toml:

[dependencies]
skribble_color = "0.0.0"

Color Conversions

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();

Examples

The following will parse a css string into a Color type automatically detecting the type of color.

Hex

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)));

Rgb

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)));

Hsl

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)));

Hwb

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)));
Commit count: 265

cargo fmt