MCPcopy Create free account
hub / github.com/csskit/csskit / with_alpha

Method with_alpha

crates/chromashift/src/lib.rs:107–180  ·  view source on GitHub ↗

Returns a copy of this colour with a new alpha value (0.0–100.0). For `Named` colours (which are always fully opaque), setting a non-100 alpha converts to `Srgb`. For `Hex`, the colour is round-tripped through `Srgb` to apply the new alpha.

(self, alpha: f32)

Source from the content-addressed store, hash-verified

105 /// For `Named` colours (which are always fully opaque), setting a non-100 alpha converts to `Srgb`. For `Hex`,
106 /// the colour is round-tripped through `Srgb` to apply the new alpha.
107 pub fn with_alpha(self, alpha: f32) -> Self {
108 match self {
109 Color::A98Rgb(mut c) => {
110 c.alpha = alpha;
111 Color::A98Rgb(c)
112 }
113 Color::DisplayP3(mut c) => {
114 c.alpha = alpha;
115 Color::DisplayP3(c)
116 }
117 Color::Hsv(mut c) => {
118 c.alpha = alpha;
119 Color::Hsv(c)
120 }
121 Color::Hsl(mut c) => {
122 c.alpha = alpha;
123 Color::Hsl(c)
124 }
125 Color::Hex(h) => {
126 let mut srgb: Srgb = h.into();
127 srgb.alpha = alpha;
128 Color::Srgb(srgb)
129 }
130 Color::Hwb(mut c) => {
131 c.alpha = alpha;
132 Color::Hwb(c)
133 }
134 Color::Lab(mut c) => {
135 c.alpha = alpha;
136 Color::Lab(c)
137 }
138 Color::Lch(mut c) => {
139 c.alpha = alpha;
140 Color::Lch(c)
141 }
142 Color::LinearRgb(mut c) => {
143 c.alpha = alpha;
144 Color::LinearRgb(c)
145 }
146 Color::Named(n) => {
147 let mut srgb: Srgb = n.into();
148 srgb.alpha = alpha;
149 Color::Srgb(srgb)
150 }
151 Color::Oklab(mut c) => {
152 c.alpha = alpha;
153 Color::Oklab(c)
154 }
155 Color::Oklch(mut c) => {
156 c.alpha = alpha;
157 Color::Oklch(c)
158 }
159 Color::ProphotoRgb(mut c) => {
160 c.alpha = alpha;
161 Color::ProphotoRgb(c)
162 }
163 Color::Rec2020(mut c) => {
164 c.alpha = alpha;

Callers 1

Calls 15

A98RgbClass · 0.85
DisplayP3Class · 0.85
HsvClass · 0.85
HslClass · 0.85
SrgbClass · 0.85
HwbClass · 0.85
LabClass · 0.85
LchClass · 0.85
LinearRgbClass · 0.85
OklabClass · 0.85
OklchClass · 0.85
ProphotoRgbClass · 0.85

Tested by

no test coverage detected