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

[style] Fade out windows on close

This commit is contained in:
Emil Ernerfeldt
2021-01-20 00:30:07 +01:00
parent 29bb7c9f9d
commit e2217ff63a
7 changed files with 86 additions and 27 deletions

View File

@@ -129,6 +129,14 @@ impl Color32 {
pub fn to_tuple(&self) -> (u8, u8, u8, u8) {
(self.r(), self.g(), self.b(), self.a())
}
/// Multiply with 0.5 to make color half as opaque.
pub fn linear_multiply(self, factor: f32) -> Color32 {
debug_assert!(0.0 <= factor && factor <= 1.0);
// As an unfortunate side-effect of using premultiplied alpha
// we need a somewhat expensive conversion to linear space and back.
Rgba::from(self).multiply(factor).into()
}
}
// ----------------------------------------------------------------------------

View File

@@ -1,11 +1,15 @@
use super::*;
/// A rectangular shadow with a soft penumbra.
/// The color and fuzziness of a fuzzy shape.
/// Can be used for a rectangular shadow with a soft penumbra.
#[derive(Clone, Copy, Debug, Default, PartialEq)]
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
pub struct Shadow {
// The shadow extends this much outside the rect.
/// The shadow extends this much outside the rect.
/// The size of the fuzzy penumbra.
pub extrusion: f32,
/// Color of the opaque center of the shadow.
pub color: Color32,
}

View File

@@ -420,8 +420,9 @@ fn stroke_path(
fn mul_color(color: Color32, factor: f32) -> Color32 {
debug_assert!(0.0 <= factor && factor <= 1.0);
// sRGBA correct fading requires conversion to linear space and back again because of premultiplied alpha
Rgba::from(color).multiply(factor).into()
// As an unfortunate side-effect of using premultiplied alpha
// we need a somewhat expensive conversion to linear space and back.
color.linear_multiply(factor)
}
// ----------------------------------------------------------------------------