pub struct Color {
pub red: u8,
pub green: u8,
pub blue: u8,
pub alpha: f32,
}Expand description
Represents an RGB color.
Fields§
§red: u8Red component (0-255)
green: u8Green component (0-255)
blue: u8Blue component (0-255)
alpha: f32Alpha component (0-1)
Implementations§
Source§impl Color
impl Color
Sourcepub fn with_alpha(red: u8, green: u8, blue: u8, alpha: f32) -> Self
pub fn with_alpha(red: u8, green: u8, blue: u8, alpha: f32) -> Self
Creates a new Color instance with an alpha component.
The alpha component is a floating-point value between 0.0 and 1.0.
A value of 0.0 represents full transparency, while 1.0 is fully opaque.
Values between 0.0 and 1.0 represent varying levels of transparency.
§Arguments
red- The red component (0-255)green- The green component (0-255)blue- The blue component (0-255)alpha- The alpha component (0.0-1.0)
§Returns
A new Color instance.
Sourcepub fn interpolate(&self, color: &Color, percentage: f32) -> Self
pub fn interpolate(&self, color: &Color, percentage: f32) -> Self
Sourcepub fn from_hex(hex: &str) -> Result<Self, ColorError>
pub fn from_hex(hex: &str) -> Result<Self, ColorError>
Sourcepub fn from_rgba(input: &str) -> Result<Self, ColorError>
pub fn from_rgba(input: &str) -> Result<Self, ColorError>
Tries to create a Color from a rgba color string.
The format is “rgba(r, g, b, a)” where r, g, b are the red, green, blue components (0-255)
Or “rgb(r, g, b)” where r, g, b are the red, green, blue components (0-255)
and a is the alpha component (0.0-1.0).
The spaces are optional.
The alpha component is optional and defaults to 1.0.
§Arguments
input- A string slice that holds the rgba color code (e.g., “rgba(255, 128, 64, 0.5)”, “rgb(255, 128, 64)”)
§Returns
A Result containing either the created Color or a ColorError.