1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 21:30:03 -04:00

Make the hex_color macro const (#7444)

* Closes <https://github.com/emilk/egui/issues/5160>
* [x] I have followed the instructions in the PR template
This commit is contained in:
YgorSouza
2025-08-12 09:12:44 +02:00
committed by GitHub
parent 6fae65a3fa
commit fb5fe645be
3 changed files with 29 additions and 5 deletions

View File

@@ -105,7 +105,7 @@ pub fn linear_f32_from_gamma_u8(s: u8) -> f32 {
/// linear [0, 255] -> linear [0, 1].
/// Useful for alpha-channel.
#[inline(always)]
pub fn linear_f32_from_linear_u8(a: u8) -> f32 {
pub const fn linear_f32_from_linear_u8(a: u8) -> f32 {
a as f32 / 255.0
}
@@ -130,7 +130,7 @@ pub fn linear_u8_from_linear_f32(a: f32) -> u8 {
fast_round(a * 255.0)
}
fn fast_round(r: f32) -> u8 {
const fn fast_round(r: f32) -> u8 {
(r + 0.5) as _ // rust does a saturating cast since 1.45
}