pub struct Color(pub f32, pub f32, pub f32, pub f32);Tuple Fields§
§0: f32§1: f32§2: f32§3: f32Implementations§
Source§impl Color
impl Color
pub const BLACK: Color
pub const WHITE: Color
pub const RED: Color
pub const GREEN: Color
pub const BLUE: Color
pub const TRANSPARENT: Color
pub const fn rgb(r: f32, g: f32, b: f32) -> Self
pub const fn rgba(r: f32, g: f32, b: f32, a: f32) -> Self
pub const fn from_rgba_u8(r: u8, g: u8, b: u8, a: u8) -> Self
pub const fn from_rgb_u8(r: u8, g: u8, b: u8) -> Self
pub fn r(&self) -> f32
pub fn g(&self) -> f32
pub fn b(&self) -> f32
pub fn a(&self) -> f32
pub fn with_alpha(&self, alpha: f32) -> Self
Sourcepub fn srgb_8bit(self) -> Self
pub fn srgb_8bit(self) -> Self
This colour as the platform’s colour type actually holds it: eight bits per channel.
androidx.compose.ui.graphics.Color is a float-shaped API over an
8-bit value. Building one in the sRGB space snaps every channel on the
spot — the bytecode of ColorKt.Color(float, float, float, float, ColorSpace) is coerceIn(0f, 1f), * 255.0f, + 0.5f, f2i, packed
into an ARGB int — so a colour an app computes in float is already a
whole channel value before anything paints with it, and the rasterizer
never sees the fraction.
A renderer that carries the fraction to the framebuffer instead leaves
the rounding to whatever converts float to unorm there. That agrees
nearly everywhere and disagrees on an exact half. It is not a rare
shape: a theme that lerps between two byte colours lands on one
routinely — mix(rail, background, 0.55) puts a Wear settings capsule
at exactly 22.5/255 on green, where this rule gives 23 and a converter
that breaks ties to even gives 22. One level, and then the row’s layer
alpha multiplies it and keeps it.
Ties go up, which is what (int)(x + 0.5f), Skia’s
SkScalarRoundToInt and Rust’s f32::round all give for a channel
clamped into 0..=1.