pub struct Color(pub f32, pub f32, pub f32, pub f32);Expand description
An RGBA color in the sRGB space. The four fields are red, green, blue and alpha, each from 0.0
to 1.0. Compose’s Color.
Tuple Fields§
§0: f32§1: f32§2: f32§3: f32Implementations§
Source§impl Color
impl Color
Sourcepub const TRANSPARENT: Color
pub const TRANSPARENT: Color
Fully transparent black, with every channel 0.0.
Sourcepub const fn rgb(r: f32, g: f32, b: f32) -> Color
pub const fn rgb(r: f32, g: f32, b: f32) -> Color
Creates an opaque color from red, green and blue channels, each from 0.0 to 1.0.
Sourcepub const fn rgba(r: f32, g: f32, b: f32, a: f32) -> Color
pub const fn rgba(r: f32, g: f32, b: f32, a: f32) -> Color
Creates a color from red, green, blue and alpha channels, each from 0.0 to 1.0.
Sourcepub const fn from_rgba_u8(r: u8, g: u8, b: u8, a: u8) -> Color
pub const fn from_rgba_u8(r: u8, g: u8, b: u8, a: u8) -> Color
Creates a color from red, green, blue and alpha channels of 0 to 255.
Sourcepub const fn from_rgb_u8(r: u8, g: u8, b: u8) -> Color
pub const fn from_rgb_u8(r: u8, g: u8, b: u8) -> Color
Creates an opaque color from red, green and blue channels of 0 to 255.
Sourcepub fn with_alpha(&self, alpha: f32) -> Color
pub fn with_alpha(&self, alpha: f32) -> Color
Returns this color with its alpha channel replaced by alpha, from 0.0 (transparent) to 1.0
(opaque).
Sourcepub fn srgb_8bit(self) -> Color
pub fn srgb_8bit(self) -> Color
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.
Trait Implementations§
impl Copy for Color
Source§impl From<Color> for Brush
A colour paints as a solid brush wherever a brush is taken, as Compose
takes a Color beside each Brush overload.
impl From<Color> for Brush
A colour paints as a solid brush wherever a brush is taken, as Compose
takes a Color beside each Brush overload.
Source§impl RenderHash for Color
impl RenderHash for Color
Source§fn render_hash(&self) -> u64
fn render_hash(&self) -> u64
Source§impl SpringScalar for Color
Colors spring as four independent channels, mirroring how Compose animates
Color as an AnimationVector4D. Channels are clamped back into [0, 1]
when the vector is rebuilt, so overshooting springs still produce valid
colors (Compose’s gamut coercion).
impl SpringScalar for Color
Colors spring as four independent channels, mirroring how Compose animates
Color as an AnimationVector4D. Channels are clamped back into [0, 1]
when the vector is rebuilt, so overshooting springs still produce valid
colors (Compose’s gamut coercion).
Source§const DIMENSIONS: usize = 4
const DIMENSIONS: usize = 4
Source§fn from_dimensions(dimensions: [f32; 4]) -> Color
fn from_dimensions(dimensions: [f32; 4]) -> Color
Self::DIMENSIONS are ignored).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 UnsafeUnpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more