#[repr(C)]pub struct Rgba {
pub r: f32,
pub g: f32,
pub b: f32,
pub a: f32,
}Expand description
An RGBA color
Fields§
§r: f32The red component of the color, in the range 0.0 to 1.0
g: f32The green component of the color, in the range 0.0 to 1.0
b: f32The blue component of the color, in the range 0.0 to 1.0
a: f32The alpha component of the color, in the range 0.0 to 1.0
Implementations§
Source§impl Rgba
impl Rgba
Sourcepub fn blend(&self, other: Rgba) -> Self
pub fn blend(&self, other: Rgba) -> Self
Create a new Rgba color by blending this and another color together
Sourcepub fn alpha(&self, a: f32) -> Self
pub fn alpha(&self, a: f32) -> Self
Returns a new RGBA color with the same red, green and blue channels, but with a new alpha value.
Example:
use gpui::rgba;
let color = rgba(0xFF0000FF);
let faded = color.alpha(0.25);
assert_eq!(faded.a, 0.25);This will return a red color with 25% opacity.
Example:
use gpui::rgba;
let color = rgba(0x3399FFCC);
let transparent = color.alpha(0.0);
assert_eq!(transparent.a, 0.0);This will return the same blue color, fully transparent.
Sourcepub fn opacity(&self, factor: f32) -> Self
pub fn opacity(&self, factor: f32) -> Self
Returns a new RGBA color with the same red, green, and blue channels, but with the alpha channel multiplied by the given factor.
Example:
use gpui::rgba;
let color = rgba(0xFF0000FF); // Fully opaque red
let faded = color.opacity(0.5);
assert_eq!(faded.a, 0.5);This will return a red color with 50% opacity.
Example:
use gpui::rgba;
let color = rgba(0x3399FFCC); // A light blue with 80% opacity
let faded = color.opacity(0.5);
assert!((faded.a - 0.4).abs() < 1e-6);This will return the same blue color scaled down to 40% opacity.
Trait Implementations§
impl Copy for Rgba
Source§impl<'de> Deserialize<'de> for Rgba
impl<'de> Deserialize<'de> for Rgba
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl From<Rgba> for Background
impl From<Rgba> for Background
Source§impl JsonSchema for Rgba
impl JsonSchema for Rgba
Source§fn json_schema(_generator: &mut SchemaGenerator) -> Schema
fn json_schema(_generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read more