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

Change Frame::multiply_with_opacity to multiply in gamma space (#4283)

This produces a more perceptually even change when used in animations,
like when fading out a closed window
This commit is contained in:
Emil Ernerfeldt
2024-03-30 18:39:05 +01:00
committed by GitHub
parent e03ea2e17d
commit ab720ce900
2 changed files with 8 additions and 4 deletions

View File

@@ -196,11 +196,15 @@ impl Frame {
self
}
/// Opacity multiplier in gamma space.
///
/// For instance, multiplying with `0.5`
/// will make the frame half transparent.
#[inline]
pub fn multiply_with_opacity(mut self, opacity: f32) -> Self {
self.fill = self.fill.linear_multiply(opacity);
self.stroke.color = self.stroke.color.linear_multiply(opacity);
self.shadow.color = self.shadow.color.linear_multiply(opacity);
self.fill = self.fill.gamma_multiply(opacity);
self.stroke.color = self.stroke.color.gamma_multiply(opacity);
self.shadow.color = self.shadow.color.gamma_multiply(opacity);
self
}
}