Struct slint_interpreter::Color
#[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§
§impl Color
impl Color
pub const fn from_argb_encoded(encoded: u32) -> Color
pub const fn from_argb_encoded(encoded: u32) -> Color
Construct a color from an integer encoded as 0xAARRGGBB
pub fn as_argb_encoded(&self) -> u32
pub fn as_argb_encoded(&self) -> u32
Returns (alpha, red, green, blue)
encoded as u32
pub const fn from_argb_u8(alpha: u8, red: u8, green: u8, blue: u8) -> Color
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.
pub const fn from_rgb_u8(red: u8, green: u8, blue: u8) -> Color
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.
pub fn from_argb_f32(alpha: f32, red: f32, green: f32, blue: f32) -> Color
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.
pub fn from_rgb_f32(red: f32, green: f32, blue: f32) -> Color
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.
pub fn to_argb_u8(&self) -> RgbaColor<u8>
pub fn to_argb_u8(&self) -> RgbaColor<u8>
Converts this color to an RgbaColor struct for easy destructuring.
pub fn to_argb_f32(&self) -> RgbaColor<f32>
pub fn to_argb_f32(&self) -> RgbaColor<f32>
Converts this color to an RgbaColor struct for easy destructuring.
pub fn to_hsva(&self) -> HsvaColor
pub fn to_hsva(&self) -> HsvaColor
Converts this color to the HSV color space.
pub fn from_hsva(hue: f32, saturation: f32, value: f32, alpha: f32) -> Color
pub fn from_hsva(hue: f32, saturation: f32, value: f32, alpha: f32) -> Color
Construct a color from the hue, saturation, and value HSV color space parameters.
Hue is between 0 and 360, the others parameters between 0 and 1.
pub fn brighter(&self, factor: f32) -> Color
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.
pub fn darker(&self, factor: f32) -> Color
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%.
pub fn transparentize(&self, factor: f32) -> Color
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));
pub fn mix(&self, other: &Color, factor: f32) -> Color
pub fn mix(&self, other: &Color, factor: f32) -> Color
Returns a new color that is a mix of this color and other
. The specified factor is
clamped to be between 0.0
and 1.0
and then applied to this color, while 1.0 - factor
is applied to other
.
§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%
purpe and 25%
orange red 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));
pub fn with_alpha(&self, alpha: f32) -> Color
pub fn with_alpha(&self, alpha: f32) -> Color
Returns a new version of this color with the opacity set to alpha
.
Trait Implementations§
§impl<'de> Deserialize<'de> for Color
impl<'de> Deserialize<'de> for Color
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Color, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Color, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl InterpolatedPropertyValue for Color
impl InterpolatedPropertyValue for Color
§fn interpolate(&self, target_value: &Color, t: f32) -> Color
fn interpolate(&self, target_value: &Color, t: f32) -> Color
§impl PartialOrd for Color
impl PartialOrd for Color
§fn partial_cmp(&self, other: &Color) -> Option<Ordering>
fn partial_cmp(&self, other: &Color) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more§impl Serialize for Color
impl Serialize for Color
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Copy for Color
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> 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,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.