Skip to content

Commit fdac4c2

Browse files
Allow creating Colors in a const context. (#135)
Co-authored-by: Daniel McNab <[email protected]>
1 parent f2b9d09 commit fdac4c2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/color.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,20 @@ impl Color {
223223
a: NV_ONE,
224224
};
225225

226+
/// Creates a new color from 4 components.
227+
///
228+
/// # Safety
229+
///
230+
/// All values must be in 0..=1 range.
231+
pub const unsafe fn from_rgba_unchecked(r: f32, g: f32, b: f32, a: f32) -> Self {
232+
Color {
233+
r: NormalizedF32::new_unchecked(r),
234+
g: NormalizedF32::new_unchecked(g),
235+
b: NormalizedF32::new_unchecked(b),
236+
a: NormalizedF32::new_unchecked(a),
237+
}
238+
}
239+
226240
/// Creates a new color from 4 components.
227241
///
228242
/// All values must be in 0..=1 range.

0 commit comments

Comments
 (0)