Skip to main content

Colorize

Trait Colorize 

Source
pub trait Colorize: Sized {
Show 14 methods // Required methods fn opacity(&self, opacity: f32) -> Self; fn divide(&self, divisor: f32) -> Self; fn invert(&self) -> Self; fn invert_l(&self) -> Self; fn lighten(&self, amount: f32) -> Self; fn darken(&self, amount: f32) -> Self; fn apply(&self, base_color: Self) -> Self; fn mix(&self, other: Self, factor: f32) -> Self; fn mix_oklab(&self, other: Self, factor: f32) -> Self; fn hue(&self, hue: f32) -> Self; fn saturation(&self, saturation: f32) -> Self; fn lightness(&self, lightness: f32) -> Self; fn to_hex(&self) -> String; fn parse_hex(hex: &str) -> Result<Self>;
}
Expand description

颜色运算扩展 trait,为颜色类型提供透明度、明暗等变换能力。

Required Methods§

Source

fn opacity(&self, opacity: f32) -> Self

返回具有给定不透明度的新颜色。

不透明度是 0.0 到 1.0 之间的值,0.0 为完全透明,1.0 为完全不透明。

Source

fn divide(&self, divisor: f32) -> Self

返回每个通道除以给定除数的新颜色。

除数范围为 0.0 .. 1.0

Source

fn invert(&self) -> Self

返回反转颜色。

Source

fn invert_l(&self) -> Self

返回反转亮度。

Source

fn lighten(&self, amount: f32) -> Self

返回亮度按给定因子增加的新颜色。

因子范围:0.0 .. 1.0

Source

fn darken(&self, amount: f32) -> Self

返回暗度按给定因子增加的新颜色。

因子范围:0.0 .. 1.0

Source

fn apply(&self, base_color: Self) -> Self

返回具有相同亮度和 alpha 但不同色相和饱和度的新颜色。

Source

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

混合两种颜色,factor 是第一种颜色的值,范围 0.0 到 1.0。

Source

fn mix_oklab(&self, other: Self, factor: f32) -> Self

在 Oklab 颜色空间中混合两种颜色,factor 是第一种颜色的值,范围 0.0 到 1.0。

类似于 CSS color-mix(in oklab, color1 factor%, color2)

Source

fn hue(&self, hue: f32) -> Self

将颜色的 色相 改为给定值,范围:0.0 .. 1.0

Source

fn saturation(&self, saturation: f32) -> Self

将颜色的 饱和度 改为给定值,范围:0.0 .. 1.0

Source

fn lightness(&self, lightness: f32) -> Self

将颜色的 亮度 改为给定值,范围:0.0 .. 1.0

Source

fn to_hex(&self) -> String

将颜色转换为十六进制字符串。例如,“#F8FAFC”。

Source

fn parse_hex(hex: &str) -> Result<Self>

从十六进制字符串解析颜色。

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§