ailloli_ui_core/style/opacity.rs
1//! Widget-level opacity multipliers.
2
3/// Widget opacity multiplier (`0.0` = transparent, `1.0` = opaque).
4///
5/// The tuple field is public for low-level construction; use [`Self::new`] to
6/// clamp ordinary finite values.
7///
8/// # Examples
9///
10/// ```
11/// use ailloli_ui_core::style::Opacity;
12/// assert_eq!(Opacity::new(1.5), Opacity(1.0));
13/// ```
14#[derive(Debug, Clone, Copy, PartialEq)]
15pub struct Opacity(pub f32);
16
17impl Default for Opacity {
18 fn default() -> Self {
19 Self(1.0)
20 }
21}
22
23impl Opacity {
24 /// Clamps a finite multiplier to `0.0..=1.0`.
25 ///
26 /// NaN remains NaN under floating-point clamp semantics.
27 ///
28 /// # Examples
29 ///
30 /// ```
31 /// use ailloli_ui_core::style::Opacity;
32 /// assert_eq!(Opacity::new(-1.0), Opacity(0.0));
33 /// ```
34 pub fn new(value: f32) -> Self {
35 Self(value.clamp(0.0, 1.0))
36 }
37}