Color

Struct Color 

Source
pub struct Color {
    pub r: u8,
    pub g: u8,
    pub b: u8,
    pub a: u8,
}
Expand description

RGBA color value with alpha channel

Alpha channel: 0 = fully transparent, 255 = fully opaque. Default color has alpha=0 to indicate “unset” state.

Fields§

§r: u8

Red component (0-255)

§g: u8

Green component (0-255)

§b: u8

Blue component (0-255)

§a: u8

Alpha component (0=transparent, 255=opaque)

Implementations§

Source§

impl Color

Source

pub const WHITE: Color

White color (#FFFFFF)

Source

pub const BLACK: Color

Black color (#000000)

Source

pub const RED: Color

Red color (#FF0000)

Source

pub const GREEN: Color

Green color (#00FF00)

Source

pub const BLUE: Color

Blue color (#0000FF)

Source

pub const CYAN: Color

Cyan color (#00FFFF)

Source

pub const YELLOW: Color

Yellow color (#FFFF00)

Source

pub const MAGENTA: Color

Magenta color (#FF00FF)

Source

pub const TRANSPARENT: Color

Transparent (fully transparent black)

Source

pub fn is_default(&self) -> bool

Check if this is the default (unset) color

Source

pub const fn is_transparent(&self) -> bool

Check if color is fully transparent

Source

pub const fn is_opaque(&self) -> bool

Check if color is fully opaque

Source

pub const fn rgb(r: u8, g: u8, b: u8) -> Self

Create color from RGB components (fully opaque)

Source

pub const fn rgba(r: u8, g: u8, b: u8, a: u8) -> Self

Create color from RGBA components

Source

pub const fn hex(hex: u32) -> Self

Create color from hex value (0xRRGGBB, fully opaque)

Source

pub const fn hexa(hex: u32) -> Self

Create color from hex value with alpha (0xRRGGBBAA)

Source

pub const fn with_alpha(self, a: u8) -> Self

Create a new color with modified alpha

Source

pub const fn semi_transparent(self) -> Self

Create a semi-transparent version (alpha = 128)

Source

pub fn alpha_f32(&self) -> f32

Get alpha as float (0.0 = transparent, 1.0 = opaque)

Source

pub fn with_alpha_f32(self, alpha: f32) -> Self

Create color with alpha from float (0.0 = transparent, 1.0 = opaque)

Source

pub const fn darken(self, amount: u8) -> Self

Darken the color by subtracting from RGB components

§Arguments
  • amount - Value to subtract from each RGB component (0-255)
§Example
let base = Color::rgb(100, 150, 200);
let darker = base.darken(30);  // rgb(70, 120, 170)
Source

pub const fn lighten(self, amount: u8) -> Self

Lighten the color by adding to RGB components

§Arguments
  • amount - Value to add to each RGB component (0-255)
§Example
let base = Color::rgb(100, 150, 200);
let lighter = base.lighten(30);  // rgb(130, 180, 230)
Source

pub fn darken_pct(self, pct: f32) -> Self

Darken by percentage (0.0 to 1.0)

§Example
let base = Color::rgb(100, 100, 100);
let darker = base.darken_pct(0.2);  // 20% darker
Source

pub fn lighten_pct(self, pct: f32) -> Self

Lighten by percentage (0.0 to 1.0)

§Example
let base = Color::rgb(100, 100, 100);
let lighter = base.lighten_pct(0.2);  // 20% lighter
Source

pub const fn pressed(self) -> Self

Get pressed state color (standard darkening)

§Example
let button_bg = Color::rgb(37, 99, 235);
let pressed_bg = button_bg.pressed();  // Darker by 30
Source

pub const fn hover(self) -> Self

Get hover state color (standard lightening)

§Example
let button_bg = Color::rgb(37, 99, 235);
let hover_bg = button_bg.hover();  // Lighter by 40
Source

pub const fn focus(self) -> Self

Get focus state color (same as hover)

§Example
let button_bg = Color::rgb(37, 99, 235);
let focus_bg = button_bg.focus();  // Lighter by 40
Source

pub fn blend(self, other: Color, ratio: f32) -> Self

Blend this color with another color

§Arguments
  • other - The other color to blend with
  • ratio - Blend ratio (0.0 = self, 1.0 = other)
§Example
let red = Color::RED;
let blue = Color::BLUE;
let purple = red.blend(blue, 0.5);  // 50% mix
Source

pub const fn with_interaction( self, pressed: bool, hovered: bool, focused: bool, ) -> Self

Apply interaction state to color

Convenience method that applies the appropriate color effect based on pressed/hovered/focused state.

§Example
let base = Color::rgb(37, 99, 235);
let final_color = base.with_interaction(pressed, hovered, focused);

Trait Implementations§

Source§

impl Clone for Color

Source§

fn clone(&self) -> Color

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Color

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Color

Source§

fn default() -> Self

Default color is transparent black (unset state)

Source§

impl PartialEq for Color

Source§

fn eq(&self, other: &Color) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Color

Source§

impl Eq for Color

Source§

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 UnwindSafe for Color

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more