ailloli_ui_core/style/
background.rs

1//! Optional solid background fill for a widget box.
2
3use super::Color;
4
5/// Widget background fill.
6///
7/// Possible values are no fill and a solid [`Background::Color`].
8///
9/// # Examples
10///
11/// ```
12/// use ailloli_ui_core::style::{Background, Color};
13/// assert!(Background::color(Color::WHITE).is_visible());
14/// ```
15#[derive(Debug, Clone, Copy, Default, PartialEq)]
16pub enum Background {
17    /// No background.
18    #[default]
19    None,
20    /// Solid linear-RGBA color, including potentially transparent colors.
21    Color(Color),
22}
23
24impl Background {
25    /// Creates a solid color background.
26    ///
27    /// # Examples
28    ///
29    /// ```
30    /// use ailloli_ui_core::style::{Background, Color};
31    /// assert_eq!(Background::color(Color::BLACK), Background::Color(Color::BLACK));
32    /// ```
33    pub fn color(color: Color) -> Self {
34        Self::Color(color)
35    }
36
37    /// Returns `true` when the variant carries a color.
38    ///
39    /// This reports configuration presence, not effective opacity: a fully
40    /// transparent [`Color`] still returns `true`.
41    ///
42    /// # Examples
43    ///
44    /// ```
45    /// use ailloli_ui_core::style::{Background, Color};
46    /// assert!(Background::color(Color::TRANSPARENT).is_visible());
47    /// assert!(!Background::None.is_visible());
48    /// ```
49    pub fn is_visible(self) -> bool {
50        !matches!(self, Self::None)
51    }
52}