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)
| 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; |