#[repr(C)]
pub struct Color { /* private fields */ }
Expand description

Color represents a color in the Slint run-time, represented using 8-bit channels for red, green, blue and the alpha (opacity). It can be conveniently converted using the to_ and from_ (a)rgb helper functions:

let col = some_color.to_argb_f32();
do_something_with_red_and_green(col.red, col.green);

let RgbaColor { red, blue, green, .. } = some_color.to_argb_u8();
do_something_with_red(red);

let new_col = Color::from(RgbaColor{ red: 0.5, green: 0.65, blue: 0.32, alpha: 1.});

Implementations§

source§

impl Color

source

pub const fn from_argb_encoded(encoded: u32) -> Color

Construct a color from an integer encoded as 0xAARRGGBB

source

pub fn as_argb_encoded(&self) -> u32

Returns (alpha, red, green, blue) encoded as u32

source

pub const fn from_argb_u8(alpha: u8, red: u8, green: u8, blue: u8) -> Color

Construct a color from the alpha, red, green and blue color channel parameters.

source

pub const fn from_rgb_u8(red: u8, green: u8, blue: u8) -> Color

Construct a color from the red, green and blue color channel parameters. The alpha channel will have the value 255.

source

pub fn from_argb_f32(alpha: f32, red: f32, green: f32, blue: f32) -> Color

Construct a color from the alpha, red, green and blue color channel parameters.

source

pub fn from_rgb_f32(red: f32, green: f32, blue: f32) -> Color

Construct a color from the red, green and blue color channel parameters. The alpha channel will have the value 255.

source

pub fn to_argb_u8(&self) -> RgbaColor<u8>

Converts this color to an RgbaColor struct for easy destructuring.

source

pub fn to_argb_f32(&self) -> RgbaColor<f32>

Converts this color to an RgbaColor struct for easy destructuring.

source

pub fn red(self) -> u8

Returns the red channel of the color as u8 in the range 0..255.

source

pub fn green(self) -> u8

Returns the green channel of the color as u8 in the range 0..255.

source

pub fn blue(self) -> u8

Returns the blue channel of the color as u8 in the range 0..255.

source

pub fn alpha(self) -> u8

Returns the alpha channel of the color as u8 in the range 0..255.

source

pub fn brighter(&self, factor: f32) -> Color

Returns a new version of this color that has the brightness increased by the specified factor. This is done by converting the color to the HSV color space and multiplying the brightness (value) with (1 + factor). The result is converted back to RGB and the alpha channel is unchanged. So for example brighter(0.2) will increase the brightness by 20%, and calling brighter(-0.5) will return a color that’s 50% darker.

source

pub fn darker(&self, factor: f32) -> Color

Returns a new version of this color that has the brightness decreased by the specified factor. This is done by converting the color to the HSV color space and dividing the brightness (value) by (1 + factor). The result is converted back to RGB and the alpha channel is unchanged. So for example darker(0.3) will decrease the brightness by 30%.

source

pub fn transparentize(&self, factor: f32) -> Color

Returns a new version of this color with the opacity decreased by factor.

The transparency is obtained by multiplying the alpha channel by (1 - factor).

§Examples

Decreasing the opacity of a red color by half:

let red = Color::from_argb_u8(255, 255, 0, 0);
assert_eq!(red.transparentize(0.5), Color::from_argb_u8(128, 255, 0, 0));

Decreasing the opacity of a blue color by 20%:

let blue = Color::from_argb_u8(200, 0, 0, 255);
assert_eq!(blue.transparentize(0.2), Color::from_argb_u8(160, 0, 0, 255));

Negative values increase the opacity

let blue = Color::from_argb_u8(200, 0, 0, 255);
assert_eq!(blue.transparentize(-0.1), Color::from_argb_u8(220, 0, 0, 255));
source

pub fn mix(&self, other: &Color, factor: f32) -> Color

Returns a new color that is a mix of self and other, with a proportion factor given by factor (which will be clamped to be between 0.0 and 1.0).

§Examples

Mix red with black half-and-half:

let red = Color::from_rgb_u8(255, 0, 0);
let black = Color::from_rgb_u8(0, 0, 0);
assert_eq!(red.mix(&black, 0.5), Color::from_rgb_u8(128, 0, 0));

Mix Purple with OrangeRed with 75%:25% ratio:

let purple = Color::from_rgb_u8(128, 0, 128);
let orange_red = Color::from_rgb_u8(255, 69, 0);
assert_eq!(purple.mix(&orange_red, 0.75), Color::from_rgb_u8(160, 17, 96));
source

pub fn with_alpha(&self, alpha: f32) -> Color

Returns a new version of this color with the opacity set to alpha.

Trait Implementations§

source§

impl Clone for Color

source§

fn clone(&self) -> Color

Returns a copy 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<(), Error>

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

impl Default for Color

source§

fn default() -> Color

Returns the “default value” for a type. Read more
source§

impl Display for Color

source§

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

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

impl From<Color> for Brush

source§

fn from(original: Color) -> Brush

Converts to this type from the input type.
source§

impl From<Color> for RgbaColor<f32>

source§

fn from(col: Color) -> RgbaColor<f32>

Converts to this type from the input type.
source§

impl From<Color> for RgbaColor<u8>

source§

fn from(col: Color) -> RgbaColor<u8>

Converts to this type from the input type.
source§

impl From<Color> for Value

source§

fn from(c: Color) -> Self

Converts to this type from the input type.
source§

impl From<RgbaColor<f32>> for Color

source§

fn from(col: RgbaColor<f32>) -> Color

Converts to this type from the input type.
source§

impl From<RgbaColor<u8>> for Color

source§

fn from(col: RgbaColor<u8>) -> Color

Converts to this type from the input type.
source§

impl InterpolatedPropertyValue for Color

source§

fn interpolate(&self, target_value: &Color, t: f32) -> Color

Returns the interpolated value between self and target_value according to the progress parameter t that’s usually between 0 and 1. With certain animation easing curves it may over- or undershoot though.
source§

impl PartialEq for Color

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Color

source§

fn partial_cmp(&self, other: &Color) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl TryFrom<Value> for Color

§

type Error = Value

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

fn try_from(v: Value) -> Result<Color, Self::Error>

Performs the conversion.
source§

impl Copy 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> Downcast for T
where T: Any,

source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> NoneValue for T
where T: Default,

§

type NoneType = T

source§

fn null_value() -> T

The none-equivalent value.
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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> ToSmolStr for T
where T: Display + ?Sized,

source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

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