pub struct Color(pub ColorValue);
Tuple Fields§
§0: ColorValue
Implementations§
Source§impl Color
impl Color
Sourcepub fn from_html<S: AsRef<str>>(s: S) -> ColorResult<Self>
pub fn from_html<S: AsRef<str>>(s: S) -> ColorResult<Self>
Create color from CSS color string.
Examples found in repository?
examples/parser.rs (line 16)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
fn main() {
let test_case = [
"rgb(137, 180, 250)",
"#89B4FA",
"rgba(137, 180, 250, 1)",
"hsla(217.16815, 91.869934%, 75.882355%, 1)",
"gradient(rgb(137, 180, 250), rgb(203, 166, 247))",
];
let other_test = "darken(rgb(137, 180, 250), 5%)";
println!(
"{}",
Color::from_html(other_test)
.unwrap()
.to_solid()
.unwrap()
.to_rgba()
);
for s in test_case {
let a = Color::from_html(s).unwrap();
if let Ok(solid) = a.to_solid() {
let rgba = solid.to_rgba();
let darken_rgba = rgba.darken(5.0);
let darken_solid = solid.darken(5.0).to_rgba();
println!("RGBA: {rgba}");
println!("Darken RGBA: {darken_rgba}");
println!("Darken Solid RGBA: {darken_solid}");
} else if let Ok(gradient) = a.to_gradient() {
println!("{gradient}");
}
}
}
Sourcepub fn to_gradient(&self) -> ColorResult<Gradient>
pub fn to_gradient(&self) -> ColorResult<Gradient>
Convert a Color
to a Gradient
.
Examples found in repository?
examples/parser.rs (line 34)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
fn main() {
let test_case = [
"rgb(137, 180, 250)",
"#89B4FA",
"rgba(137, 180, 250, 1)",
"hsla(217.16815, 91.869934%, 75.882355%, 1)",
"gradient(rgb(137, 180, 250), rgb(203, 166, 247))",
];
let other_test = "darken(rgb(137, 180, 250), 5%)";
println!(
"{}",
Color::from_html(other_test)
.unwrap()
.to_solid()
.unwrap()
.to_rgba()
);
for s in test_case {
let a = Color::from_html(s).unwrap();
if let Ok(solid) = a.to_solid() {
let rgba = solid.to_rgba();
let darken_rgba = rgba.darken(5.0);
let darken_solid = solid.darken(5.0).to_rgba();
println!("RGBA: {rgba}");
println!("Darken RGBA: {darken_rgba}");
println!("Darken Solid RGBA: {darken_solid}");
} else if let Ok(gradient) = a.to_gradient() {
println!("{gradient}");
}
}
}
Sourcepub fn to_solid(&self) -> ColorResult<Solid>
pub fn to_solid(&self) -> ColorResult<Solid>
Convert a Color
to a Solid
.
Examples found in repository?
examples/parser.rs (line 18)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
fn main() {
let test_case = [
"rgb(137, 180, 250)",
"#89B4FA",
"rgba(137, 180, 250, 1)",
"hsla(217.16815, 91.869934%, 75.882355%, 1)",
"gradient(rgb(137, 180, 250), rgb(203, 166, 247))",
];
let other_test = "darken(rgb(137, 180, 250), 5%)";
println!(
"{}",
Color::from_html(other_test)
.unwrap()
.to_solid()
.unwrap()
.to_rgba()
);
for s in test_case {
let a = Color::from_html(s).unwrap();
if let Ok(solid) = a.to_solid() {
let rgba = solid.to_rgba();
let darken_rgba = rgba.darken(5.0);
let darken_solid = solid.darken(5.0).to_rgba();
println!("RGBA: {rgba}");
println!("Darken RGBA: {darken_rgba}");
println!("Darken Solid RGBA: {darken_solid}");
} else if let Ok(gradient) = a.to_gradient() {
println!("{gradient}");
}
}
}
Trait Implementations§
Source§impl PartialOrd for Color
impl PartialOrd for Color
impl StructuralPartialEq for Color
Auto Trait Implementations§
impl Freeze for Color
impl RefUnwindSafe for Color
impl Send for Color
impl Sync for Color
impl Unpin for Color
impl UnwindSafe for Color
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more