pub struct Solid(/* private fields */);
Implementations§
Source§impl Solid
impl Solid
Sourcepub const fn new(r: f32, g: f32, b: f32, a: f32) -> Self
pub const fn new(r: f32, g: f32, b: f32, a: f32) -> Self
Arguments:
r
: Red value [0..1]g
: Green value [0..1]b
: Blue value [0..1]a
: Alpha value [0..1]
pub fn to_array(&self) -> [f32; 4]
Sourcepub fn to_rgba(&self) -> Rgba
pub fn to_rgba(&self) -> Rgba
Examples found in repository?
examples/parser.rs (line 20)
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}");
}
}
}
pub fn to_normalized_rgba(&self) -> NormalizedRgba
pub fn to_rgba16(&self) -> Rgba16
pub fn clamp(&self) -> Self
Sourcepub fn from_rgba8(r: u8, g: u8, b: u8, a: u8) -> Self
pub fn from_rgba8(r: u8, g: u8, b: u8, a: u8) -> Self
Arguments:
r
: Red value [0..255]g
: Green value [0..255]b
: Blue value [0..255]a
: Alpha value [0..255]
Sourcepub fn from_rgba16(r: u16, g: u16, b: u16, a: u16) -> Self
pub fn from_rgba16(r: u16, g: u16, b: u16, a: u16) -> Self
Arguments:
r
: Red value [0..65535]g
: Green value [0..65535]b
: Blue value [0..65535]a
: Alpha value [0..65535]
Sourcepub fn from_rgba(r: u8, g: u8, b: u8, a: f32) -> Self
pub fn from_rgba(r: u8, g: u8, b: u8, a: f32) -> Self
Arguments:
r
: Red value [0..255]g
: Green value [0..255]b
: Blue value [0..255]a
: Alpha value [0..1]
Sourcepub fn from_normalized_rgba(r: f32, g: f32, b: f32, a: f32) -> Self
pub fn from_normalized_rgba(r: f32, g: f32, b: f32, a: f32) -> Self
Arguments:
r
: Red value [0..1]g
: Green value [0..1]b
: Blue value [0..1]a
: Alpha value [0..1]
Sourcepub fn from_normalized_linear_rgba(r: f32, g: f32, b: f32, a: f32) -> Self
pub fn from_normalized_linear_rgba(r: f32, g: f32, b: f32, a: f32) -> Self
Arguments:
r
: Red value [0..1]g
: Green value [0..1]b
: Blue value [0..1]a
: Alpha value [0..1]
Sourcepub fn from_linear_rgba(r: u8, g: u8, b: u8, a: f32) -> Self
pub fn from_linear_rgba(r: u8, g: u8, b: u8, a: f32) -> Self
Arguments:
r
: Red value [0..255]g
: Green value [0..255]b
: Blue value [0..255]a
: Alpha value [0..1]
Sourcepub fn from_linear_rgba8(r: u8, g: u8, b: u8, a: u8) -> Self
pub fn from_linear_rgba8(r: u8, g: u8, b: u8, a: u8) -> Self
Arguments:
r
: Red value [0..255]g
: Green value [0..255]b
: Blue value [0..255]a
: Alpha value [0..255]
Sourcepub fn from_linear_rgba16(r: u16, g: u16, b: u16, a: u16) -> Self
pub fn from_linear_rgba16(r: u16, g: u16, b: u16, a: u16) -> Self
Arguments:
r
: Red value [0..65535]g
: Green value [0..65535]b
: Blue value [0..65535]a
: Alpha value [0..65535]
Sourcepub fn from_hsla(h: f32, s: f32, l: f32, a: f32) -> Self
pub fn from_hsla(h: f32, s: f32, l: f32, a: f32) -> Self
Arguments:
h
: Hue angle [0..360]s
: Saturation [0..100]l
: Lightness [0..100]a
: Alpha [0..1]
Sourcepub fn from_normalized_hsla(h: f32, s: f32, l: f32, a: f32) -> Self
pub fn from_normalized_hsla(h: f32, s: f32, l: f32, a: f32) -> Self
Arguments:
h
: Hue angle [0..360]s
: Saturation [0..1]l
: Lightness [0..1]a
: Alpha [0..1]
Sourcepub fn from_html<S: AsRef<str>>(s: S) -> SolidResult<Self>
pub fn from_html<S: AsRef<str>>(s: S) -> SolidResult<Self>
Create Solid
from CSS color string.
pub fn name(&self) -> Option<&'static str>
Sourcepub fn to_hsla(&self) -> Hsla
pub fn to_hsla(&self) -> Hsla
Returns: [h, s, l, a]
h
: Hue angle [0..360]s
: Saturation [0..100]l
: Lightness [0..100]a
: Alpha [0..1]
Sourcepub fn to_normalized_hsla(&self) -> NormalizedHsla
pub fn to_normalized_hsla(&self) -> NormalizedHsla
Returns: [h, s, l, a]
h
: Hue angle [0..360]s
: Saturation [0..1]l
: Lightness [0..1]a
: Alpha [0..1]
Sourcepub fn to_normalized_linear_rgba(&self) -> NormalizedRgba
pub fn to_normalized_linear_rgba(&self) -> NormalizedRgba
Returns: [r, g, b, a]
- Red, green, blue and alpha in the range [0..1]
Sourcepub fn to_linear_rgba(&self) -> Rgba
pub fn to_linear_rgba(&self) -> Rgba
Returns: [r, g, b, a]
- Red, green, blue in the range [0..255]
- Alpha in the range [0..1]
Sourcepub fn to_hex_string(&self) -> String
pub fn to_hex_string(&self) -> String
Get the RGB hexadecimal color string.
Sourcepub fn to_rgb_string(&self) -> String
pub fn to_rgb_string(&self) -> String
Get the CSS rgb()
format string.
Sourcepub fn interpolate_rgb(&self, other: &Solid, t: f32) -> Self
pub fn interpolate_rgb(&self, other: &Solid, t: f32) -> Self
Blend this color with the other one, in the RGB color-space. t
in the range [0..1].
Sourcepub fn interpolate_linear_rgb(&self, other: &Solid, t: f32) -> Self
pub fn interpolate_linear_rgb(&self, other: &Solid, t: f32) -> Self
Blend this color with the other one, in the linear RGB color-space. t
in the range [0..1].
Sourcepub fn darken(&self, percentage: f32) -> Self
pub fn darken(&self, percentage: f32) -> Self
Examples found in repository?
examples/parser.rs (line 29)
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}");
}
}
}
pub fn lighten(&self, percentage: f32) -> Self
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Solid
Implement Serde deserialization from string
impl<'de> Deserialize<'de> for Solid
Implement Serde deserialization from string
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<NormalizedRgba> for Solid
impl From<NormalizedRgba> for Solid
Source§fn from(rgba: NormalizedRgba) -> Self
fn from(rgba: NormalizedRgba) -> Self
Converts to this type from the input type.
Source§impl PartialOrd for Solid
impl PartialOrd for Solid
impl StructuralPartialEq for Solid
Auto Trait Implementations§
impl Freeze for Solid
impl RefUnwindSafe for Solid
impl Send for Solid
impl Sync for Solid
impl Unpin for Solid
impl UnwindSafe for Solid
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