pub struct Color(/* private fields */);Expand description
A color value that can be resolved in different color spaces.
This is the main color type that wraps a resolvable color value. Colors can be created from sRGB, P3, OKLCH, or custom color spaces.
§Layout Behavior
Color is a greedy view that expands to fill all available space in both
directions. Use .frame() to constrain its size, or use it as a background.
§Examples
// Fills entire container
Color::blue()
// Constrained to specific size
Color::red().frame().width(100.0).height(50.0)
// As a background
text("Hello").background(Color::yellow())Implementations§
Source§impl Color
impl Color
Sourcepub fn new(custom: impl Resolvable<Resolved = ResolvedColor> + 'static) -> Color
pub fn new(custom: impl Resolvable<Resolved = ResolvedColor> + 'static) -> Color
Creates a new color from a custom resolvable color value.
§Arguments
custom- A resolvable color implementation
Sourcepub fn srgb(red: u8, green: u8, blue: u8) -> Color
pub fn srgb(red: u8, green: u8, blue: u8) -> Color
Creates an sRGB color from 8-bit color components.
§Arguments
red- Red component (0-255)green- Green component (0-255)blue- Blue component (0-255)
Sourcepub fn srgb_f32(red: f32, green: f32, blue: f32) -> Color
pub fn srgb_f32(red: f32, green: f32, blue: f32) -> Color
Creates an sRGB color from floating-point color components.
§Arguments
red- Red component (0.0 to 1.0)green- Green component (0.0 to 1.0)blue- Blue component (0.0 to 1.0)
Sourcepub fn p3(red: f32, green: f32, blue: f32) -> Color
pub fn p3(red: f32, green: f32, blue: f32) -> Color
Creates a P3 color from floating-point color components.
§Arguments
red- Red component (0.0 to 1.0)green- Green component (0.0 to 1.0)blue- Blue component (0.0 to 1.0)
Sourcepub fn oklch(lightness: f32, chroma: f32, hue: f32) -> Color
pub fn oklch(lightness: f32, chroma: f32, hue: f32) -> Color
Creates an OKLCH color from perceptual lightness, chroma, and hue values.
OKLCH is recommended for authoring UI colors due to its perceptual uniformity.
Sourcepub fn srgb_hex(hex: &str) -> Color
pub fn srgb_hex(hex: &str) -> Color
Creates an sRGB color from a hexadecimal color string.
Panics if the string does not contain exactly six hexadecimal digits.
Sourcepub fn try_srgb_hex(hex: &str) -> Result<Color, HexColorError>
pub fn try_srgb_hex(hex: &str) -> Result<Color, HexColorError>
Tries to create an sRGB color from a hexadecimal color string.
§Errors
Returns HexColorError if the provided string is not a valid six-digit
hexadecimal color.
Sourcepub fn transparent() -> Color
pub fn transparent() -> Color
Returns a fully transparent color.
Sourcepub fn with_opacity(self, opacity: f32) -> Color
pub fn with_opacity(self, opacity: f32) -> Color
Creates a new color with the specified opacity applied.
§Arguments
opacity- Opacity value (0.0 = transparent, 1.0 = opaque)
Sourcepub fn with_alpha(self, opacity: f32) -> Color
pub fn with_alpha(self, opacity: f32) -> Color
Alias for [with_opacity].
Sourcepub fn with_headroom(self, headroom: f32) -> Color
pub fn with_headroom(self, headroom: f32) -> Color
Creates a new color with extended headroom for HDR content.
§Arguments
headroom- Additional headroom value for extended range
Sourcepub fn lighten(self, amount: f32) -> Color
pub fn lighten(self, amount: f32) -> Color
Lightens the color by increasing its OKLCH lightness component.
Sourcepub fn darken(self, amount: f32) -> Color
pub fn darken(self, amount: f32) -> Color
Darkens the color by decreasing its OKLCH lightness component.
Sourcepub fn saturate(self, amount: f32) -> Color
pub fn saturate(self, amount: f32) -> Color
Adjusts the color saturation by scaling the OKLCH chroma component.
Sourcepub fn desaturate(self, amount: f32) -> Color
pub fn desaturate(self, amount: f32) -> Color
Decreases the color saturation by scaling the OKLCH chroma component down.
Sourcepub fn hue_rotate(self, degrees: f32) -> Color
pub fn hue_rotate(self, degrees: f32) -> Color
Rotates the color’s hue by the provided number of degrees.
Sourcepub fn mix(self, other: impl Into<Color>, factor: f32) -> Color
pub fn mix(self, other: impl Into<Color>, factor: f32) -> Color
Mixes this color with another color using linear interpolation.
Sourcepub fn resolve(&self, env: &Environment) -> Computed<ResolvedColor>
pub fn resolve(&self, env: &Environment) -> Computed<ResolvedColor>
Resolves this color to a concrete color value in the given environment.
§Arguments
env- The environment to resolve the color in
Trait Implementations§
Source§impl FormBuilder for Color
impl FormBuilder for Color
Source§impl From<Color> for Background
impl From<Color> for Background
Source§impl<T> From<T> for Colorwhere
T: Resolvable<Resolved = ResolvedColor> + 'static,
impl<T> From<T> for Colorwhere
T: Resolvable<Resolved = ResolvedColor> + 'static,
Source§impl NativeView for Color
impl NativeView for Color
Source§fn stretch_axis(&self) -> StretchAxis
fn stretch_axis(&self) -> StretchAxis
Auto Trait Implementations§
impl Freeze for Color
impl !RefUnwindSafe for Color
impl !Send for Color
impl !Sync for Color
impl Unpin for Color
impl !UnwindSafe for Color
Blanket Implementations§
Source§impl<S> AnimationExt for Swhere
S: SignalExt,
impl<S> AnimationExt for Swhere
S: SignalExt,
Source§fn animated(self) -> WithMetadata<Self, Animation>where
Self: Sized,
fn animated(self) -> WithMetadata<Self, Animation>where
Self: Sized,
Source§fn with_animation(self, animation: Animation) -> WithMetadata<Self, Animation>where
Self: Sized,
fn with_animation(self, animation: Animation) -> WithMetadata<Self, Animation>where
Self: Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)Source§impl<T> IdentifiableExt for T
impl<T> IdentifiableExt for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<C, Output> IntoSignal<Output> for C
impl<C, Output> IntoSignal<Output> for C
Source§impl<C> SignalExt for Cwhere
C: Signal,
impl<C> SignalExt for Cwhere
C: Signal,
Source§fn map<F, Output>(self, f: F) -> Map<Self, F, Output>
fn map<F, Output>(self, f: F) -> Map<Self, F, Output>
Source§fn zip<B: Signal>(self, b: B) -> Zip<Self, B>
fn zip<B: Signal>(self, b: B) -> Zip<Self, B>
Source§fn computed(self) -> Computed<Self::Output>where
Self: Clone + 'static,
fn computed(self) -> Computed<Self::Output>where
Self: Clone + 'static,
Computed wrapper. Read moreSource§fn with<T>(self, metadata: T) -> WithMetadata<Self, T>
fn with<T>(self, metadata: T) -> WithMetadata<Self, T>
Source§impl<C> SignalExt for Cwhere
C: Signal,
impl<C> SignalExt for Cwhere
C: Signal,
Source§fn map<F, Output>(self, f: F) -> Map<Self, F, Output>
fn map<F, Output>(self, f: F) -> Map<Self, F, Output>
Source§fn cached(self) -> Cached<Self>
fn cached(self) -> Cached<Self>
Source§fn computed(self) -> Computed<Self::Output>where
Self: 'static,
fn computed(self) -> Computed<Self::Output>where
Self: 'static,
Computed container.