use crate::color::Color;
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct ShadowParams {
pub offset_x: f32,
pub offset_y: f32,
pub blur_radius: f32,
pub spread: f32,
pub color: Color,
}
impl ShadowParams {
#[inline]
pub const fn new(offset_x: f32, offset_y: f32, blur_radius: f32, color: Color) -> Self {
Self {
offset_x,
offset_y,
blur_radius,
spread: 0.0,
color,
}
}
pub const DEFAULT: Self = Self {
offset_x: 0.0,
offset_y: 4.0,
blur_radius: 8.0,
spread: 0.0,
color: Color(0x40000000),
};
pub const NONE: Self = Self {
offset_x: 0.0,
offset_y: 0.0,
blur_radius: 0.0,
spread: 0.0,
color: Color::TRANSPARENT,
};
#[inline]
pub const fn with_spread(mut self, spread: f32) -> Self {
self.spread = spread;
self
}
#[inline]
pub fn is_visible(&self) -> bool {
self.blur_radius > 0.0 || self.spread > 0.0 || self.offset_x != 0.0 || self.offset_y != 0.0
}
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct BlurParams {
pub radius: f32,
pub blur_type: BlurType,
}
impl BlurParams {
#[inline]
pub const fn new(radius: f32, blur_type: BlurType) -> Self {
Self { radius, blur_type }
}
#[inline]
pub const fn gaussian(radius: f32) -> Self {
Self {
radius,
blur_type: BlurType::Gaussian,
}
}
#[inline]
pub const fn box_blur(radius: f32) -> Self {
Self {
radius,
blur_type: BlurType::Box,
}
}
pub const NONE: Self = Self {
radius: 0.0,
blur_type: BlurType::Box,
};
#[inline]
pub fn is_visible(&self) -> bool {
self.radius > 0.0
}
}
#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, Hash)]
pub enum BlurType {
#[default]
Box = 0,
Gaussian = 1,
Motion = 2,
Radial = 3,
}
impl BlurType {
#[inline]
pub fn from_u8(value: u8) -> Option<Self> {
match value {
0 => Some(Self::Box),
1 => Some(Self::Gaussian),
2 => Some(Self::Motion),
3 => Some(Self::Radial),
_ => None,
}
}
#[inline]
pub const fn name(&self) -> &'static str {
match self {
Self::Box => "Box",
Self::Gaussian => "Gaussian",
Self::Motion => "Motion",
Self::Radial => "Radial",
}
}
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct OpacityParams {
pub value: f32,
}
impl OpacityParams {
#[inline]
pub const fn new(value: f32) -> Self {
Self { value }
}
pub const OPAQUE: Self = Self { value: 1.0 };
pub const TRANSPARENT: Self = Self { value: 0.0 };
#[inline]
pub fn to_alpha(&self) -> u8 {
(self.value.clamp(0.0, 1.0) * 255.0) as u8
}
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Default)]
pub struct WindowEffects {
pub shadow: ShadowParams,
pub backdrop_blur: BlurParams,
pub opacity: OpacityParams,
pub corner_radius: f32,
}
impl WindowEffects {
pub const NONE: Self = Self {
shadow: ShadowParams::NONE,
backdrop_blur: BlurParams::NONE,
opacity: OpacityParams::OPAQUE,
corner_radius: 0.0,
};
pub const DEFAULT: Self = Self {
shadow: ShadowParams::DEFAULT,
backdrop_blur: BlurParams::NONE,
opacity: OpacityParams::OPAQUE,
corner_radius: 8.0,
};
#[inline]
pub const fn with_shadow(mut self, shadow: ShadowParams) -> Self {
self.shadow = shadow;
self
}
#[inline]
pub const fn with_backdrop_blur(mut self, blur: BlurParams) -> Self {
self.backdrop_blur = blur;
self
}
#[inline]
pub const fn with_opacity(mut self, opacity: f32) -> Self {
self.opacity = OpacityParams::new(opacity);
self
}
#[inline]
pub const fn with_corner_radius(mut self, radius: f32) -> Self {
self.corner_radius = radius;
self
}
}