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 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%.
Trait Implementationsยง
ยงimpl From<Color> for PremultipliedRgbaColor
impl From<Color> for PremultipliedRgbaColor
Convert a non-premultiplied color to a premultiplied one
ยงfn from(col: Color) -> PremultipliedRgbaColor
fn from(col: Color) -> PremultipliedRgbaColor
ยงimpl PartialOrd<Color> for Color
impl PartialOrd<Color> 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 moreimpl Copy for Color
impl StructuralPartialEq for Color
Auto Trait Implementationsยง
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> 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>
ยงimpl<T> IsDefault for Twhere
T: Default + PartialEq<T> + Copy,
impl<T> IsDefault for Twhere
T: Default + PartialEq<T> + Copy,
ยงfn is_default(&self) -> bool
fn is_default(&self) -> bool
ยง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 Pwhere
R: Read + ReadEndian<P>,
P: Default,
impl<R, P> ReadPrimitive<R> for Pwhere
R: Read + ReadEndian<P>,
P: Default,
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()
.